- General Structure of Android game
- Gui with Android
- Source Code
- Download Android Snake Game (Source Code attached)
“Java Swing: Snake with different Guis”. The only difference is that the AndroidGameController now actually does run the main game loop in its own so that the updating of the view works (over a Handler) – otherwise the execution of the logic would block the updating of the view.
Here is a UML class diagram of the general structure including the new android classes as well as the old Swing once.
– CursorThe input to the cursor can be received with a simple OnKeyListener. The last input is saved in a field and retrieved by the GameController when needed (so only the last key pressed in one game turn will be applied to the game).
– TouchscreenIt turned out that the gathering of input via the touch screen is a little more complicated. The different text view do not cover the whole game field, so if the player would touch between them, the input would not be registered when using OnItemClickListener. I then used a OnTouchListener for the whole gridview and translated the absolute position of the touch event. This does work, but seems to be not the optimal solution. I will leave it like this anyways because I expect that most users will provide input via the cursor.
Snake Android [90.2 kB]