Mam problem z powtarzalnością losowanych liczb przez Random. Pisze sobie taką jakby walkę robotów żeby mniej więcej sie uczyć na konkretnym projekcie, utrwalać nowo poznane rzeczy, caly czas rozbudowywać, itd. i napotkałem problem, a mianowicie caly czas dostaję te same wartości attack i deffence (zawsze ich różnica wychodzi 5). Nie mam pojęcia jak temu zaradzić ;/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace MyApp
{
class KlasaGlowna
{
static void Main(string[] args)
{
Robot r1 = new Robot();
Robot r2 = new Robot();
do
{
r1.versus(r1.attack(), r2.deffence());
Console.WriteLine();
Thread.Sleep(1500);
r2.versus(r2.attack(), r1.deffence());
Thread.Sleep(1500);
} while (r1.HP > 0 || r2.HP > 0);
if (r1.HP == 0)
Console.WriteLine("Zwycięża robot 2");
else
Console.WriteLine("Zwycięża robot 1");
Console.ReadKey();
}
}
public class Robot
{
public int HP = 100;
int dmg = 0;
Random random = new Random();
public int attack()
{
int attack = random.Next(5, 10);
return attack;
}
public int deffence()
{
int deffence = random.Next(0, 5);
return deffence;
}
public void versus(int atc, int def)
{
dmg = atc-def;
Console.WriteLine("Atakujesz z siłą o wartości {0}, obrona przeciwnika wynosi {1}.\nZadane obrażenia {2}!!!", atc, def, dmg);
HP -= dmg;
}
}
}
Mile widziane także wszelkiego rodzaju inne wykryte błędy, niedociągnięcia, itp.