Mon Feb 11, 2008 7:27 pm
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;
}
Wed Jan 14, 2009 10:57 am
Thu Jan 15, 2009 12:03 am
Fri Feb 20, 2009 9:19 am
Thu May 14, 2009 3:11 pm
Fri May 22, 2009 6:49 pm
Mon May 25, 2009 8:41 am
Tue Aug 18, 2009 3:40 pm
Tue Aug 18, 2009 4:21 pm
Tue Sep 22, 2009 8:39 pm
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
Powered by phpBB © phpBB Group.