И я получаю эту ошибку:Истребитель класс не реализует интерфейс члена
Error 1 'Fight.Fighter' does not implement interface member 'Fight.IFighter.Utok(Fight.IFighter)'
Это первый раз, когда я пытаюсь научиться работать с интерфейсами, так что извините за самосвала вопрос.
Любые идеи?
У меня есть следующий код:
Интерфейс:
interface IFighter
{
string GraphicLife();
bool IsLive();
int Obrana(int utocneCislo);
void Utok(IFighter bojovnik);
}
}
Класс:
class Fighter : IFighter
{
protected string name;
protected int life;
protected int maxLife;
protected int attack;
protected int defence;
protected Kostka kostka;
public Fighter(string name, int life, int maxLife, int attack, int defence, Kostka kostka){
this.name = name;
this.life = life;
this.maxLife = maxLife;
this.attack = attack;
this.defence = defence;
this.kostka = kostka;
}
public bool IsLive()
{
if (life > 0)
{
return true;
}
else return false;
}
public string GraphicLife()
{
int pozic = 20;
int numberOfParts = (int)Math.Round(((double)life/(double)maxLife) * (double)pozic);
string zivot = String.Concat(Enumerable.Repeat("#", numberOfParts));
zivot = zivot + String.Concat(Enumerable.Repeat("_", pozic - numberOfParts));
zivot = "[" + zivot + "]";
return zivot;
}
public void Utok(Fighter warrior)
{
if (warrior.IsLive())
{
int utok = (int)Math.Round((double)attack/(double)kostka.getPocetStran() * (double)kostka.getNumber());
int obrana = warrior.Obrana(utok);
Console.WriteLine(this.name + "utoci na " + warrior.name + " silou " + utok + " " + warrior.name + " se brani silou " + obrana);
Console.WriteLine(this.name + " - " + this.life);
Console.WriteLine(this.GraphicLife());
Console.WriteLine(warrior.name + " - " + warrior.life);
Console.WriteLine(warrior.GraphicLife());
}
else Console.WriteLine(this.name + " utoci na mrtvolu");
}
public int Obrana(int attackNumber)
{
int localDefence = (int)Math.Round((double)defence/ (double)kostka.getPocetStran() * (double)kostka.getNumber());
int utok = attackNumber - localDefence;
if (utok < 0) utok = 0;
life = life - utok;
return localDefence;
}
}}
Щелкните правой кнопкой мыши по интерфейсу в определении класса и выберите интерфейс реализации – Sayse
Обратите внимание на сообщение об ошибке. Это говорит вам метод, вызывающий проблему (Utok), и тип параметра, который он ожидает от него (IFighter). –