コード例 #1
0
        public void Run()
        {
            while (!m_game.IsGameOver)
            {
                m_game.BeginNewRound();
                bool validSelection = false;
                while (!validSelection)
                {
                    m_game.ShowGameState();
                    Console.WriteLine("Make your choice: 1. attack 2. Cure 3. Save 4. Load");
                    var str = Console.ReadLine();
                    if (str.Length != 1)
                    {
                        continue;
                    }
                    switch (str[0])
                    {
                    case '1':
                    {
                        validSelection = true;
                        m_game.AttackMonster();
                        break;
                    }

                    case '2':
                    {
                        validSelection = true;
                        m_game.CurePlayer();
                        break;
                    }

                    case '3':
                    {
                        validSelection           = false;
                        m_gameSaveStore.GameSave = m_game.CreateSave();
                        break;
                    }

                    case '4':
                    {
                        validSelection = false;
                        if (m_gameSaveStore.GameSave == null)
                        {
                            Console.WriteLine("no save to load");
                        }
                        else
                        {
                            m_game.RestoreFromGameSave(m_gameSaveStore.GameSave);
                        }
                        break;
                    }

                    default:
                        break;
                    }
                }
                if (!m_game.IsGameOver)
                {
                    m_game.AttackPlayer();
                }
            }
        }