Section 7.3 Snake with Queues Tutorial
Subsection 7.3.1 Goals
- The classic game of Snake. Move a "snake" (line of sprites) along a 2D grid attempting to run over a randomly placed object to help it grow.
- If it runs into itself the game is over and the player has lost.
- The object of the game is to make the snake as big as possible.
- Represent the snake as a queue
- The Snake must avoid bombs that make it smaller
Subsection 7.3.2 Programming Tasks
- Create a function that generates the apple object into a random cell on the grid.
- Create a function that generates the bomb object into a random cell on the grid.
- Create a function that handles the condition of the snakes head interacting with the food object. Make sure the snakes body grows and the object is gone after a collision. The growing will use enqueuing of a linked list.
- Create a function that handles the condition of the snakes head interacting with the bomb object. Make sure the snakes body shrinks and the object is gone after a collision. The shrinking will use dequeuing of a linked list.
- Implement enqueue and dequeue functionality
Subsection 7.3.3 Getting Started
You can begin by downloading the starting class here: SnakeScaffold-1.java 1
There will be 7 functions that will need editing:
- initialize() //Init the queue and size of snake (10 points)
- plantBomb() //Choose bomb position on board (10 points)
- plantApple() //Choose apple position on board (10 points)
- detectApple() //Detect if snake collides with apple (5 points)
- detectBomb() //Detect if snake collides with bomb (5 points)
- enqueue() // enqueue a Block object onto the snake (10 points)
- dequeue() //dequeue a Block object from the snake (10 points)
Each of these functions have corresponding TO-DO comments on how to complete them. It is recommended to complete these functions in the order above. To move the snake you can use the arrow keys.
Subsection 7.3.4 Visualizing the Program
You must use the https://bridges-games.herokuapp.com 2 site to run and test your project. You should be able to use the same BRIDGES account on this site. Once you run your code, the program will continue to run until stopped manually. Once you run your code you can go onto the site, and go to your assignments page. From here you can click the "connect to game button" that will start the game.
If you would like to stop your game, you can manually stop the program from your IDE. Before running the program again, you must manually stop your program from the IDE. If you forget this step, the program will run multiple instances of the game creating some errors in server communication. If this happens, just close and reopen the project IDE.
You have attempted of activities on this page.
uncc.instructure.com/courses/16965/files/21470907?wrap=1
bridges-games.herokuapp.com/https://bridges-games.herokuapp.com/