コード例 #1
0
ファイル: Ship.cs プロジェクト: yendtm/Mohawk_Battleship
        public bool ConflictsWith(Ship otherShip)
        {
            foreach (var otherShipLocation in otherShip.GetAllLocations())
            {
                if (this.IsAt(otherShipLocation))
                {
                    return true;
                }
            }

            return false;
        }
コード例 #2
0
        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);
        }
コード例 #3
0
ファイル: Ship.cs プロジェクト: Zunderbird/kottans_homeworks
        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;
        }
コード例 #4
0
ファイル: Ship.cs プロジェクト: Zunderbird/kottans_homeworks
 public bool OverlapsWith(Ship ship)
 {
     return (X - 1 <= ship.EndX && EndX + 1 >= ship.X && Y - 1 <= ship.EndY && EndY + 1 >= ship.Y);
 }
コード例 #5
0
ファイル: Cruiser.cs プロジェクト: agni90/kottansHomeTasks
 public Cruiser(Ship ship)
     : base(ship)
 {
 }
コード例 #6
0
ファイル: PatrolBoat.cs プロジェクト: agni90/kottansHomeTasks
 public PatrolBoat(Ship ship)
     : base(ship)
 {
     this.Direction = Direction.Horizontal;
 }
コード例 #7
0
 public void ShotHitAndSink(Point shot, Ship sunkShip)
 {
     ShotHit(shot, true);
 }
コード例 #8
0
ファイル: BattleField.cs プロジェクト: dichaos/battleship
 public void AddShip(Ship ship)
 {
     _ships.Add(ship);
     _shipsLeft.Add(ship.Type);
 }
コード例 #9
0
ファイル: Tile.cs プロジェクト: morris1500m/Swin-BattleShips
 /// <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;
 }
コード例 #10
0
ファイル: Player.cs プロジェクト: JacDev/Battleship
 public void AddShipAfterLoadGame(string line, int shipNumb)
 {
     PlayerShips[shipNumb] = new Ship(line, shipNumb);
 }
コード例 #11
0
ファイル: Tile.cs プロジェクト: morris1500m/Swin-BattleShips
 /// <summary>
 /// Clearship will remove the ship from the tile
 /// </summary>
 public void ClearShip()
 {
     _Ship = null;
 }
コード例 #12
0
 public Segment(Ship owner)
 {
     Owner = owner;
     IsHit = false;
 }
コード例 #13
0
 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()
     );
 }
コード例 #14
0
 public override void TearDown()
 {
     testShipBattleShip = null;
     testShipCustom = null;
     testShipInvalid = null;
 }
コード例 #15
0
 public override void SetUp()
 {
     testShipBattleShip = new Ship(ShipType.BATTLESHIP);
     testShipCustom = new Ship(7);
     testShipInvalid = new Ship(4);
 }