我正在尝试创建一个足球模拟程序。我有一个名为“团队”的主类和4个名为“守门员”,“后卫”,“前锋”和“中场球员”的派生类。从派生类到基类
我根据他们的位置创建球员。 例如:
team fb = new team("fb");
forward alex = new forward(fb.tName, "alex", 73, 77, 77, 69, 70);
我的队伍等级:
public class team
{
public string tName;
public team(string tName)
{
this.tName = tName;
}
public string teamInfo()
{
return tName;
}
}
正向类:
class forward:team
{
//özellikler
public string pName;
public string pPosName;
public int finishing;
public int longShots;
public int composure;
public int offTheBall;
public int firstTouch;
public forward(string tName, string pName, int finishing, int longShots, int composure, int offTheBall, int firstTouch)
: base(tName)
{
this.pName = pName;
this.pPosName = "Forward";
this.finishing = finishing;
this.longShots = longShots;
this.composure = composure;
this.offTheBall = offTheBall;
this.firstTouch = firstTouch;
}
//etkiyi hesapla
public double influence
{
get
{
//calculations
return processed;
}
}
//futbolcunun genel bilgileri
public void playerInfo()
{
Console.WriteLine("\n##############################\n" + pName + "-" + tName + "-" + pPosName + "\n" + "Finishing= " + finishing + "\n" + "Long Shots= " + longShots + "\n" + "Composure= " + composure + "\n" + "Off the ball= " + offTheBall + "\n" + "Frist Touch= " + firstTouch + "\n##############################\n");
}
}
,你能看到我的根据自己的技术属性计算每个球员的影响力。
我想要的是自动化过程。例如,我创建了一支球队......增加了球员,我希望所有球员的影响力都通过球队名称进行调用。我打算给出球队名称和阵地名称,这会给我在球队所选位置上的球员的平均影响力。
我该怎么做?
在此先感谢...
注意:我的代码可能看起来很愚蠢。我是一个新手:)
你应该只使用继承模型的是,有关系(和其他一些关系)一名球员是不是球队因此它的通常不是一个好主意从一个团队派生出一个球员 –
你应该马上改变一些东西。守门员/后卫/前锋/中场球员不是**球队,而是球员。调用你的基类玩家,并在某个地方可以有一个由一组玩家对象组成的团队。 –
只是一个想法 - 你不会考虑前锋,守门员,中场和后卫是*球员类型*。然后一支球队会成为球员的一个*集合? – StuartLC