public ShipInstance(Position pos, Rotation r, Ship ship) { this.pos = pos; this.rotation = r; this.ship = ship; this.sunken = false; }
public ShotType FireAtShip(Position pos) { ShipInstance hit = HitsShip(pos); if (hit != null) { shots[pos.x + (pos.y * boardSize)] = ShotType.HIT; } else { shots[pos.x + (pos.y * boardSize)] = ShotType.MISS; } return shots[pos.x + (pos.y * boardSize)]; }
public List<Position> GetPath() { List<Position> path = new List<Position>(); Position shippos = pos; Position rotpos = new Position(rotation); for (int i = 0; i < ship.length; i++) { path.Add(shippos); shippos += rotpos; } return path; }
public ShipInstance HitsShip(Position pos) { foreach(ShipInstance shipinst in ships) { List<Position> shipPath = shipinst.GetPath (); if (shipPath.Contains (pos)) return shipinst; } return null; }
public ShotType Fire(int playerId, Position pos) { gb.SendMessage(new ChatMessage("SYSTEM", "TURN:"+(1-playerId))); ShotType stype = gb.games[1 - playerId].FireAtShip(pos); return stype; }