I need to design the classes of a game(simplified version mentioned here) played between 2 players. Game consists of multiple rounds between the 2 players.
I have come up with 3 classes: Game, Player, Round. Game consists of the 2 players. When the round is to be started, Round object is created on the fly and players are passed to round class from Game class.
class Game
{
Player _player1;
Player _player2;
int _maxRounds;
public Game(int maxRounds)
{
_player1 = new Player() { Name = "A" };
_player2 = new Player() { Name = "B" };
_maxRounds = maxRounds;
}
public void Play()
{
for (int i = 1; i <= _maxRounds; i++)
{
var round = new Round(i);
round.StartRound(_player1, _player2);
}
}
}
class Player
{
public string Name { get; set; }
public int Score { get; set; }
public void PlayAgainst(Player player)
{
//GameLogic that updates Score property of the current player
}
}
class Round
{
private int _roundCount;
public Round(int roundCount)
{
_roundCount = roundCount;
}
public void StartRound(Player player1, Player player2)
{
player1.PlayAgainst(player2);
}
}
Is this design correct? Should the players be part of the Round class instead of Game class? Game includes the Rounds and Players, but the Round also include Players.
Aucun commentaire:
Enregistrer un commentaire