I can not come up with a good architecture for my card game. I need help to understand how games usually are designed.
First, I will describe game rules.
Game Rules
Setup
- There are four players, each two player form a team.
- Each player gets 12 shuffled cards
- There are 4 blinded cards on table(river)
- Players order are like this
Betting
- Each player can pass or select a number greater than current bet between 100 to 160
- Betting starts from first player and circles until a team pass
- Once a player pass they can't bet anymore
- The team that wins the betting round should at least collect points equal to their bet in order to win the game
The team that lost the betting round should not allow the their team achieve their goal
If the team that won betting round gets all the points the other team will get negative points equal to their bet
- if the team that lost the betting round collects all the points the other team will get double negative points
Game flow and collecting points
- Player that won betting round (the king) gets four remaining cards on the table.
- Then she/he can save a set of four cards in their team cards bank without even playing them.
- The king will pick a suit as the ruler suit and let others know that
- King starts the game by putting a card from his/her hand on table. Each other player should play in this order
- if they have the same suit of that card in their hand, they have to play one of those cards
- if they don't have it, they can play any other suit
- After all other players played their hands, winner of the round will be:
- The one who has highest card if all cards are the same
- The one who has highest "ruler" card if there is any
- Winner of the round will collect cards and put it in their bank
- Player who won previous round will start the next round
- This will continue until everybody's hand is empty
Counting points
- Winning each round has 5 points. This means every 4 cards has at least 5 points.
- Having Ace, 10 or 5 in bank each adds 5 points
My Design
Classes
class Card {
string suit;
string rank
}
class Deck {
List cards = [];
List suits = ['S', 'H', 'D', 'C'];
List ranks = ['1', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A'];
private void init(){..}
void shuffle(){...}
}
class Game{
Deck deck = new Deck();
Player player1;
Player player2;
Player player3;
Player player4;
int _isOn = 0;
Game(this.player1, this.player2, this.player3, this.player4){
deck.makeCards();
deck.shuffle();
start();
}
void start(){
player1.cards.addAll( deck.cards.getRange(0, 12) );
player2.cards.addAll( deck.cards.getRange(12, 24) );
player3.cards.addAll( deck.cards.getRange(24, 36) );
player4.cards.addAll( deck.cards.getRange(36, 48) );
deck.cards.removeRange(0, 48);
}
String toJson(){
}
String toString(){
}
}
class Player{
String name;
int points;
List cards = [];
Player(this.name, {this.points});
String toJson(){}
String toString(){}
}
My Problem
Now that I've defined all these classes I don't know how to bind this definitions to a database (like Mongo) and control the game flow.
- Where should all that logic go?
- How should I keep state in a server/client scenario?
Note:
I'm using Dart to program this but I don't necessary want answers be written in Dart.