私はサッカーのシミュレーションプログラムを作成しようとしています。私は "チーム"と呼ばれるメインクラスと "ゴールキーパー"、 "ディフェンダー"、 "フォワード"と "ミッドフィールダー"という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