あいさつ、私はプログラミングに不慣れで、現時点ではゲーム戦艦のクローンを開発しています。5隻の艦隊を実装する必要があります。これは私がこれまでに行ったことです:
クラスCellは、テーブルセルのステータスを保持します。
public class Cell
{
// class for holding cell status information
public enum cellState
{
WATER,
SCAN,
SHIPUNIT,
SHOT,
HIT
}
public Cell()
{
currentCell = cellState.WATER;
}
public Cell(cellState CellState)
{
currentCell = CellState;
}
public cellState currentCell { get; set; }
}
クラスGridUnitはテーブルセル情報を保持します:
public class GridUnit
{
public GridUnit()
{
Column = 0;
Row = 0;
}
public GridUnit(int column, int row)
{
Column = column;
Row = row;
}
public int Column { get; set; }
public int Row { get; set; }
}
最後に、クラスShipunitには上記のクラスの両方が含まれ、個々のセルの状態情報のラッパーとして機能します。
public class ShipUnit
{
public GridUnit gridUnit = new GridUnit();
public Cell cell = new Cell(Cell.cellState.SHIPUNIT);
}
現時点では、次のようなジャグ配列にフリート情報を実装することを考えています。
ShipUnit[][] Fleet = new ShipUnit[][]
{
new ShipUnit[] {ShipUnit,ShipUnit,ShipUnit,ShipUnit,ShipUnit},
new ShipUnit[] {ShipUnit,ShipUnit,ShipUnit,ShipUnit},
new ShipUnit[] {ShipUnit,ShipUnit,ShipUnit}
new ShipUnit[] {ShipUnit,ShipUnit,ShipUnit}
new ShipUnit[] {ShipUnit,ShipUnit}
};
コードの最後のビットが機能しないことに気づきました。アイデアを提示するためだけのものです。
しかし、問題は、ジャグ配列の各行が表す船のタイプを示すフィールドが必要であり、すべてのセル情報にこの情報を記載することは実用的ではないと思います。
だから私はあなたからこの問題の実装のいくつかのアイデアをお願いします。
ありがとうございました。