Friday, July 1, 2011

The Game of Snake - Part 1

Play the Game First


You need to have flash installed.
5 difficulty settings, 10 level layouts, Enjoy !






Source Code

You have just played the flash version of the game. Since this is a Java programming blog, the source code of the Java version will be provided at the end of this article. Of course it won't be compiled to a flash. Instead it will be compiled to a Java application. Nevertheless, the game control is identical to the flash version.

Compile and Run

javac Snake10.java
java Snake10

Adjusting difficulties

The Java version doesn't provide interface to adjust the game difficulty. However, as a programmer, you can do a little hack to the source code. Just locate the line :
int difficulty = 3;  // 1=hardest, 5=easiest
in the method gameLoop(). Change it to any value between 1 and 5.

Explanation of Source Code

Selected portions of the source code will be explained in subsequent articles.

Related Posts


Source Listing


1 comment:

  1. hi Ivan i was wondering if you could explain the code for me because i have to make a game for my java class and i wanted to make a snake game, and if understood how your code worked, i was going to change it to fit my taste

    ReplyDelete