Ejemplo n.º 1
0
        public void CanSinkShip()
        {
            var board = SetupBoard();

            var coordinate = new Coordinate(10, 6);
            var response = board.FireShot(coordinate);

            Assert.AreEqual(ShotStatus.Hit, response.ShotStatus);
            Assert.AreEqual("Battleship", response.ShipImpacted);

            coordinate = new Coordinate(10, 7);
            response = board.FireShot(coordinate);

            Assert.AreEqual(ShotStatus.Hit, response.ShotStatus);
            Assert.AreEqual("Battleship", response.ShipImpacted);

            coordinate = new Coordinate(10, 8);
            response = board.FireShot(coordinate);

            Assert.AreEqual(ShotStatus.Hit, response.ShotStatus);
            Assert.AreEqual("Battleship", response.ShipImpacted);

            coordinate = new Coordinate(10, 9);
            response = board.FireShot(coordinate);

            Assert.AreEqual(ShotStatus.HitAndSunk, response.ShotStatus);
            Assert.AreEqual("Battleship", response.ShipImpacted);
        }
Ejemplo n.º 2
0
        public void CanMissShip()
        {
            var board = SetupBoard();

            var coordinate = new Coordinate(5, 5);
            var response = board.FireShot(coordinate);

            Assert.AreEqual(ShotStatus.Miss, response.ShotStatus);
        }
Ejemplo n.º 3
0
        public void CanNotFireOffBoard()
        {
            var board = SetupBoard();

            var coordinate = new Coordinate(15, 20);

            var response = board.FireShot(coordinate);

            Assert.AreEqual(ShotStatus.Invalid, response.ShotStatus);
        }
Ejemplo n.º 4
0
        public void CanHitShip()
        {
            var board = SetupBoard();

            var coordinate = new Coordinate(3, 1);
            var response = board.FireShot(coordinate);

            Assert.AreEqual(ShotStatus.Hit, response.ShotStatus);
            Assert.AreEqual("Cruiser", response.ShipImpacted);
        }
Ejemplo n.º 5
0
        public void CanNotFireDuplicateShot()
        {
            var board = SetupBoard();

            var coordinate = new Coordinate(5, 5);
            var response = board.FireShot(coordinate);

            Assert.AreEqual(ShotStatus.Miss, response.ShotStatus);

            // fire same shot
            response = board.FireShot(coordinate);
            Assert.AreEqual(ShotStatus.Duplicate, response.ShotStatus);
        }
Ejemplo n.º 6
0
        public ShotStatus FireAtShip(Coordinate position)
        {
            if (BoardPositions.Contains(position))
            {
                _lifeRemaining--;

                if(_lifeRemaining == 0)
                    return ShotStatus.HitAndSunk;

                return ShotStatus.Hit;
            }

            return ShotStatus.Miss;
        }
Ejemplo n.º 7
0
        private FireShotResponse SinkSubmarine(Board board)
        {
            var coordinate = new Coordinate(1, 5);

            board.FireShot(coordinate);

            coordinate = new Coordinate(2, 5);
            board.FireShot(coordinate);

            coordinate = new Coordinate(3, 5);
            return board.FireShot(coordinate);
        }
Ejemplo n.º 8
0
        private FireShotResponse SinkDestroyer(Board board)
        {
            var coordinate = new Coordinate(1, 8);
            board.FireShot(coordinate);

            coordinate = new Coordinate(2, 8);
            return board.FireShot(coordinate);
        }
Ejemplo n.º 9
0
        private FireShotResponse SinkCruiser(Board board)
        {
            var coordinate = new Coordinate(3, 1);
            board.FireShot(coordinate);

            coordinate = new Coordinate(3, 2);
            board.FireShot(coordinate);

            coordinate = new Coordinate(3, 3);
            return board.FireShot(coordinate);
        }
Ejemplo n.º 10
0
        private FireShotResponse SinkCarrier(Board board)
        {
            var coordinate = new Coordinate(4, 4);
            board.FireShot(coordinate);

            coordinate = new Coordinate(5, 4);
            board.FireShot(coordinate);

            coordinate = new Coordinate(6, 4);
            board.FireShot(coordinate);

            coordinate = new Coordinate(7, 4);
            board.FireShot(coordinate);

            coordinate = new Coordinate(8, 4);
            return board.FireShot(coordinate);
        }
Ejemplo n.º 11
0
        private FireShotResponse SinkBattleship(Board board)
        {
            var coordinate = new Coordinate(10, 6);
            board.FireShot(coordinate);

            coordinate = new Coordinate(10, 7);
            board.FireShot(coordinate);

            coordinate = new Coordinate(10, 8);
            board.FireShot(coordinate);

            coordinate = new Coordinate(10, 9);
            return board.FireShot(coordinate);
        }
Ejemplo n.º 12
0
        public void CoordinateEquality()
        {
            var c1 = new Coordinate(5, 10);
            var c2 = new Coordinate(5, 10);

            Assert.AreEqual(c1, c2);
        }
Ejemplo n.º 13
0
 public Ship(ShipType shipType, int numberOfSlots)
 {
     ShipType = shipType;
     _lifeRemaining = numberOfSlots;
     BoardPositions = new Coordinate[numberOfSlots];
 }
Ejemplo n.º 14
0
 public Ship(ShipType shipType, int numberOfSlots)
 {
     ShipType = shipType; // ShipType object, set to one of the values of the enum ship type
     _lifeRemaining = numberOfSlots;
     BoardPositions = new Coordinate[numberOfSlots];
 }