コード例 #1
0
        private void finishGame()
        {
            int playerOneScore = 0, playerTwoScore = 0;

            m_GameManager.CalculatePointAndGameStatus(ref playerOneScore, ref playerTwoScore);

            switch (m_GameManager.m_GameStatus)
            {
            case eGameStatus.Draw:
                UserInterface.PrintDraw();
                break;

            case eGameStatus.PlayerOneWin:
                UserInterface.PrintWinner(m_NameOfPlayer1, m_GameManager.GetNameOfPlayer(eUserTurn.User2), playerOneScore, playerTwoScore);
                break;

            case eGameStatus.PlayerTwoWin:
                UserInterface.PrintWinner(m_GameManager.GetNameOfPlayer(eUserTurn.User2), m_NameOfPlayer1, playerTwoScore, playerOneScore);
                break;
            }

            if (isContinueGame()) //check if user want to continue
            {
                m_GameManager.m_Board.InitBoard();
                m_GameManager.m_GameStatus      = eGameStatus.OnPlay;
                m_GameManager.m_CurrentUserTurn = eUserTurn.User1;
                Screen.Clear();
                BoardView.PrintBoard(m_GameManager.m_Board.GetBoard());
                startGame();
            }
        }
コード例 #2
0
        private void play()
        {
            bool isFirstTry = true;

            if (!m_IsFirstTurn)
            {
                PrintParametersOfPrevTurn(m_GameManager.GetNameOfPlayer(m_PrevUser), m_GameManager.GetSignOfUser(m_PrevUser));
            }

            bool isQuit, IsDesiredMoveValid;
            bool isMoreEats = false;

            IsDesiredMoveValid = false;

            Position sourcePosition, targetPosition;

            do
            {
                if (!isFirstTry)
                {
                    printErrorMessageInvalidMove();
                }
                //check if computer playing
                if (m_GameManager.m_CurrentUserTurn == eUserTurn.User2 && m_GameManager.m_IsComputerPlaying == true)
                {
                    m_GameManager.GetCurrentTurnFromComputer(out sourcePosition, out targetPosition, out isQuit);
                }
                else
                {
                    getParametersOfCurrentTurn(out sourcePosition, out targetPosition, out isQuit);
                }

                if (isQuit == true)
                {
                    m_GameManager.m_GameStatus = eGameStatus.Quit;
                    break;
                }

                if (m_GameManager.CheckMove(sourcePosition, targetPosition))
                {
                    IsDesiredMoveValid = true;
                    m_GameManager.Move(sourcePosition, targetPosition, out isMoreEats);
                }
                m_IsFirstTurn = false;
                isFirstTry    = false;
            }while (!IsDesiredMoveValid);

            if (m_GameManager.m_GameStatus != eGameStatus.Quit)
            {
                storePrevTurn(sourcePosition, targetPosition, m_GameManager.m_CurrentUserTurn, m_GameManager.GetSignOfUser(m_GameManager.m_CurrentUserTurn));
                m_GameManager.HandleStatusGame();
                Screen.Clear();
                BoardView.PrintBoard(m_GameManager.m_Board.GetBoard());
                if (!isMoreEats)
                {
                    m_GameManager.NextTurn();
                }
            }
        }
コード例 #3
0
 public UserInterface()
 {
     getDetailsOfPlay();
     m_GameManager = new GameManager(m_NameOfPlayer1, m_NameOfPlayer2, m_SizeOfBoard);
     Screen.Clear();
     BoardView.PrintBoard(m_GameManager.m_Board.GetBoard());
     startGame();
 }