private void Start() { // reset game states m_rounds = 1; m_player = new Player(); m_enemy = new Enemy(); ConsoleEx.AddSeparator(); string str = "Escolha uma dificuldade.\n" + "A dificuldade afeta o tempo de resposta e as operações."; Console.WriteLine(str); ConsoleEx.WriteLine("1. Fácil\n2. Normal\n3. Difícil", ConsoleColor.Yellow); ConsoleEx.ParseUint(ref m_difficulty, 1, 3, "Dificuldade inválida, escolha entre 1 (fácil), 2 (médio) ou 3 (difícil)."); // set the answer interval by difficulty if (m_difficulty == (uint)Difficulty.Easy) { aTimer.Interval = 10000; } else if (m_difficulty == (uint)Difficulty.Normal) { aTimer.Interval = 7000; } else { aTimer.Interval = 5000; } Console.WriteLine("Você terá {0} segundos para resolver cada operação.", aTimer.Interval / 1000); Thread.Sleep(1000); Poll(); }
private void Poll() { // player turn, get body target ConsoleEx.AddSeparator(); Console.WriteLine("Rodada {0}\nSeu HP: {1}\nHP do Matemágico: {2}", m_rounds, m_player.GetHealth(), m_enemy.GetHealth()); ConsoleEx.WriteLine("Escolha onde deseja atacar:\n" + "1. Torso\n2. Pernas\n3. Cabeça", ConsoleColor.Yellow); uint bodyTarget = 0; ConsoleEx.ParseUint(ref bodyTarget, 1, 3, "Local inválido, escolha entre 1 (torso), 2 (perna) ou 3 (cabeça)."); if (m_rounds == 0) { Console.WriteLine("Faça o cálculo necessário para acertar a flecha!"); Thread.Sleep(1000); } // reset timer aTimer.Stop(); aTimer.Enabled = true; // gen math operation (string operation, int result) = GenOperation(bodyTarget); ConsoleEx.WriteLine(operation, ConsoleColor.Yellow); uint answer = 0; while (aTimer.Enabled && (!uint.TryParse(Console.ReadLine(), out answer))) { if (aTimer.Enabled) { Console.WriteLine("Número inválido, tente novamente."); } } // show results if (!aTimer.Enabled) { ConsoleEx.WriteLine("Você perdeu o turno.", ConsoleColor.Red); } else if (answer == result) { ConsoleEx.WriteLine("Você acertou a flecha!", ConsoleColor.Green); Random rand = new Random(); int damage; if (bodyTarget == (uint)BodyTarget.Torso) { damage = rand.Next(3, 6); } else if (bodyTarget == (uint)BodyTarget.Legs) { damage = rand.Next(4, 7); } else { damage = rand.Next(7, 11); } m_enemy.Hit(damage); } else { ConsoleEx.WriteLine(String.Format("Você errou a flecha. A resposta certa era {0}!", result), ConsoleColor.Red); } aTimer.Stop(); Thread.Sleep(1000); // victory? if (m_enemy.IsDead()) { End(true); return; } m_player.Hit(m_enemy.GetDamage()); Thread.Sleep(1000); // defeat? if (m_player.IsDead()) { End(false); return; } // continue m_rounds++; Poll(); }