コード例 #1
0
        /// <summary>
        /// Permet la surbrillance d'une tuile.
        /// </summary>
        /// <param name="coordFrom">D'ou provient le mouvement.</param>
        public void tryMove(int[] coordFrom)
        {
            //if (m_board[p_x,p_y].CurrentPiece != null)
            bool isMove = m_board.isMoving(coordFrom, m_turn);

            //If the player is trying to select a piece
            if (!isMove)
            {
                bool isValidTile = m_board.trySelectTile(coordFrom, m_turn);
                if (isValidTile)
                {
                    m_board.markPossible(coordFrom, coordFrom);
                    if (this.m_turn == 'W')
                    {
                        this.m_move = new Move(m_board.SelectedTile);
                    }
                    else
                    {
                        this.m_move = new Move(m_board.SelectedTile);
                    }
                }
            }
            //If the player is trying to move
            else
            {
                m_move.End = m_board[coordFrom[0], coordFrom[1]];
                bool destValid = this.m_board.isDestinationValid(m_move.Start, m_move.End, this.m_turn);
                if (destValid)
                {
                    bool validMovement = this.m_move.isValidMovement();
                    if (validMovement)
                    {
                        bool isCollisionning = this.m_board.isCollisionning(m_move.getCoordFrom(), m_move.getCoordTo());
                        if (!isCollisionning)
                        {
                            //If the board is in a check state
                            if (!askBoardCheck())
                            {
                                move(m_move.getCoordFrom(), m_move.getCoordTo());
                                switchTurns();
                                if (m_board.detectCheck(m_turn))
                                {
                                    m_gameGUI.writeEvent(getCurrentPlayerName() + ": Déplacement invalide vers X(" + (m_move.getCoordTo()[0] + 1) + "), Y(" + (m_move.getCoordTo()[1] + 1) + "), car vous êtes en échec!");
                                }
                            }
                            else
                            {
                                if (askBoardCheckPat())
                                {
                                    Console.WriteLine(m_turn + "checkPat Detected !");
                                }
                            }


                            this.m_board.isCheckState = m_board.detectCheck(this.m_turn);


                            if (askBoardCheckMat())
                            {
                                switchTurns();
                                m_gameGUI.writeEvent(getCurrentPlayerName() + ": a gagné!");
                                m_gameGUI.Refresh();
                                refreshBoard();

                                if (Turn)
                                {
                                    endGame(m_pWhite, m_pBlack);
                                }
                                else
                                {
                                    endGame(m_pBlack, m_pWhite);
                                }

                                Thread.Sleep(3000);
                                m_gameGUI.Close();
                            }
                            refreshBoard();
                        }
                    }
                }
            }
            refreshBoard();
        }