Pokemon battling again for practice. Tried to make it a little harder this time with attack and defense. Health - (attack - defense).
I get the feeling my order of operations is getting messed up somehow, because no matter, how I re-code it, somebody is always gaining life.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication9
{
class Pokemon
{
public string Name;
public int Health;
public int Attack;
public int Defense;
}
class Program
{
static List<Pokemon> shaunPokemon = new List<Pokemon>() {
new Pokemon {
Name = "Mega Bidoof",
Health = 700,
Attack = 600,
Defense = 500
},
new Pokemon {
Name = "Bidoof",
Health = 350,
Attack = 150,
Defense = 50,
},
new Pokemon {
Name = "Bidoof",
Health = 350,
Attack = 150,
Defense = 50,
}
};
static List<Pokemon> myPokemon = new List<Pokemon>() {
new Pokemon {
Name = "Scizor",
Health = 400,
Attack = 180,
Defense = 100
},
new Pokemon {
Name = "Houndoom",
Health = 380,
Attack = 220,
Defense = 50
},
new Pokemon {
Name = "Tyranitar",
Health = 350,
Attack = 100,
Defense = 80
}
};
static void Main(string[] args)
{
//Random Generator
var rnd = new Random();
var randomChoice = shaunPokemon[rnd.Next(shaunPokemon.Count)];
Console.WriteLine("Writer Shaun challenges you to a battle!");
Console.WriteLine("I choose you, " + randomChoice.Name + "! \n");
Console.WriteLine("Please choose your Pokemon.");
for (int i = 0; i < myPokemon.Count; i++)
{
Console.WriteLine("Press " + (i + 1) + " for " + myPokemon[i].Name + ".");
}
var myInput = Console.ReadLine();
int index = int.Parse(myInput) - 1;
Console.WriteLine();
Pokemon selected = myPokemon[index];
Console.WriteLine("I choose you, " + selected.Name + "! \n");
Console.WriteLine("Press Enter to attack.");
string acceptInput = Console.ReadLine();
while (selected.Health > 0 && randomChoice.Health > 0)
{
selected.Health -= (randomChoice.Attack - selected.Defense);
randomChoice.Health -= (selected.Attack - randomChoice.Defense);
Console.WriteLine(selected.Name + "'s health = " + selected.Health);
Console.WriteLine(randomChoice.Name + "'s health = " + randomChoice.Health);
Console.WriteLine();
Console.WriteLine("Press Enter to Attack again.");
Console.ReadLine();
};
}
}
}
As you can see, I even raised the attacks, to make sure that (Attack-Defense) should always be positive.
Am I missing something that simple?