This question already has an answer here:
im trying to learn c# and slowly trying to create my own code but i have a bit of a problem with the random number generator it keeps giving me the same number all the time instead of different ones. warning the code i wrote is pretty newbie so yeah... still learning. much help would be appreciated
Random random = new Random();
lvl = random.Next(1, 11);
switch (lvl)
{
case 1:
case 2:
case 3:
case 4:
case 5:
hitpoints = random.Next(10, 50);
xp = random.Next(1, 5);
damage3 = random.Next(1, 5);
break;
case 6:
case 7:
case 8:
case 9:
case 10:
hitpoints = random.Next(50, 110);
xp = random.Next(5, 11);
damage3 = random.Next(5, 11);
break;
default:
break;
}
if (hitpoints == 0)
{
character tom = new character();
Console.WriteLine("You have defeated the monster");
tom.xp = +xp;
return;
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire