« All Events
5 PM – Android Game Dev – Gamas
November 4, 2023 @ 5:00 pm - 6:00 pm
Today We Did
- We continued on Snake and Apple game.
- We added Snake into the screen and using android.os.Handler to move the snake once every 200 milliseconds.
Homework
- We need to change the direction of snake movement according to the arrow button that user presses.
- Inside GameBoardView.java
- Add a new attribute direction.
- Add a method setSnakeDirection(String direction)
- Change code inside update() method to increase and decrease snake.x and snake.y according to attribute direction.
- Inside GameActivity.java,
- get GameBoardView using findViewById(R.id.gameBoardView) method.
- when user click the right arrow, call gameBoardView.setSnakeDirection(“RIGHT)
- when user click the left arrow, call gameBoardView.setSnakeDirection(“LEFT)
- when user click the up arrow, call gameBoardView.setSnakeDirection(“UP)
- when user click the down arrow, call gameBoardView.setSnakeDirection(“DOWN)