Esempio n. 1
0
 public Hex(Position position)
 {
     Position = position;
     Piece = null;
     Neighbours = new List<Hex>();
 }
Esempio n. 2
0
 bool PieceCanReachHex(Piece piece, Hex hex)
 {
     if (piece.Type.PassThrough)
         return piece.Type.Movement >= piece.Hex.Position.GetDistance(hex.Position);
     else
     {
         HashSet<Position> map = new HashSet<Position>();
         GetMovementMap(piece.Hex, piece.Type.Movement, map);
         piece.Type.FilterMovementMap(piece.Hex.Position, piece.Owner.Colour, map);
         return map.Contains(hex.Position);
     }
 }
Esempio n. 3
0
 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;
 }
Esempio n. 4
0
 int GetAttackSum(Piece attacker, Piece defender)
 {
     int attackSum = attacker.Type.Attack;
     foreach (Hex neighbour in defender.Hex.Neighbours)
     {
         Piece piece = neighbour.Piece;
         if (piece != null && piece != attacker && piece.Owner == attacker.Owner)
             attackSum += piece.Type.Support;
     }
     return attackSum;
 }
Esempio n. 5
0
 public void PromotePiece(Position position, PieceTypeIdentifier type)
 {
     position.CheckValidity();
     if (CurrentTurnActions >= GameConstants.ActionsPerTurn)
         throw new GameException("You may not perform any more actions this turn");
     Hex hex = GetHex(position);
     Piece piece = hex.Piece;
     if (piece == null)
         throw new GameException("There is no piece to promote, the specified hex is empty");
     if (piece.Type.Identifier != PieceTypeIdentifier.Pawn)
         throw new GameException("Only pawns may be promoted");
     if (!piece.CanMove)
         throw new GameException("This piece has already been moved this turn and can hence not be promoted");
     if(type == PieceTypeIdentifier.Pawn)
         throw new GameException("Invalid promotion identifier");
     bool isClear = true;
     foreach (Hex neighbour in hex.Neighbours)
     {
         Piece neighbourPiece = neighbour.Piece;
         if (neighbourPiece != null && !object.ReferenceEquals(neighbourPiece.Owner, CurrentTurnPlayer))
         {
             isClear = false;
             break;
         }
     }
     if (!isClear)
         throw new GameException("You cannot promote a piece that is in direct proximity of an opponent's piece");
     Piece newPiece = new Piece(GameConstants.Pieces[type], CurrentTurnPlayer);
     hex.Piece = newPiece;
     newPiece.Hex = hex;
     newPiece.CanMove = false;
     piece.Hex = null;
     CurrentTurnActions++;
 }