AIsOfCatan.GameController.BuildFirstSettlement C# (CSharp) Метод

BuildFirstSettlement() публичный Метод

Let a player build a settlement without a requirement for connectivity and free of charge The settlement still has to follow the distance rule and cannot be placed on top of another building
public BuildFirstSettlement ( Player player, Intersection intersection ) : GameState
player Player The player placing the settlement
intersection AIsOfCatan.API.Intersection The intersection to build a settlement on
Результат GameState
        public GameState BuildFirstSettlement(Player player, Intersection intersection)
        {
            if (board.GetPiece(intersection) != null)
                throw new IllegalBuildPositionException("The chosen position is occupied by another building");
            if (!board.HasNoNeighbors(intersection))
                throw new IllegalBuildPositionException("The chosen position violates the distance rule");
            if (!board.CanBuildPiece(intersection))
                throw new IllegalBuildPositionException("The chosen position is not valid");

            player.SettlementsLeft--;
            board = board.PlacePiece(intersection, new Piece(Token.Settlement, player.Id));
            return CurrentGamestate();
        }

Usage Example

Пример #1
0
 /// <summary>
 /// Build a settlement on the board
 /// If you try to build too close to another building a IllegalBuildPosition is thrown
 /// Must be called before BuildRoad, otherwise an IllegalActionException is thrown
 /// </summary>
 /// <param name="firstTile">The intersection</param>
 public void BuildSettlement(Intersection intersection)
 {
     if (settlementBuilt)
     {
         throw new IllegalActionException("Only one settlement may be built in a turn during the startup");
     }
     settlementPosition = intersection;
     controller.BuildFirstSettlement(player, intersection);
     settlementBuilt = true;
 }