我是新人。
我的问题:
class Battle
{
public void Fight(string charOne, string charTwo)
{
void CurrentHealth()
{
Console.WriteLine(charOne.name + "'s Health: " +
charOne.currentHealth + "/" + charOne.maxHealth +
" | " + charTwo.name + "'s Health: " + charTwo.currentHealth +
"/" + charTwo.maxHealth);
}
}
}
" .name"和" .currentHealth"不工作。 charOne将是一个类实例,而charTwo将是另一个类实例。
[更新如下]
下面是最初在主程序类中工作的代码,我试图将它移到一个类中,我可以将一些参数传递给类,因此Hero可以在未来与其他怪物对抗。这个单身怪物是"蚊子"。 我只是想能够更换一只蚊子"与狼一起#34;上课,也许" hero2"而不是"英雄"。希望这更有意义。
void CurrentHealth()
{
Console.WriteLine(hero.name + "'s Health: " + hero.currentHealth + "/" + hero.maxHealth + " | " + mosquito.name + "'s Health: " + mosquito.currentHealth + "/" + mosquito.maxHealth);
}
void Attack(int dmg)
{
Console.WriteLine(hero.name + " Dealt " + dmg + " damage to " + mosquito.name + ".");
}
while (mosquito.currentHealth > 0 && hero.currentHealth > 0)
{
Console.Clear();
int damage = hero.AttackAction();
mosquito.currentHealth = mosquito.currentHealth - damage;
int newHealth = mosquito.currentHealth;
Attack(damage);
CurrentHealth();
Console.WriteLine();
Console.WriteLine("Press any key to continue.");
Console.Read();
}
if (mosquito.currentHealth <= 0)
{
Console.WriteLine("Right on! You are Victorious!!!");
}
else if (hero.currentHealth <= 0)
{
Console.WriteLine("Oh no.. you are dead...");
}
else
{
Console.WriteLine("You reached the end.");
}
答案 0 :(得分:0)
public void Fight(MyCharacterClass charOne, MyCharacterClass charTwo)
尝试这样,当然用 MyCharacterClass
更改自己的课程