Edit this page Backlinks This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ====== Lab 08: Games ====== We are going to implement a Snake game in Scala. Please download the code for the game from [[https://github.com/VU-Programming/OOFP-snake/tree/master|OOFP-snake]] and you will need to install the Gradle plugin for VSCode (for Intellij it works out of the box). To run the code from VSCode run it from the Gradle plugin -> Tasks -> application -> run. All the code you need to implement will be in the `src/snake/logic/GameLogic.scala` file and you can take a look at the classes that are used in that file. **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.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.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.7.** Implement the `step` function that: - 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 it's body the game is over - 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.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.