Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
fp2025:lab08 [2026/04/23 16:51] silviu |
fp2025:lab08 [2026/04/23 16:52] (current) silviu |
||
|---|---|---|---|
| Line 6: | Line 6: | ||
| **8.1.** Add a field of type `Point` that represents the snake head that is randomly placed on the grid. | **8.1.** Add a field of type `Point` that represents the snake head that is randomly placed on the grid. | ||
| + | |||
| **8.2.** Add a field that represents the snake body. | **8.2.** Add a field that represents the snake body. | ||
| + | |||
| **8.3.** Add a field that represents the apple, the apple needs to be placed randomly on the grid (Hint: make a grid of points and filter out the points that represent the snake, then pick a point randomly from that grid) | **8.3.** Add a field that represents the apple, the apple needs to be placed randomly on the grid (Hint: make a grid of points and filter out the points that represent the snake, then pick a point randomly from that grid) | ||
| + | |||
| **8.4.** Add a field of type `Direction` that represents the current direction the snake is taking. | **8.4.** Add a field of type `Direction` that represents the current direction the snake is taking. | ||
| + | |||
| **8.5.** Implement the `getCellType` function that takes a point and determinates which point type it is, snake head, snake body, apple or just an empty cell. | **8.5.** Implement the `getCellType` function that takes a point and determinates which point type it is, snake head, snake body, apple or just an empty cell. | ||
| + | |||
| **8.6.** Implement the `changeDir` that sets the current direction the snake is moving. | **8.6.** Implement the `changeDir` that sets the current direction the snake is moving. | ||
| + | |||
| **8.7.** Implement the `step` function that: | **8.7.** Implement the `step` function that: | ||
| - | - moves the snake in the current direction | + | * moves the snake in the current direction |
| - | - if the snake moves over the apple the apple is consumed, a new apple is randomly placed on the grid and the snake body gets a new segment | + | * if the snake moves over the apple the apple is consumed, a new apple is randomly placed on the grid and the snake body gets a new segment |
| - | - if the snake moves over it's body the game is over | + | * if the snake moves over it's body the game is over |
| - | - if the game is over nothing moves | + | * if the game is over nothing moves |
| **8.8** Run the game and try playing it, use the arrow keys to change the direction the snake moves. | **8.8** Run the game and try playing it, use the arrow keys to change the direction the snake moves. | ||
| + | |||
| **8.9.** (Bonus) Implement the `setReverse` activated by pressing the `R` key with the following behavior: | **8.9.** (Bonus) Implement the `setReverse` activated by pressing the `R` key with the following behavior: | ||
| - | - if the set value is false the game plays normal and at each step the current state of the game is saved | + | |
| - | - if the set value is true the game will go at each call of the `step` function back showing the previous game state such that the game plays alone in reverse as you played until pressing the `R` key. | + | * if the set value is false the game plays normal and at each step the current state of the game is saved |
| + | * if the set value is true the game will go at each call of the `step` function back showing the previous game state such that the game plays alone in reverse as you played until pressing the `R` key. | ||