42 lines
1.3 KiB
C#
42 lines
1.3 KiB
C#
namespace OOP.RPG
|
|
{
|
|
public class Simulation
|
|
{
|
|
public Simulation(Character opponent1, Character opponent2)
|
|
{
|
|
Opponent1 = opponent1;
|
|
Opponent2 = opponent2;
|
|
}
|
|
|
|
public Character Opponent1 { get; set; }
|
|
public Character Opponent2 { get; set; }
|
|
|
|
public void StartSimulation()
|
|
{
|
|
while (!(Opponent1.Health <= 0) && !(Opponent2.Health <= 0))
|
|
{
|
|
// Attack opponent2
|
|
|
|
var attack1 = Opponent1.Attack();
|
|
Opponent2.Health -= attack1;
|
|
Console.WriteLine($"Opponent1 attacks Opponent2");
|
|
Console.WriteLine($"Opponent1 attacks with {attack1} and Opponent2 has {Opponent2.Health} left");
|
|
|
|
var attack2 = Opponent2.Attack();
|
|
Opponent1.Health -= attack2;
|
|
Console.WriteLine($"Opponent2 attacks Opponent2");
|
|
Console.WriteLine($"Opponent2 attacks with {attack2} and Opponent1 has {Opponent1.Health} left");
|
|
}
|
|
|
|
if (Opponent1.Health <= 0)
|
|
{
|
|
Console.WriteLine("Opponent2 wins");
|
|
}
|
|
|
|
if (Opponent2.Health <= 0)
|
|
{
|
|
Console.WriteLine("Opponent1 wins");
|
|
}
|
|
}
|
|
}
|
|
} |