public static void MouseEnter(object sender, EventArgs e) { if (ship == null) { return; } SeaBattlePicture cell = (SeaBattlePicture)sender; protoShip.Location = new Location(cell.CellLocation.I, cell.CellLocation.J); checkValidLocation = shipsOnFild.CheckLocation(protoShip, protoShip.Location); DisplayPrototypeShip(); }
public static void MouseLeave(object sender, EventArgs e) { if (ship == null) { return; } SeaBattlePicture cell = (SeaBattlePicture)sender; Location endLocation = new Location( cell.CellLocation.I + (1 - (int)protoShip.Orientation) * (protoShip.Size - 1), cell.CellLocation.J + (int)protoShip.Orientation * (protoShip.Size - 1) ); DisplayFieldPlace(cell.CellLocation, endLocation); }
void Cell_Click(object sender, MouseEventArgs e) { if (!canMove) { return; } SeaBattlePicture cell = (SeaBattlePicture)sender; cell.Enabled = false; CellCondition shotResult = Form1.RightField.Shot(cell); if (shotResult == CellCondition.Miss) { canMove = false; CallTransferMove(); } }
public Field() { MatrixShips = new bool[Size, Size]; MatrixShips.Initialize(); CellField = new SeaBattlePicture[Size, Size]; for (var i = 0; i < Size; i++) { for (var j = 0; j < Size; j++) { CellField[i, j] = new SeaBattlePicture(); CellField[i, j].CellLocation = new Location(i, j); MatrixShips[i, j] = false; } } FillingShips(); }
public CellStatus Shot(SeaBattlePicture cellShot) { if (MatrixShips[cellShot.CellLocation.I, cellShot.CellLocation.J]) { if (cellShot.ShipIntoCell.CheckDrowned(cellShot.CellLocation)) { DrownedShip(cellShot.ShipIntoCell); } else { cellShot.RenderingMode = CellStatus.Crippled; } } else { cellShot.RenderingMode = CellStatus.Miss; } MadeShot(this, new shotEventArgs(cellShot.RenderingMode)); return(cellShot.RenderingMode); }
public static void MouseClicked(object sender, MouseEventArgs e) { SeaBattlePicture cell = (SeaBattlePicture)sender; if (!BeginArround) { if (cell.ShipIntoCell == null) { return; } BeginArround = true; ship = cell.ShipIntoCell; ship.Destruction(); shipsOnFild.RecalculationCompletingCell(ship); Location endLocation = new Location( cell.CellLocation.I - (1 - (int)ship.Orientation), cell.CellLocation.J - (int)ship.Orientation); DisplayFieldPlace(ship.Location, endLocation); protoShip = new PrototypeShip(cell.CellLocation, ship.Orientation, ship.Size); checkValidLocation = shipsOnFild.CheckLocation(protoShip, protoShip.Location); DisplayPrototypeShip(); } else { BeginArround = false; Ship newShips; checkValidLocation = shipsOnFild.CheckLocation(protoShip, protoShip.Location); if (checkValidLocation) { newShips = new Ship(protoShip.Location, protoShip.Orientation, protoShip.Size, Form1.LeftField); } else { newShips = new Ship(ship); Location endedLocation = new Location( cell.CellLocation.I + (1 - (int)protoShip.Orientation) * (protoShip.Size - 1), cell.CellLocation.J + (int)protoShip.Orientation * (protoShip.Size - 1)); DisplayFieldPlace(cell.CellLocation, endedLocation); } shipsOnFild.AddShips(newShips); Location endLocation = new Location( newShips.Location.I + (1 - (int)newShips.Orientation) * (newShips.Size - 1), newShips.Location.J + (int)newShips.Orientation * (newShips.Size - 1) ); DisplayFieldPlace(newShips.Location, endLocation); ship = null; } }