Hi all,
I am new to C#, so please bear with me.
What I need to do, is to create a method in one class, that can be used to update the scores of an object in another class.
The entire thing is a small program, that creates a VERY small figthing game..
SO - A random "warrior" is created in the game, and IF it is LukeS (Yep, Luke Skywalker..) I need to use the method from my other class to help him, and set his score back to "Healthy". If its not LukeS, nothing happens.
Here the random warrior name is created:
JediKnight warrior = myJedis[randomInt];
switch (warrior.Name)
{
case "Darth Vader":
if (!warrior.Deceased)
{
warrior.AttackEnemy(warrior, LukeS);
if (myWarrior.DarkSide == false) { warrior.AttackEnemy(warrior, myWarrior); }
}
else // this happens if the Emperor points a bony finger at a dead Jedi Knight
{
warrior.Deceased = false;
warrior.currentDamageLevel = JediKnight.DamageLevel.Hurting;
}
break;
case "Luke Skywalker":
if (!warrior.Deceased)
{
// THIS IS WHERE I TRY TO HELP LUKE, AND GIVE HIM A HIGHER DAMAGELEVEL, IF ITS CURRENT < HURTING (25)
if (warrior.currentDamageLevel < JediKnight.DamageLevel.Hurting)
{
// USE THE OBIWANK.SAVELUKE METHOD - EXPLAINED JUST BELOW...
ObiwanK.SaveLuke(warrior);
}
warrior.AttackEnemy(warrior, DarthV);
if (myWarrior.DarkSide == true) { warrior.AttackEnemy(warrior, myWarrior); }
}
break;
}
In the case: Luke Skywalker, I am using this to give him a better score, if his score has dropped to below "hurting", which is a constant set earlier.
// HELPER METHOD FOR LUKES
if (warrior.currentDamageLevel < JediKnight.DamageLevel.Hurting)
{
// HELP LUKE SKYWALKER AND GIVE HIM A BETTER DAMAGELEVEL:
ObiwanK.SaveLuke(warrior);
}
But nothing happens at all, to the score. I have set ObiWanK earlier up in the program and left it out here. But it should be good..
The other class that has the helper method is like this:
public void SaveLuke(JediKnight Warrior)
{
// HELP LUKES AND GIVE HIM A HIGHER CURRENTDAMAGELEVEL HERE:
this.currentDamageLevel = JediKnight.DamageLevel.Healthy;
}
So trying to set his damagelevel to healthy doesnt Work like this, and I have not too much experience in C#, so I have been stuck here for the last two days.
JediKnight is a class, with broader enums defining warrior name and other things. By using it as a parameter, is that not the right way to Refer to it, so that I can target the currentDamageLevel defined in the class, for the specific object LukeS?
Basically, I need to use the object ObiWanK to update the currentDamageLevel of the object warrior, if the warrior name is LukeS..
I hope it makes sense, and will appreciate all help a lot, as I have to deliver tomorrow and my lack of experience is stopping me from getting much further at the moment :-/
Best Regards, Klemme