问候,我是编程新手,目前正在开发游戏战舰的克隆。我需要建立一个由 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; }
}
finally 类 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}
};
我意识到最后一点代码不起作用。它只是为了提出这个想法。
但问题是我需要一个字段来说明每行锯齿状数组代表什么类型的船,我认为在每个单元格信息中说明这些信息是不切实际的。
所以我想从你那里得到一些实施这个问题的想法。
谢谢你。