-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFood.java
More file actions
33 lines (23 loc) · 845 Bytes
/
Food.java
File metadata and controls
33 lines (23 loc) · 845 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
public class Food {
private snake snake = new snake();
private int foodX; // Stores X pos of our food
private int foodY; // Stores Y pos of our food
// Used to determine random position of food
private final int RANDOMPOSITION = 40;
public void createFood() {
// Set our food's x & y position to a random position
int location = (int) (Math.random() * RANDOMPOSITION);
foodX = ((location * board.getDotSize()));
location = (int) (Math.random() * RANDOMPOSITION);
foodY = ((location * board.getDotSize()));
if ((foodX == snake.getSnakeX(0)) && (foodY == snake.getSnakeY(0))) {
createFood();
}
}
public int getFoodX() {
return foodX;
}
public int getFoodY() {
return foodY;
}
}