Пример #1
0
        /// <summary>
        /// Executes a ChessCommand.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="command">The ChessCommand.</param>
        public void ExecuteCommand(AuthenticatedClient client, ChessCommand command)
        {
            bool executionAllowed = false;

            if (this.PlayerTurn)
            {
                if (this.HostClient == client)
                {
                    executionAllowed = true;
                }
            }
            else
            {
                if (this.GuestClient == client)
                {
                    executionAllowed = true;
                }
            }

            if (executionAllowed)
            {
                // Do stuff
                this.Model.ExecuteCommand(command);
            }

            this.NotifyClients();
        }
Пример #2
0
        public void ExecuteCommand(ChessCommand command)
        {
            int posX = command.PositionXY[0];
            int posY = command.PositionXY[1];

            ChessSquare[,] chessSquares = this.GetSquares();

            AbstractChessPiece chessPiece = chessSquares[posX, posY].ChessPiece;

            if (chessPiece != null)
            {
                if (this.CurrentPiece != null && this.CurrentPiece.IsWhite != chessPiece.IsWhite)
                {
                    this.PlaceCurrentPiece(posX, posY);
                }
                else
                {
                    this.TakePiece(chessPiece);
                }

                //TestIfCheck();
            }
            else
            {
                this.PlaceCurrentPiece(posX, posY);
                //TestIfCheck();
            }
        }
Пример #3
0
 /// <summary>
 /// Called when a ChessCommand is received.
 /// </summary>
 /// <param name="packetHeader">The packet header.</param>
 /// <param name="connection">The connection.</param>
 /// <param name="command"></param>
 private void HandleChessCommandSent(PacketHeader packetHeader, Connection connection, ChessCommand command)
 {
     if (this.IsClientAuthenticated(connection))
     {
         AuthenticatedClient client = this.AuthenticatedClients.GetAuthenticatedClientFromConnection(connection);
         this.ChessGameRoomList.ExecuteCommandInRoom(client, command);
     }
 }
Пример #4
0
        /// <summary>
        /// Executes a command in the given room.
        /// </summary>
        /// <param name="roomID">The room's ID.</param>
        public void ExecuteCommandInRoom(AuthenticatedClient client, ChessCommand command)
        {
            ChessGameRoom gameRoom = this.GetRoomFromID(command.RoomID);

            gameRoom.ExecuteCommand(client, command);
        }