public string atacar(Inimigo alvo) { if (alvo.vidaAtual <= 0) { return(alvo.nome + " já está morto."); } string mensagem = ""; Random r = new Random(); int danoCausado = r.Next(armaPrincipal.getDanoMin(), armaPrincipal.getDanoMax() + 1); alvo.vidaAtual -= danoCausado; mensagem = alvo.nome + " recebeu " + danoCausado + " de dano da arma " + armaPrincipal.ToString() + ".\n"; if (alvo.vidaAtual <= 0) { mensagem += alvo.nome + " morreu.\n"; mensagem += setExperiencia(alvo.getExpAoMatar()); } else { mensagem += "Ficando com " + alvo.vidaAtual + " de vida restante."; } return(mensagem); }
static void Main(string[] args) { while (true) { string nome = Pergunta.RetornoTexto("Qual o seu nome?"); string raca = Pergunta.RetornoTexto("Qual a sua raça?"); Heroi h = new Heroi(30, nome, raca); Random r = new Random(); int i = r.Next(0, TodosOsObjetos.inimigo.Count()); Inimigo s = TodosOsObjetos.inimigo[i]; while (true) { Console.Clear(); int escolha = -1; Console.WriteLine("Você encontrou um inimigo!\n"); do { s.getInfo(); h.getInfo(); Console.WriteLine(Menu.Luta()); try { escolha = Pergunta.RetornoInt("Indique o número para executar a ação."); } catch { } Console.Clear(); switch (escolha) { case 0: Console.WriteLine(h.atacar(s)); break; case 1: break; } Console.WriteLine(); } while (lutando); Console.ReadLine(); } } }