Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Snake Game
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
katerinabee1538




PostPosted: Sat Jan 21, 2012 10:40 pm   Post subject: Snake Game

What is it you are trying to achieve?
I have a game due on monday, but I've been having a problem with it.


What is the problem you are having?
Whenever the snake hits itself, it's supposed to exit the game but it's not working..


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
I did this because the "maze" is green, but my snake is red. I tried doing the same thing but instead of green, put red, but it doesn't work : if whatdotcolour (x+6, y-6) = green then
put "YOU LOSE"


[syntax="turing"]

PLEASE ANSWER ASAP, SINCE IT'S DUE ON MONDAY
Sponsor
Sponsor
Sponsor
sponsor
Alex C.




PostPosted: Sat Jan 21, 2012 11:01 pm   Post subject: RE:Snake Game

make the snake head a different color Razz
Wakening




PostPosted: Sun Jan 22, 2012 12:40 am   Post subject: Re: Snake Game

It all depends on how your program works in terms of the snake's body. The program should detect that the head has collided with the body like it does when it hits a wall. Use the debugging menu and go step by step through your program and try and figure out why the collision isn't being detected.
Alex C.




PostPosted: Sun Jan 22, 2012 1:11 am   Post subject: RE:Snake Game

@Wakening um, do you know how whatdotcolour works? Confused
katerinabee1538




PostPosted: Sun Jan 22, 2012 3:06 pm   Post subject: Re: Snake Game

here's what I have so far, but I still have a problem when the snake collides into itself, it doesn't exit. How would you change the colour o the snake's head? :S sorry I'm kinda a noob at programming


setscreen ("graphics: 1000; 650")
var x, y : int
var key : array char of boolean

Draw.FillBox (0, 0, 1000, 20, green)
Draw.FillBox (0, 0, 20, 650, green)
Draw.FillBox (980, 0, 1000, 650, green)
Draw.FillBox (0, 630, 1000, 650, green)
Draw.FillBox (500, 0, 550, 325, green)
Draw.FillBox (200, 500, 250, 650, green)
Draw.FillBox (750, 500, 800, 650, green)

x := 100
y := 100


loop

Input.KeyDown (key)
if key (KEY_UP_ARROW)
then
y := y + 5
elsif key (KEY_DOWN_ARROW)
then
y := y - 5
elsif key (KEY_RIGHT_ARROW)
then
x := x + 5
elsif key (KEY_LEFT_ARROW)
then
x := x - 5
end if


Draw.FillOval (x, y, 5, 5, 40)
View.Update
delay (15)


if whatdotcolour (x - 6, y + 6) = green then
cls
colour (40)


put " .oOOOo. Oo Oo oO o.OOoOoo "
put " .O o o O O O o o O "
put " o O o o o O O o "
put " O oOooOoOo O Oo O ooOO "
put " O .oOOo o O O o O "
put " o. O O o o O o "
put " O. oO o O o O O "
put " `OooO' O. O O o ooOooOoO "
put skip
put skip
put " .oOOOo. o 'O o.OOoOoo `OooOOo. "
put " .O o. O o O o `o "
put " O o o O o O O "
put " o O o o ooOO o .O "
put " O o O O' O OOooOO' "
put " o O `o o o o o "
put " `o O' `o O O O O "
put " `OoooO' `o' ooOooOoO O o "


exit
end if

end loop
Alex C.




PostPosted: Sun Jan 22, 2012 3:55 pm   Post subject: Re: Snake Game

Y U NO USE CODE TAGS!!!!!!!!!!!!

... oh gods, now that i looked at your code i am shocked Nuty Eyes
anyways i would change the circles to squares, make the head move as much as the square size so you could color up the snake behind you as you go...

pretty simple really
Alex C.




PostPosted: Sun Jan 22, 2012 4:02 pm   Post subject: RE:Snake Game

seriously, i would use actual collision detection instead of what dot color for the walls since you can break the game easily with your code
Aange10




PostPosted: Sun Jan 22, 2012 4:05 pm   Post subject: RE:Snake Game

Quote:

seriously, i would use actual collision detection instead of what dot color for the walls since you can break the game easily with your code


Don't double post. Just edit your original one.



There's nothing wrong with whatdotcolor(). It's accurate.

It took me about 5 seconds to fix your entire game. All I did was exactly what you wanted.

I drew the character's head [blue], and every time I moved I drew the head red, and then moved the head over.
Sponsor
Sponsor
Sponsor
sponsor
katerinabee1538




PostPosted: Sun Jan 22, 2012 4:31 pm   Post subject: Re: Snake Game

how would you change the colour of the head? can you fix it for me, because I have no idea how to do it lol
Aange10




PostPosted: Sun Jan 22, 2012 4:35 pm   Post subject: RE:Snake Game

No, I'm not going to fix it for you.

How do you change the color? Did you write this code?

You change the color by drawing it with a different parameter for the color.
katerinabee1538




PostPosted: Sun Jan 22, 2012 4:47 pm   Post subject: Re: Snake Game

I FIXED IT! yay thanks so much
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 11 Posts ]
Jump to:   


Style:  
Search: