public bool AddShip(ShipInstance ship) { if (TestShipDuplicate(ship.ship)) { throw new FaultException("Duplicate Ship (cheater)"); } else if (ship.pos.x >= 0 && ship.pos.x < boardSize && (ship.rotation != Rotation.RIGHT || ship.pos.x + ship.ship.length < boardSize) && //EITHER ship is not pointing right, or if it is pointing right then is within grid ship.pos.y >= 0 && ship.pos.y < boardSize && (ship.rotation != Rotation.DOWN || ship.pos.y + ship.ship.length < boardSize)) { if (TestShipPosition(ship)) { ships.Add(ship); return(true); } else { throw new FaultException("Overlapping with another ship"); } } else { throw new FaultException("Going outside grid"); } }
public bool AddShip(ShipInstance ship) { if (TestShipDuplicate(ship.ship)) { throw new FaultException("Duplicate Ship (cheater)"); } else if (ship.pos.x >= 0 && ship.pos.x < boardSize && (ship.rotation != Rotation.RIGHT || ship.pos.x + ship.ship.length < boardSize) && //EITHER ship is not pointing right, or if it is pointing right then is within grid ship.pos.y >= 0 && ship.pos.y < boardSize && (ship.rotation != Rotation.DOWN || ship.pos.y + ship.ship.length < boardSize)) { if (TestShipPosition(ship)) { ships.Add(ship); return true; } else { throw new FaultException("Overlapping with another ship"); } } else { throw new FaultException("Going outside grid"); } }
public bool TestShipPosition(ShipInstance ship) { foreach (ShipInstance shipinst in ships) { if (shipinst.CheckOverlap(ship)) { return(false); } } return(true); }
public bool CheckOverlap(ShipInstance other) { List<Position> path = GetPath(); List<Position> otherpath = other.GetPath(); foreach (Position pos in path) { if (otherpath.Contains(pos)) { return true; } } return false; }
public bool CheckOverlap(ShipInstance other) { List <Position> path = GetPath(); List <Position> otherpath = other.GetPath(); foreach (Position pos in path) { if (otherpath.Contains(pos)) { return(true); } } return(false); }
public bool AddShip(int playerId, ShipInstance ship) { //clients only have access to the ship ID field // read this out and inject in the real ship instance. ship.ship = gb.ships[ship.shipId]; bool result = gb.games[playerId].AddShip(ship); //automate ready if (gb.games[playerId].ships.Count >= gb.ships.Count) //if pships > gbships SHOULD never happem, but.. you never know { setReady(playerId); } return result; }
public bool AddShip(int playerId, ShipInstance ship) { //clients only have access to the ship ID field // read this out and inject in the real ship instance. ship.ship = gb.ships[ship.shipId]; bool result = gb.games[playerId].AddShip(ship); //automate ready if (gb.games[playerId].ships.Count >= gb.ships.Count) //if pships > gbships SHOULD never happem, but.. you never know { setReady(playerId); } return(result); }
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 bool TestShipPosition(ShipInstance ship) { foreach (ShipInstance shipinst in ships) { if (shipinst.CheckOverlap (ship)) return false; } return true; }