Apply suggestions from code review
Co-authored-by: delvh <dev.lh@web.de>
This commit is contained in:
parent
7c55e049cf
commit
04931dfd99
@ -12,7 +12,7 @@ import java.awt.Rectangle;
|
||||
* Created: <strong>01.07.2020</strong><br>
|
||||
*
|
||||
* @author Kai S. K. Engelbart
|
||||
* @since Snake 1.1
|
||||
* @since Snake 1.2
|
||||
*/
|
||||
public final class Food implements Updateable {
|
||||
|
||||
@ -26,7 +26,7 @@ public final class Food implements Updateable {
|
||||
* @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
|
||||
* @since Snake 1.2
|
||||
*/
|
||||
public Food(Color color, int lengthBonus, Rectangle bounds) {
|
||||
this.color = color;
|
||||
@ -42,13 +42,13 @@ public final class Food implements Updateable {
|
||||
|
||||
/**
|
||||
* @return the length added to the snake when the food item is eaten
|
||||
* @since Snake 1.1
|
||||
* @since Snake 1.2
|
||||
*/
|
||||
public int getLengthBonus() { return lengthBonus; }
|
||||
|
||||
/**
|
||||
* @return the bounds of the food item
|
||||
* @since Snake 1.1
|
||||
* @since Snake 1.2
|
||||
*/
|
||||
public Rectangle getBounds() { return bounds; }
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public final class FoodFactory {
|
||||
*
|
||||
* @param width the width of the viewport
|
||||
* @param height the height of the viewport
|
||||
* @since Snake 1.1
|
||||
* @since Snake 1.2
|
||||
*/
|
||||
public FoodFactory(int width, int height) {
|
||||
this.width = width;
|
||||
@ -45,7 +45,7 @@ public final class FoodFactory {
|
||||
|
||||
/**
|
||||
* @return a new food item
|
||||
* @since Snake 1.1
|
||||
* @since Snake 1.2
|
||||
*/
|
||||
public synchronized Food spawn() {
|
||||
nextSpawnTime = System.currentTimeMillis() + random.nextInt(15000) + 1000;
|
||||
@ -63,7 +63,7 @@ public final class FoodFactory {
|
||||
|
||||
/**
|
||||
* @return the time after which a new food item should be spawned
|
||||
* @since Snake 1.1
|
||||
* @since Snake 1.2
|
||||
*/
|
||||
public long getNextSpawnTime() { return nextSpawnTime; }
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import java.awt.Graphics2D;
|
||||
* Created: <strong>01.07.2020</strong><br>
|
||||
*
|
||||
* @author Kai S. K. Engelbart
|
||||
* @since Snake 1.1
|
||||
* @since Snake 1.2
|
||||
*/
|
||||
public final class Handler implements Updateable {
|
||||
|
||||
@ -24,7 +24,7 @@ public final class Handler implements Updateable {
|
||||
*
|
||||
* @param snake the snake
|
||||
* @param foodFactory the food factory
|
||||
* @since Snake 1.1
|
||||
* @since Snake 1.2
|
||||
*/
|
||||
public Handler(Snake snake, FoodFactory foodFactory) {
|
||||
this.snake = snake;
|
||||
|
@ -147,7 +147,7 @@ public class Snake implements Updateable {
|
||||
|
||||
/**
|
||||
* @return the current {@link Direction} of the snake
|
||||
* @since Snake 1.0
|
||||
* @since Snake 1.2
|
||||
*/
|
||||
public Direction getDirection() { return direction; }
|
||||
|
||||
@ -159,7 +159,7 @@ public class Snake implements Updateable {
|
||||
|
||||
/**
|
||||
* @return a rectangle representing the head of the snake
|
||||
* @since Snake 1.1
|
||||
* @since Snake 1.2
|
||||
*/
|
||||
public Rectangle getHead() { return tiles.get(0); }
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ public interface Updateable {
|
||||
* Here should the actions be implemented that are supposed to happen when a new
|
||||
* frame gets created.
|
||||
*
|
||||
* @since Snake 1.0
|
||||
* @since Snake 1.2
|
||||
*/
|
||||
default void tick() {}
|
||||
|
||||
|
@ -14,7 +14,7 @@ import java.util.TimerTask;
|
||||
* Created: <strong>01.07.2020</strong><br>
|
||||
*
|
||||
* @author Kai S. K. Engelbart
|
||||
* @since Snake 1.0
|
||||
* @since Snake 1.2
|
||||
*/
|
||||
public class Viewport extends Canvas {
|
||||
|
||||
@ -33,7 +33,7 @@ public class Viewport extends Canvas {
|
||||
|
||||
/**
|
||||
* @param gameRoot the game object responsible for updating the rest
|
||||
* @since Snake 1.0
|
||||
* @since Snake 1.2
|
||||
*/
|
||||
public Viewport(Updateable gameRoot) {
|
||||
this.gameRoot = gameRoot;
|
||||
@ -43,7 +43,7 @@ public class Viewport extends Canvas {
|
||||
/**
|
||||
* Starts the render task.
|
||||
*
|
||||
* @since Snake 1.1
|
||||
* @since Snake 1.2
|
||||
*/
|
||||
public void start() {
|
||||
if (renderTask != null)
|
||||
@ -72,7 +72,7 @@ public class Viewport extends Canvas {
|
||||
/**
|
||||
* Stops the render task.
|
||||
*
|
||||
* @since Snake 1.1
|
||||
* @since Snake 1.2
|
||||
*/
|
||||
public void stop() {
|
||||
renderTask.cancel();
|
||||
|
@ -32,7 +32,7 @@ public class Endscreen extends JDialog {
|
||||
public Endscreen(int score) {
|
||||
this.score = score;
|
||||
setTitle("Endscreen");
|
||||
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
||||
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 700, 700);
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
|
Loading…
Reference in New Issue
Block a user