I am trying to develop my understanding of OOP so I created a console adventure game. I have a battle class which basically has 3 methods:
public static void StartFight(Dragon dragonWarrior, Goblin goblinEnemy)
public static string YouAttack(Dragon dragonWarrior, Goblin goblinEnemy)
public static string EnemyAttack(Goblin goblinEnemy, Dragon dragonWarrior)
The first calls the other 2 until someone dies. YouAttack and EnemyAttack include messages like:
Console.WriteLine("{0} the dragon attacks {1} and has dealt {2} damage",
dragonWarrior.Name, goblinEnemy.Name, damageDone);
In all, lets says that my 3 methods collectively takes 90 lines of code.
My problem is this. Lets say, I have an orc. I can easily copy and paste the methods and overload them like this:
public static void StartFight(Orc orcWarrior, Goblin goblinEnemy)
But that's going to generate a lot of bloat. Especially as the number of object Warriors increase (Centaur, Demon, Dwarf etc etc)
So is there a way of passing an object and the compiler figuring out what object has been passed? If there is, does anyone know of a good tutorial? Is there another solution that I can research??
I am aware that this might be a rubbish question but I am entirely self taught. I don't have any friends or tutors that code so every problem can be a struggle. Thank you in advance