예제 #1
0
파일: Hex.cs 프로젝트: epicvrvs/Shashkrid
 public Hex(Position position)
 {
     Position = position;
     Piece = null;
     Neighbours = new List<Hex>();
 }
예제 #2
0
파일: Game.cs 프로젝트: epicvrvs/Shashkrid
 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);
     }
 }
예제 #3
0
파일: Game.cs 프로젝트: epicvrvs/Shashkrid
 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;
 }
예제 #4
0
파일: Game.cs 프로젝트: epicvrvs/Shashkrid
 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;
 }
예제 #5
0
파일: Game.cs 프로젝트: epicvrvs/Shashkrid
 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++;
 }