Closed adamjw closed 9 years ago
So, lists. If you want to read a lot about generics: http://docs.oracle.com/javase/tutorial/java/generics/why.html
Here are some brief notes:
List<MyClass> myList = ...
where MyClass
would be the name of a class like String
or Integer
. (Integer
is a class and int
is a primitive. Hah!)for(MyClass myObject : myList) {
System.out.println(myObject);
}
for(int i = 0; i < myList.size(); i++) {
MyClass myObject = myList.get(i);
System.out.println(myObject);
}
The first is generally more elegant.
For updateMovingDirection
:
The keyboard
object of type BufferedKeyboard
holds a list of keys pressed since the last time the snake was moved. The order of the keys is from oldest to newest. That is, the key at index 0
was pressed before the key at index n > 0
. Keyboard keys are represented as integer values. To map the integer value to a direction, use the helper method getDirectionForKey
.
It would also be elegant to write a helper method that decides if that direction is valid. My suggestion would be to write a private method that returns true
if the direction is valid, and false
otherwise.
For move
:
Note that the Position
class is immutable, too. Look through the Snake
class's methods to see what will help you (F3
to navigate to the definition).
Press space to start the game.
Implement the two functions in
snake.game.controller.SnakeController
:updateMovingDirection
andmove
. These two calls will need to be added toupdateLogic
insnake.game.SnakeGame
.Acceptance Criteria: