Adding assignments

This commit is contained in:
2025-08-18 10:24:52 +02:00
commit 7b723f25f6
21 changed files with 734 additions and 0 deletions

13
RPG/Character.cs Normal file
View File

@@ -0,0 +1,13 @@
namespace OOP.RPG
{
public class Character
{
public string Name { get; set; }
public int Health { get; set; } = 100;
public virtual int Attack()
{
return 10;
}
}
}

17
RPG/Mage.cs Normal file
View File

@@ -0,0 +1,17 @@
namespace OOP.RPG
{
public class Mage : Character
{
public Mage(int Mana)
{
this.Mana = Mana;
}
public int Mana = 10;
public override int Attack()
{
return Mana / 2;
}
}
}

42
RPG/Simulation.cs Normal file
View File

@@ -0,0 +1,42 @@
namespace OOP.RPG
{
public class Simulation
{
public Simulation(Character opponent1, Character opponent2)
{
this.opponent1 = opponent1;
this.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");
}
}
}
}

19
RPG/Warrior.cs Normal file
View File

@@ -0,0 +1,19 @@
namespace OOP.RPG
{
public class Warrior : Character
{
public Warrior(int strength)
{
this.strength = strength;
}
public int strength = 10;
public int multiplier = 2;
public override int Attack()
{
return base.Attack() * multiplier;
}
}
}