Exemple #1
0
        private void ButtonCellMakeAMoveClick_Click(object sender, EventArgs e)
        {
            Logic.Move move;
            string     endOfGameMessege = string.Empty;

            if (m_ChosenButton != null)
            {
                move = new B18_Ex05_Logic.Move(m_ChosenButton.CellLocation, (sender as ButtonCell).CellLocation);
                if (m_LogicGame.MakeAPlayerMove(ref move))
                {
                    updateBoard(sender as ButtonCell, move);
                    m_ChosenButton.IsClicked = false;
                    m_ChosenButton           = null;
                    if (m_LogicGame.IsGameOver(ref endOfGameMessege))
                    {
                        gameIsOver(endOfGameMessege);
                    }
                    else
                    {
                        playNextMove();
                    }
                }
                else
                {
                    MessageBox.Show("Move is not valid");
                }
            }
        }
Exemple #2
0
        private bool handleUserMove()
        {
            bool moveIsValid = true;

            m_latstmove = Console.ReadLine();
            checkAndHandleIfCharactersAreValid(ref m_latstmove);
            if (m_latstmove != "Q")
            {
                Location cellFrom = new Location(m_latstmove[1] - m_a, m_latstmove[0] - m_A);
                Location cellTo   = new Location(m_latstmove[4] - m_a, m_latstmove[3] - m_A);
                Move     move     = new Move(cellFrom, cellTo);
                m_latstmove = getLastMoveString(m_game.Player[(int)m_game.PlayerTurn].Name, (char)m_game.Player[(int)m_game.PlayerTurn].PlayerSign, m_latstmove);
                moveIsValid = m_game.MakeAPlayerMove(ref move);
            }
            else
            {
                if (m_game.TryToQuit())
                {
                    m_latstmove = null;
                    gameIsOver("User Quit");
                }
                else
                {
                    moveIsValid = false;
                }
            }

            if (!moveIsValid)
            {
                Console.WriteLine("Move Is not Valid Please Try Again:");
            }

            return(moveIsValid);
        }