I am a beginner at programming. I made this snake game in JavaFX to practice and improve my coding skills. I tried to make my code clean, but I'm not sure if it is, or if it is well-organized. I also tried to make the design object oriented-oriented. So I would like to ask your opinion on my code's structure and clarity. I would appreciate any advice you give me to improve.
This is what the game looks like:
SnakeGame
SnakeGameis the main class that is responsible for putting the game together and starting, restarting, ending the game, and taking user input.GameBoard
GameBoardextends PanePane. It is responsible for the snake and the fruit objects. It has an inner class, SnakeMovementSnakeMovement, that extends TimerTaskTimerTask. This task invokes the methods for checking for collisions, checking if the snake ate a fruit, and invokes the moveSnake()moveSnake()method in the Snake class.Snake
Snakeclass extends ArrayListArrayList<Rectangle>. It has the methods for creating the snake, moving the snake, and adding a new head to the snake when a fruit is eaten.Fruit
Fruitclass extends RectangleRectangle. It has the methods to get a random empty tile and to spawn the fruit in an empty tile.
Edit:
#root {
-fx-background-color: black;
}
#scoreBar {
-fx-alignment: center;
-fx-padding: 10px;
-fx-border-style: solid;
-fx-border-width: 0px 0px 2px 0px;
-fx-border-color: white;
}
#scoreIndicator {
-fx-text-fill: white;
-fx-font-size: 15px;
-fx-font-family: monospace;
}
#replay {
-fx-background-color: transparent;
-fx-text-fill: white;
-fx-font-size: 15px;
-fx-font-family: monospace;
}
#root {
-fx-background-color: black;
}
#scoreBar {
-fx-alignment: center;
-fx-padding: 10px;
-fx-border-style: solid;
-fx-border-width: 0px 0px 2px 0px;
-fx-border-color: white;
}
#scoreIndicator {
-fx-text-fill: white;
-fx-font-size: 15px;
-fx-font-family: monospace;
}
#replay {
-fx-background-color: transparent;
-fx-text-fill: white;
-fx-font-size: 15px;
-fx-font-family: monospace;
}