public Game() { Black = new Player(PlayerColour.Black); White = new Player(PlayerColour.White); Players = new List<Player>() { Black, White, }; CurrentTurnPlayer = Black; CurrentTurn = 1; CurrentTurnActions = 0; _Winner = null; CreateGrid(); DeployPawns(Black); DeployPawns(White); }
bool PlayerWasAnnihilated(Player annihilator, Player victim) { if (victim.Pieces.Any()) return false; _Winner = annihilator.Colour; return true; }
List<Hex> GetZoneOfControl(Player player) { int initial; int direction; if (player.Colour == PlayerColour.Black) { initial = 0; direction = 1; } else { initial = GameConstants.GridSizeY - 1; direction = -1; } List<Hex> zone = new List<Hex>(); for (int x = 0; x < GameConstants.GridSizeX; x++) { int? maximum = null; for (int y = initial; y >= 0 && y < GameConstants.GridSizeY; y += direction) { Position position = new Position(x, y); if (!position.IsValid()) break; Hex hex = GetHex(position); Piece piece = hex.Piece; if (piece == null) continue; else if (object.ReferenceEquals(piece.Owner, player)) maximum = y; else break; } if (maximum == null) continue; for (int y = initial; ; y += direction) { Position position = new Position(x, y); Hex hex = GetHex(position); zone.Add(hex); if (y == maximum) break; } } return zone; }
void DeployPawns(Player player) { int firstRankY; int secondRankY; int secondRankInitialX; int secondRankFinalX; if(player.Colour == PlayerColour.Black) { firstRankY = 2; secondRankY = 1; secondRankInitialX = 6; secondRankFinalX = 12; } else { firstRankY = 6; secondRankY = 7; secondRankInitialX = 0; secondRankFinalX = 6; } for (int x = 0; x < GameConstants.GridSizeX; x++) { Position position = new Position(x, firstRankY); DeployPawn(position, player); } for (int x = secondRankInitialX; x <= secondRankFinalX; x++) { Position position = new Position(x, secondRankY); DeployPawn(position, player); } }
void DeployPawn(Position position, Player player) { Hex hex = GetHex(position); Piece piece = new Piece(GameConstants.Pieces[PieceTypeIdentifier.Pawn], player); player.Pieces.Add(piece); hex.Piece = piece; }
public void NewTurn() { if (object.ReferenceEquals(CurrentTurnPlayer, Black)) CurrentTurnPlayer = White; else CurrentTurnPlayer = Black; CurrentTurn++; CurrentTurnActions = 0; foreach (Player player in Players) { foreach (Piece piece in player.Pieces) piece.CanMove = true; } }