Add ol' JDoc
This commit is contained in:
parent
52a4c876fa
commit
7c55e049cf
@ -5,6 +5,8 @@ import java.awt.Graphics2D;
|
|||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Represents a food item.
|
||||||
|
* <p>
|
||||||
* Project: <strong>Snake</strong><br>
|
* Project: <strong>Snake</strong><br>
|
||||||
* File: <strong>Food.java</strong><br>
|
* File: <strong>Food.java</strong><br>
|
||||||
* Created: <strong>01.07.2020</strong><br>
|
* Created: <strong>01.07.2020</strong><br>
|
||||||
@ -18,23 +20,35 @@ public final class Food implements Updateable {
|
|||||||
private final int lengthBonus;
|
private final int lengthBonus;
|
||||||
private final Rectangle bounds;
|
private final Rectangle bounds;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a food item.
|
||||||
|
*
|
||||||
|
* @param color the color of the food item
|
||||||
|
* @param lengthBonus the length added to the snake when the food item is eaten
|
||||||
|
* @param bounds the bounds of the food item
|
||||||
|
* @since Snake 1.1
|
||||||
|
*/
|
||||||
public Food(Color color, int lengthBonus, Rectangle bounds) {
|
public Food(Color color, int lengthBonus, Rectangle bounds) {
|
||||||
this.color = color;
|
this.color = color;
|
||||||
this.lengthBonus = lengthBonus;
|
this.lengthBonus = lengthBonus;
|
||||||
this.bounds = bounds;
|
this.bounds = bounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkCollision(Snake snake) {
|
|
||||||
if (bounds.intersects(snake.getHead())) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(Graphics2D g) {
|
public void render(Graphics2D g) {
|
||||||
g.setColor(color);
|
g.setColor(color);
|
||||||
g.fill(bounds);
|
g.fill(bounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the length added to the snake when the food item is eaten
|
||||||
|
* @since Snake 1.1
|
||||||
|
*/
|
||||||
public int getLengthBonus() { return lengthBonus; }
|
public int getLengthBonus() { return lengthBonus; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the bounds of the food item
|
||||||
|
* @since Snake 1.1
|
||||||
|
*/
|
||||||
public Rectangle getBounds() { return bounds; }
|
public Rectangle getBounds() { return bounds; }
|
||||||
}
|
}
|
||||||
|
@ -55,8 +55,8 @@ public final class FoodFactory {
|
|||||||
FOOD_LENGTH_BONUSES[seed],
|
FOOD_LENGTH_BONUSES[seed],
|
||||||
new Rectangle(random.nextInt(width - 100) + 50,
|
new Rectangle(random.nextInt(width - 100) + 50,
|
||||||
random.nextInt(height - 100) + 50,
|
random.nextInt(height - 100) + 50,
|
||||||
seed * 10,
|
10 + seed * 5,
|
||||||
seed * 10
|
10 + seed * 5
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,13 @@ public final class Handler implements Updateable {
|
|||||||
|
|
||||||
private volatile Food food;
|
private volatile Food food;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a handler.
|
||||||
|
*
|
||||||
|
* @param snake the snake
|
||||||
|
* @param foodFactory the food factory
|
||||||
|
* @since Snake 1.1
|
||||||
|
*/
|
||||||
public Handler(Snake snake, FoodFactory foodFactory) {
|
public Handler(Snake snake, FoodFactory foodFactory) {
|
||||||
this.snake = snake;
|
this.snake = snake;
|
||||||
this.foodFactory = foodFactory;
|
this.foodFactory = foodFactory;
|
||||||
@ -29,6 +36,7 @@ public final class Handler implements Updateable {
|
|||||||
public void tick() {
|
public void tick() {
|
||||||
snake.tick();
|
snake.tick();
|
||||||
food.tick();
|
food.tick();
|
||||||
|
|
||||||
// Check for food collision
|
// Check for food collision
|
||||||
if (snake.getHead().intersects(food.getBounds())) {
|
if (snake.getHead().intersects(food.getBounds())) {
|
||||||
snake.addLength(food.getLengthBonus());
|
snake.addLength(food.getLengthBonus());
|
||||||
|
@ -60,7 +60,7 @@ public class Viewport extends Canvas {
|
|||||||
long time = System.currentTimeMillis();
|
long time = System.currentTimeMillis();
|
||||||
double dt = (time - lastTime) * 1E-3;
|
double dt = (time - lastTime) * 1E-3;
|
||||||
lastTime = time;
|
lastTime = time;
|
||||||
|
// TODO: Delta time adjustment
|
||||||
gameRoot.tick();
|
gameRoot.tick();
|
||||||
render();
|
render();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user