예제 #1
0
        public void TestConstructor_CreateSquareWithShipNull()
        {
            Square square = new Square(null, SquareState.EmptyNoShot);

            Assert.AreEqual(null, square.Ship);
            Assert.AreEqual(SquareState.EmptyNoShot, square.State);
        }
예제 #2
0
        public void TestConstructor_CreateSquareWithShipProvided()
        {
            Ship ship = new Ship(ShipType.Battleship);
            Square square = new Square(ship, SquareState.EmptyNoShot);

            Assert.AreSame(ship, square.Ship);
            Assert.AreEqual(SquareState.EmptyNoShot, square.State);
        }
예제 #3
0
        public Grid(int inXSize, int inYSize)
        {
            width = inXSize;
            height = inYSize;

            // Create the grid using a funky-for-loop-solution
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    Square sq = new Square(x, y);
                    grid.Add(sq);
                }
            }
        }
예제 #4
0
        private IEnumerable<Square> GetSquaresForShip(Ship ship)
        {
            int deltaRow = ship.Direction == ShipDirection.Horizontal ? 0 : 1;
            int deltaCol = ship.Direction == ShipDirection.Horizontal ? 1 : 0;

            Square[] squares = new Square[ship.Size];

            for (int i = 0; i < ship.Size; i++)
            {
                int row = ship.Bow.Row + (i * deltaRow);
                int col = ship.Bow.Col + (i * deltaCol);

                squares[i] = this.grid[row, col];
            }

            return squares;
        }