コード例 #1
0
        // $G$ DSN-999 (-10) Why all methods are static? , next time create an instance of CheckersGame
        public static void Run()
        {
            Game.eMessage outputMessage = Game.eMessage.StartGame;

            getGameDetails();
            s_Game.StartNewGame();
            UI.PrintBoard(s_Game);
            while (outputMessage != Game.eMessage.EndGame)
            {
                if (outputMessage == Game.eMessage.NewGame)
                {
                    s_Game.StartNewGame();
                    printUpdatedBoard();
                }

                if (!s_Game.PlayerCanPlay(s_Game.FirstPlayerId) || outputMessage == Game.eMessage.PlayerQuit)
                {
                    outputMessage = endRound();
                }
                else
                {
                    outputMessage = play(s_Game.FirstPlayerId);
                    if (s_Game.PlayerCanPlay(s_Game.SecondPlayerId) && outputMessage != Game.eMessage.PlayerQuit)
                    {
                        outputMessage = play(s_Game.SecondPlayerId);
                    }
                    else
                    {
                        outputMessage = endRound();
                    }
                }
            }
        }
コード例 #2
0
        private static Game.eMessage play(Game.ePlayerId i_PlayerId)
        {
            bool   isTurnFinished = false;
            string input          = string.Empty;
            string playerName     = s_Game.GetPlayerNameById(i_PlayerId);

            BoardCell.eSigns playerSign    = BoardCell.GetSignFromPlayerId(i_PlayerId);
            Game.eMessage    outputMessage = Game.eMessage.StartGame;

            while (!isTurnFinished)
            {
                if (i_PlayerId == Game.ePlayerId.Computer)
                {
                    Thread.Sleep(k_SleepTime);
                    input = s_Game.GetComputerInstruction();
                }
                else
                {
                    input = UI.GetInstruction(playerName, playerSign);
                }

                outputMessage  = s_Game.PlayTurn(input, i_PlayerId);
                isTurnFinished = isPlayerTurnFinished(outputMessage);
                if (outputMessage == Game.eMessage.MustJumpOverAgain)
                {
                    printUpdatedBoard();
                    printLastInsruction(i_PlayerId, input);
                    UI.PrintMessage(outputMessage);
                }
            }

            printUpdatedBoard();
            printLastInsruction(i_PlayerId, input);

            return(outputMessage);
        }
コード例 #3
0
        private static bool isPlayerTurnFinished(Game.eMessage i_Message)
        {
            UI.PrintMessage(i_Message);

            return(i_Message == Game.eMessage.EndTurn || i_Message == Game.eMessage.PlayerQuit);
        }
コード例 #4
0
 public static void PrintMessage(Game.eMessage i_MessageId)
 {
     Console.WriteLine(s_Messages[(int)i_MessageId]);
 }