Total members 11893 |It is currently Tue Nov 05, 2024 6:35 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka



Go to page 1, 2, 3  Next



* Project Name:   Snake 2d-java snake code
* Programmer:   msi_333
* Type:   Game
* Technology:  Java
* IDE:   NetBeans
* Description:   This is the simple snake game that i made . It is a net beans Project so if u don't have it you will find all the codes in folder "src". There is also an executable called M_snake.jar in the folder "dist" which u can run the game without compiling. To run the game you must have JVM(Java Virtual Machine).

1. download M_snake.rar
2. Unrar it.
3. run the game
have fun, you can make your changes in the code to fix bugs and add new features.


Attachment:
File comment: Simple snake screen shot
snake.GIF
snake.GIF [ 5.3 KiB | Viewed 131713 times ]

Here is a sample code :
engin.java
java code
package Snake_engin;

import javax.swing.JOptionPane;
import m_snake.MainPanel.snakeBody.Food;
import m_snake.MainPanel.snakeBody.snake;
/**
*
* @author SQLStudent
*/
public class engin {

/** Creates a new instance of engin */
public engin()
{

}

public void Move_mySnake(int newDirection,boolean food_eaten)
{


if(!Game_Over)
{

switch(newDirection)
{
case 1: if(direction!=3)
{
my_snake.put_Head_postion(0,-step_to_move);
direction=1;
}
else move_as_last(direction);
break;//UP

case 2: if(direction!=4)
{
my_snake.put_Head_postion(step_to_move,0);
direction=2;
}
else move_as_last(direction);
break;//RIGHT
case 3:
if(direction!=1)
{
my_snake.put_Head_postion(0,step_to_move);
direction=3;
}
else move_as_last(direction);
break;//DOWN

case 4:
if(direction!=2)
{
my_snake.put_Head_postion(-step_to_move,0);
direction=4;
}
else move_as_last(direction);

break;//LEFT
}


if(food_eaten)
{
my_snake.Increase_lenght();// IF the Snake ate new Food
}
my_snake.Move_snake();


if((my_snake.getHeadX()==snakeFood.get_int_X())&&(my_snake.getHeadY()== snakeFood.get_int_Y()))
{
snakeFood.getFood();
Score+=20;

my_snake.Increase_lenght();
while(check_food_place())
{
snakeFood.getFood();
}

}

Game_Over=my_snake.check_game_over();


}
if(Game_Over)
{
JOptionPane.showConfirmDialog(null,"Score = "+Integer.toString(Score),"Your Score",JOptionPane.DEFAULT_OPTION);
// Thread.yield();
}


}
public void move_as_last(int diirec)
{
switch(direction)
{
case 1:

my_snake.put_Head_postion(0,-step_to_move);


break;//UP

case 2:
my_snake.put_Head_postion(step_to_move,0);

break;//RIGHT
case 3:

my_snake.put_Head_postion(0,step_to_move);

break;//DOWN

case 4:

my_snake.put_Head_postion(-step_to_move,0);


break;//LEFT
}


}
public int[] return_Snake_postionsX()
{
return my_snake.get_All_postionsX();
}
public int[] return_Snake_postionsY()
{
return my_snake.get_All_postionsY();
}

public int get_Oval_size()
{
return my_snake.getOval_Size();
}

public int get_my_snake_lenght()
{
return my_snake.get_lenght();
}
public void set_step_length()
{
step_to_move=5;
}
public int get_Food_X()
{
return (int)snakeFood.getX();
}
public int get_Food_Y()
{
return (int)snakeFood.getY();
}
public boolean check_food_place()
{
int xfood=(int)snakeFood.getX();
int yfood=(int)snakeFood.getY();
if(xfood>260||yfood>260)return true;
else
return my_snake.compare_with_foodPostion(xfood,yfood);

}

public boolean get_Game_over()
{
return Game_Over;
}

private int direction=2;
private boolean Game_Over;
private boolean Moving_vertical=false;
private snake my_snake=new snake();
private final Food snakeFood=new Food();
private int step_to_move=20;
private int Score;

}

Attachment:
File comment: Java Snake Project
M_snake.rar [32.62 KiB]
Downloaded 40764 times




_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

For this message the author DrRakha has received thanks - 3: ductri09t3, gyuriteso, Ranest

can i have u source code...
thnk u if can..



Author:
Newbie
User avatar Posts: 1
Have thanks: 0 time

You can download the package for free , it includes all the java source files.


_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

Thank you for this i like it!



Author:
Newbie
User avatar Posts: 3
Have thanks: 0 time

respect thank you



Author:
Newbie
User avatar Posts: 1
Have thanks: 0 time

thank you



Author:
Newbie
User avatar Posts: 1
Have thanks: 0 time

Hi, I would like to make a terminal (non gui, the dos texty type interface) snake game and have a general idea of what to do but would like some help with the following: how do I make the walls? and how do I catch the keyboard input to move the snake (preferrably would like to use the arrow keys such that up moves the snake up, left moves the snake left, right moves the snake right, and down moves the snake down)? Thanks!



Author:
Newbie
User avatar Posts: 5
Have thanks: 0 time

Thank you very much.



Author:
Newbie
User avatar Posts: 1
Have thanks: 0 time

I played this 20 years ago on my Atari console,

and then again about 10 yeard ago on my old Nokia,

Love the game :) I can cancel my Wow Subscription now



Author:
Newbie
User avatar Posts: 5
Have thanks: 0 time

thank u so much



Author:
Newbie
User avatar Posts: 5
Have thanks: 0 time
Post new topic Reply to topic  [ 29 posts ]  Go to page 1, 2, 3  Next

  Related Posts  to : Snake Java (SE) Game
 need help in java 1.4 snake game project     -  
 Snake Game 2D (J2SE)     -  
 Simple Snake Game     -  
 Need Snake Game implemented using J2me on Mobile     -  
 2d game in java-Monster-Java 2D Game Graphics and Animation     -  
 ping pong game - java-Sticker-ball game (modified v1.1)     -  
 fill all Squares of game board - 2d Java Game Example     -  
 Chess Game in Java     -  
 Need help getting started on a small java game?     -  
 JChess game (2 players Java chess )     -  



cron






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com