First off, stop creating new Random instance when you want them: create one at class level:
private Random rand = new Random();
Because Random starts it's generation using the system clock as a starter, if you create them repeatedly you are likely to generate the same sequence each time!
Secondly, you need to understand what happens when you pass a parameter to a method: the variable you pass is passed by value, not by reference. What that means is that a copy of the variable is taken and passes to the method, which can modify it all it likes, because it will not affect the world outside the method! (There is a more detailed explanation of what happens in this:
Using struct and class - what's that all about?[
^] but it might be a bit too much for you as a beginner).
Think about it:
void add(int a)
{
a = a + 1;
}
Is fine and dandy when you do this:
int A = 6;
add(A);
But what happens when you do this:
add(6);
You can't start changing constants! :laugh:
You could do it by passing a reference to the value - and that's very easy - but a better solution is to use the current class values, and not pass anything:
namespace ConsoleApplication1
{
class Battle
{
public int heroat, monsterat, herohealth, monsterhealth;
private Random rand = new Random();
public Battle()
{
heroat = 0;
monsterat=0;
herohealth = 100;
monsterhealth = 100;
do
{
Console.WriteLine(@"
{2} Health={0} Monster Health={1}
Hero's Attack={3} Monster's Attack={4}", herohealth, monsterhealth, Main.heroname,heroat,monsterat);
HeroAtk();
MonsAtk();
Console.ReadLine();
}
while (herohealth > 0 && monsterhealth > 0);
}
public void HeroAtk()
{
heroat = rand.Next(10, 21);
monsterhealth=monsterhealth - heroat;
}
public void MonsAtk()
{
monsterat = rand.Next(10, 20);
herohealth = herohealth - monsterat;
}
}
}
There are a couple of other changes it'd be worth doing, but they can wait until you have this working.