We are working on a simple turn-based card game. We would like to implement it using a design which let us create additional "monsters" and "events" later on (so the code should be flexible).
Also, we would like to separate the actual logic (who does what) from the presentation (view/rendering) so we could write a different renderer whenever we want (Unity, WPF, etc.)
This game is already playable on paper (we have a table, figures, cards, etc.) but we would like to speed up some things (for example the battle). And this would be a learning project. This is the reason why we would like to implement it in a nice way (instead of just "hacking" things together).
The main concept of the MVC pattern is to have the model, controller and view separated. In a fully-separated design the view can display the model by asking the controller to give some data. The view can also ask the controller to modify the model based on its input. However the controller has no knowledge about the view.
Our problem is that we would like to "generate the view" based on the "controller" (action). This might sound a little wierd but let me give you some examples:
In this game we have some special "event cards" and these are doing different things when the player meets with them. For example the "Wise" gives the player x gold based on a roll OR it gives the player his treasure if he has any. Since we are not storing the actual map in this program (we are playing on a physical table) the GM (Game Master) must choose the operation based on the current state of the game. This means that when the GM selects the "Wise" there should be two buttons, like "Give treasure" and "Give gold". This is when the controller/model/action defines the view.
Something like this:
- GM selects the player
- The player makes some action in real-life
- When the player enters a zone where an "event card" can be found, the GM selects the right "event card" on his tablet (for example)
- Then the selected event card defines the possible actions which defines the view (since the GM has to press some buttons)
It is not important that if we are generating the view (using a layout and filling it with text and buttons) or if we are creating the views by hand. The main problem is that we don't know how to "glue" them together. When the GM selects an event card, which view should we generate? Which button should execute which action? Sometimes a specific action requires another view to be shown. This seems like a hard coupling between the logic and the view.
Here is a mini code-snippet (note this is not the actual code, it's just an example).
interface IEventCard
{
void Selected();
}
class Wise : IEventCard
{
void Selected()
{
// add "Give treasure" action
// add "Give gold" action
}
}
class GameManager
{
IList<IEventCard> cards;
void Initialize()
{
// create cards
cards = new List<IEventCard>();
cards.Add(new Wise());
// ...
}
// called from the UI
void Select(int id)
{
IEventCard card = cards[id];
card.Selected();
// it should open a view
// the view should be populated with:
// - the name and description of the event card
// - buttons that execute the corresponding action
// some of these actions should open another views
// for example the "give treasure" action should open the "inventory screen" which lets the GM select the item
// or the "give gold" action should open a "roll the dice" window first to determine how much gold the player should get
// etc.
}
}
Sorry if it's hard to understand my description, I've tried to explain things as short as possible. We would appreciate if you could give us some tips, preferable some code snippets.