Alert icon
We're changing our privacy policy. This stuff matters.  Learn more  Dismiss

Snake Game in GridWorld

Loading...

Sign in or sign up now!
Alert icon
Upgrade to the latest Flash Player for improved playback performance. Upgrade now or more info.
481 views
Loading...
Alert icon
Sign in or sign up now!
Alert icon

Uploaded by on May 13, 2011

This game is supposed to be an excersize for learning programmers. It doesn't make sense to give away the code, but I've freely described how it works due to the number of comments/pms on how this and some of my other programs are made. I did this with just the knowledge of the case studies available online and a bit of Googling, so you should be able to as well.

This is a quick Snake game I wrote in under an hour. It's Yoshi themed- Yoshi is followed by its eggs. If you let it step on on egg or walk off the grid, it's game over. Eat the food (still rocks in this version, will update later) and gain an egg.

Code Walkthrough (- means carrot, those characters just aren't allowed.):
SnakeWorld-Actor- extends World-Actor-
public SnakeWorld(Yoshi, grid){
call super, then assign Yoshi or its location to a private variable.
}
public boolean keyPressed(str, loc){
Send Yoshi a setdirection method based on the controls of your choice (I have A, S, D, W, others like arrows and others like keypad).
Always return true on a keypress in GridWorld
}
public static newFood(){
place a sweet in any random empy location
}

Yoshi extends Bug
Yoshi(){super();}
void act(){
check if the location it's looking at is VALID, then if it is EMPTY. If so, move forward and create a new egg where it was previously at. If it is not empty but there is food, increment Yoshi's counter. If not, remove Yoshi from the game and let the world clear itself.
}
public getCount(){
return the number of times Yoshi ate food
}

Egg extends Rock(){
void act(){
increment age. if age is greater than getCount of Yoshi, remove the egg from the grid.
}

Category:

Science & Technology

Tags:

License:

Standard YouTube License

  • likes, 0 dislikes

Link to this comment:

Share to:

Uploader Comments (1232121212321212)

  • That goes so fast o.o

  • @bumrang Its because hypercam speeds up videos. It's not really that fast, but that bar on the bottom can change the speed to be faster than in the video.

see all

All Comments (4)

Sign In or Sign Up now to post a comment!
  • Could you help me with some of the code via messages or email?

    I really need help.

    Oh.... and Magikarp. x)

  • do u think u can email me this code, because I am trying to create sucha game my self and this would put me in the right direction? so can u ?

    I would really appreciate it. thank you.

Loading...
Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more