public bool ConflictsWith(Ship otherShip) { foreach (var otherShipLocation in otherShip.GetAllLocations()) { if (this.IsAt(otherShipLocation)) { return true; } } return false; }
public void Add(Ship ship) { switch (ship.Direction) { case Direction.Horizontal: if ((byte)(ship.X + ship.Length - 1) > 10 || ship.Y > 10) throw new ArgumentOutOfRangeException(); break; case Direction.Vertiacal: if ((byte)(ship.Y + ship.Length - 1) > 10 || ship.X > 10) throw new ArgumentOutOfRangeException(); break; } if (ships.Any(boat => boat.OverlapsWith(ship))) { throw new ShipOverlapException(); } ships.Add(ship); }
public static bool TryParse(string notation, out Ship pos) { if (RegexExprShip.FullExpression.Match(notation) == Match.Empty) { pos = null; return false; } var x = RegexExprShip.GetX(notation); var y = RegexExprShip.GetY(notation); var length = RegexExprShip.GetLength(notation); var direction = RegexExprShip.GetDirection(notation); pos = CreateNewShip(x, y, length, direction); return true; }
public bool OverlapsWith(Ship ship) { return (X - 1 <= ship.EndX && EndX + 1 >= ship.X && Y - 1 <= ship.EndY && EndY + 1 >= ship.Y); }
public Cruiser(Ship ship) : base(ship) { }
public PatrolBoat(Ship ship) : base(ship) { this.Direction = Direction.Horizontal; }
public void ShotHitAndSink(Point shot, Ship sunkShip) { ShotHit(shot, true); }
public void AddShip(Ship ship) { _ships.Add(ship); _shipsLeft.Add(ship.Type); }
/// <summary> /// The tile constructor will know where it is on the grid, and is its a ship /// </summary> /// <param name="row">the row on the grid</param> /// <param name="col">the col on the grid</param> /// <param name="ship">what ship it is</param> public Tile(int row, int col, Ship ship) { _RowValue = row; _ColumnValue = col; _Ship = ship; }
public void AddShipAfterLoadGame(string line, int shipNumb) { PlayerShips[shipNumb] = new Ship(line, shipNumb); }
/// <summary> /// Clearship will remove the ship from the tile /// </summary> public void ClearShip() { _Ship = null; }
public Segment(Ship owner) { Owner = owner; IsHit = false; }
public void ShotHitAndSink(Point shot, Ship sunkShip) { io.WriteLine("shot-hit-and-sink {0} {1} {2} {3}", sunkShip.Length, sunkShip.Location.X, sunkShip.Location.Y, sunkShip.Orientation.ToString().ToLower() ); }
public override void TearDown() { testShipBattleShip = null; testShipCustom = null; testShipInvalid = null; }
public override void SetUp() { testShipBattleShip = new Ship(ShipType.BATTLESHIP); testShipCustom = new Ship(7); testShipInvalid = new Ship(4); }