コード例 #1
0
        /// <summary>
        /// Moves a gama piece n number of steps taking into account game rules of legal movement.
        /// </summary>
        /// <param name="gamePiece"></param>
        /// <param name="steps"></param>
        public void MoveGamePiece(GamePiece gamePiece, int steps)
        {
            if (!gamePiece.IsAtGoal)
            {
                if (gamePiece.IsAtBase && steps >= 6)
                {
                    BoardSquare startSquare = GameBoard.GetStartingSquare(gamePiece.Player);
                    gamePiece.BoardSquareNumber = startSquare.BoardSquareNumber;
                    GameBoard.PlaceGamePiece(gamePiece, startSquare);
                    gamePiece.IsAtBase = false;
                }
                else
                {
                    GameBoard.GetCurrentSquare(gamePiece).GamePieces.Remove(gamePiece);

                    for (int i = 0; i < steps; i++)
                    {
                        gamePiece.BoardSquareNumber = GameBoard.FindNextValidSquare(gamePiece).BoardSquareNumber;

                        if (GameBoard.Board[gamePiece.BoardSquareNumber.Value].IsEndSquare)
                        {
                            gamePiece.IsAtGoal = true;
                        }
                    }

                    if (!gamePiece.IsAtGoal)
                    {
                        BoardSquare currentSquare = GameBoard.GetCurrentSquare(gamePiece);
                        GameBoard.PlaceGamePiece(gamePiece, currentSquare);
                    }
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// Places gamePiece in squares' list of game pieces.
 /// </summary>
 /// <param name="gamePiece"></param>
 public void AddGamePiecesToBoard(GamePiece gamePiece)
 {
     if (Board.Where(bs => bs.BoardSquareNumber == gamePiece.BoardSquareNumber).Any())
     {
         BoardSquare boardSquare = Board.Where(bs => bs.BoardSquareNumber == gamePiece.BoardSquareNumber.Value).FirstOrDefault();
         boardSquare.GamePieces.Add(gamePiece);
     }
 }
コード例 #3
0
        public void PlaceGamePiece(GamePiece gamePiece, BoardSquare boardSquare)
        {
            BoardSquare currentSquare = this.Board.Where(bs => bs == boardSquare).FirstOrDefault();

            currentSquare.PlaceGamePiece(gamePiece);
        }