예제 #1
0
        private CheckersMove IsMoveValidCore(CheckersPiece piece, Point[] path)
        {
            // Failsafe .. be sure piece is valid
            if (piece == null)
            {
                throw new ArgumentNullException("piece");
            }
            if (!pieces.Contains(piece))
            {
                throw new ArgumentException("Argument 'piece' must be a piece in play to the current game.");
            }
            // Be sure piece can be moved
            if (!CanMovePiece(piece))
            {
                throw new ArgumentException("Checkers piece cannot be moved on this turn.", "piece");
            }
            CheckersMove move = CheckersMove.FromPath(this, piece, path);

            if (!move.Moved)
            {
                return(null);         // No movement
            }
            if (move.MustMove)
            {
                return(null);       // A move must yet be made
            }
            // Success
            return(move);
        }
예제 #2
0
        /// <summary>Creates a duplicate Checkers game object.</summary>
        /// <returns>The new Checkers move object.</returns>
        public CheckersGame Clone()
        {
            CheckersGame game = new CheckersGame(optionalJumping);

            game.isReadOnly = isReadOnly;
            game.isPlaying  = isPlaying;
            game.firstMove  = firstMove;
            game.turn       = turn;
            game.winner     = winner;
            game.pieces     = new CheckersPieceCollection();
            game.board      = new CheckersPiece[BoardSize.Width, BoardSize.Height];
            foreach (CheckersPiece piece in pieces)
            {
                CheckersPiece newPiece = new CheckersPiece(game, piece.Player, piece.Rank, piece.Location, piece.InPlay);
                game.board[newPiece.Location.X, newPiece.Location.Y] = newPiece;
                game.pieces.Add(newPiece);
            }
            int lastMovePieceIndex = ((lastMove != null) ? (pieces.IndexOf(lastMove.Piece)) : (-1));

            game.lastMove = ((lastMovePieceIndex != -1) ? (CheckersMove.FromPath(game, game.pieces[lastMovePieceIndex], lastMove.Path)) : (null));
            return(game);
        }