Reputation: 79615
I'm working on implementing an android version of the board game Cloud 9. I have never designed games, android apps (except 1-2 hello world apps) or even programs with GUI before (did a lot of CLI), and I have some questions regarding the design.
The game is turn-based, so there's no real-time considerations here, and I was wondering what was best to do. The game consists of pretty simple 2-3-options selections for each decision the player has to make, and for starters I want to make it "text-based", i.e., have a TextView with the game "log" on it and whenever the human player has to make a decision, he is given 2-3 buttons with the options he can play. The game consists of several rounds and levels.
I started out implementing the game "core" without a GUI altogether and with AI players. I then tried to figure out how to allow for human players, GUI, etc. My current design idea is a GameEventListener
class which will be informed of different events in the game (round begins, round ends, a certain player did a certain action, etc.), and have the activity implement it and thus it can draw/write to the screen what happens, etc.
However, I'm not sure if this is the best approach, and how the Android part should be implemented (for example, I would like that after some events, the player will have a "continue" button, so he can see what was done before the game continues - how do I wait for the button to be pressed? If I return from the listener function, the game will continue). Any suggestion on how to proceed?
Upvotes: 3
Views: 1721
Reputation: 5457
You can take a look at my Tetrads Drop game here for GUI and some of my approach http://code.google.com/p/tetrads-drop-lite/ It is a tetris clone and can play with another player over the internet. If you need help with some GUI code, Ed Burnette's "Hello, Android" is a good book to start.
Updated
It is quite similar to what you are designing.
There are these package hierarchies
-com.aunndroid.Engine (handling game logic)
-com.aunndroid.View (managing 2D Views)
-com.aunndroid.Tolk (communication between deivces)
Upvotes: 1
Reputation: 1117
Since your game is turn-based, then I think design such as GameEventListener is OK. Basically,this kind of GUI can be implemented by replying to the events. You can assign each UI component your listener. For example, button.setOnClickListener(Your listener class);
For different buttons, you can create different listener classes for them respectively, and you can collect them in one GameEventListener as well. If the operation reacted to the events is not complicated, we can even use anonymous class:
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v){
//do your operations here(e.g. get input, update UI)
}});
Upvotes: 0