I am trying to write a simple domino (five-game) game with 2 players. I must say I am very bad at OOP design, and so I don't want to get myself too deep into coding then realize I have a bad design to start with. I'd appreciate if someone shed some light on how to better design this.
Here is summary of the game:
- there are 28 dominos
- there will be 2 players
- initially, each player receives 7 random tiles, the remaining 14 tiles are left to the bone yard pool
- initially, whichever player got the heaviest tile gets to play first
- whoever scores x points first wins the game (e.g: 100,150,etc)
Here is what I have so far:
Player
class:
public class Player
{
//properties
string ID { get; set; } //player id
int Wins { get; set; }
int Losses { get; set; }
bool IsMyTurn { get; set; }
List<Domino> Hand { get; set; } //each player will have a list of domino tiles
void ShowHand(); //just display what's in their hands if needed
void PlayerStatistic(); //get user's historical wins/losses, number game played, etc.
}
Game
class:
public class Game
{
//properties
int ID { get; set; } //game id, assuming each player can play multiple games as once
Player PlayerTurn { get; set; } //signifies if it is his turn
Dominos DominoSet { get; set; }
List<string> Board { get; set; }
void Move(Player player, Domino domino);
public Game(Player player1, Player player2)
{
ID = 0; //TODO
DominoSet = new Dominos(); //create a set of dominos
Board = new List<string>(); //create a new game board that store all the moves
Domino curDomino = InitializePlayers(player1, player2, DominoSet.AllDominos);
DominoSet.AllDominos.RemoveRange(0, 14); //remove all dominos that have been assigned to 2 players
//...and other good stuffs
}
}
Domino
class, which was intended to describe a single domino:
public class Domino
{
public string Name { get; set; } // "0,1", "0,2", etc.
public int Head { get; set; } //each domino has 2 side, i called it head and tail
public int Tail { get; set; }
public int Weight { get; set; } //a 0-27, e.g: a "6,6" domino would have the highest predifined weight of 27
public bool IsDouble { get; set; } //whether the tile is double or not
public Domino(string name, int head, int tail, int weight){
Name = name;
Head = head;
Tail = tail;
Weight = weight;
IsDouble = (head == tail ? true : false);
}
}
Dominos
class, which was intended for use to store a list of 28 domino set, and perform other actions such as shuffle dominos, track domino, etc.:
public class Dominos
{
private string[] _tiles = {"0,1","0,2","0,3","0,4","0,5","0,6",
"1,2","1,3","1,4","1,5","1,6",
"2,3","2,4","2,5","2,6",
"3,4","3,5","3,6",
"4,5","4,6",
"5,6",
"0,0","1,1","2,2", "3,3", "4,4","5,5","6,6"};
public List<Domino> AllDominos { get; set; }
public void Shuffle(){} //radomize the dominos
public Dominos()
{
AllDominos = new List<Domino>();
for (int i = 0; i < _tiles.Length; i++)
{
string[] word = _tiles[i].Split(',');
Domino d = new Domino(_tiles[i], int.Parse(word[0]), int.Parse(word[1]), i);
AllDominos.Add(d);
}
Shuffle();//randomize the domino list
}
}
Main program to wire things together:
class Program
{
static void Main(string[] args)
{
Player _player1 = new Player("Player1");
Player _player2 = new Player("Player2");
Game _game = new Game(_player1, _player2);
}
}