Hey,
I've downloaded a program with source code a while ago from this website, I was wondering if it is possible for anybody to help me understand some of the stuff in the code that I didn't really get?
#ANY help or comment is really appreciated
The program is the snake game
If it is possible then first I would like to start with the world and the following questions regarding the code below:
1) why r we setting color in this statement / Color color1= new Color(255,250,250);
if it is for the score then we didn't we do that in score actor
2) what is this part? from what I understood that we already added array in the part where we set the head and two other parts so what is the need of the following & what does it mean?
public void addArray()
{
Snake newSnake = new Snake;
System.arraycopy(snake, 0, newSnake, 0, snake.length); #don't seem 2 b able 2 wrap my head around this one
snake = newSnake;
}
3) here is almost same question, why do we have "add object/item" and then "add item" separately, what I understood is "public void add item" is to add an item to the world but "public void update" is to change & update what happens after the item is removed to add a new one?? is that correct
can we say that r1 & r2 below are x,y for the item ??
private void update()
{
int r1, r2;
r1 = Greenfoot.getRandomNumber(24);
r2 = Greenfoot.getRandomNumber(24);
addObject(new Item(), r1*20+10, r2*20+10); #don't get the multiplication here
----------------------------------------------------------------------------------------------
public class Bord extends World {
public Snake snake;
Color color1= new Color(255,250,250);
int a,b;
private Score thisScore;
private Item item;
public void act()
{
addItem();
}
public bord()
{
super(500, 500, 1);
Greenfoot.setSpeed(35);
snake = new Snake;
snake = new Snake("head");
snake = new Snake();
snake = new Snake();
addObject(snake, 110, 50);
addObject(snake, 90, 50);
addObject(snake, 70, 50);
addObject(new Wall(), 150, 381);
addObject(new Wall(), 350, 119 );
thisScore = new Score();
addObject(thisScore, 130, 5);
}
public void addArray()
{
Snake newSnake = new Snake;
System.arraycopy(snake, 0, newSnake, 0, snake.length);
snake = newSnake;
}
public void addItem()
{
List<Item> item = getObjects(Item.class);
if (item.isEmpty())
{
update();
}
}
public Score getScore()
{
return thisScore;
}
private void update()
{
int r1, r2;
r1 = Greenfoot.getRandomNumber(24);
r2 = Greenfoot.getRandomNumber(24);
addObject(new Item(), r1*20+10, r2*20+10);
}
}
------------------------------------------------------------------------------------------
Sorry for being annoying with too many questions & thanks in advance

