예제 #1
0
        public void TestRemoveShip()
        {
            Dictionary <ShipName, Ship> dict = new Dictionary <ShipName, Ship> ();

            SeaGrid c    = new SeaGrid(dict);
            Ship    ship = new Ship(ShipName.None);


            Ship [] s = new Ship [2];
            s [0] = new Ship(ShipName.Tug);
            s [1] = new Ship(ShipName.Submarine);


            //dict.Add (ShipName.Tug, ship);
            //dict.Add (ShipName.Submarine, ship);
            c.AddShip(6, 7, Direction.LeftRight, s [0]);
            c.AddShip(3, 5, Direction.LeftRight, s [1]);

            //Assert.AreEqual (2, c.ShipCount);

            //ship.Remove(ShipName.Tug, ship);

            s [0].Remove();
            s [1].Remove();

            Assert.AreEqual(0, c.ShipCount);
            Assert.AreNotEqual(1, c.ShipCount);
        }
예제 #2
0
        public Player(BattleShipsGame controller)
        {
            _game       = controller;
            _playerGrid = new SeaGrid(_Ships);
            //for each ship add the ships name so the seagrid knows about them
            foreach (ShipName name in Enum.GetValues(typeof(ShipName)))
            {
                if (name != ShipName.None)
                {
                    _Ships.Add(name, new Ship(name));
                }
            }

            RandomizeDeployment();
        }
예제 #3
0
        public Player(BattleShipsGame controller)
        {
            // Non-static class variable initialization is below.  Class variables cannot be initially assigned non-static values in C#.
            _playerGrid = new SeaGrid(_Ships);

            _game = controller;

            //for each ship add the ships name so the seagrid knows about them
            foreach (ShipName name in Enum.GetValues(typeof(ShipName)))
            {
                if (name != ShipName.None)
                {
                    _Ships.Add(name, new Ship(name));
                }
            }

            RandomizeDeployment();
        }
예제 #4
0
        public void TestAddShip()
        {
            Dictionary <ShipName, Ship> dict = new Dictionary <ShipName, Ship> ();

            SeaGrid c    = new SeaGrid(dict);
            Ship    ship = new Ship(ShipName.None);

            Ship [] s = new Ship [2];
            s [0] = new Ship(ShipName.Tug);
            s [1] = new Ship(ShipName.Submarine);

            Assert.AreEqual(0, c.ShipCount);

            dict.Add(ShipName.Tug, ship);
            dict.Add(ShipName.Submarine, ship);

            Assert.AreEqual(2, c.ShipCount);
        }
예제 #5
0
 /// <summary>
 /// Create the SeaGridAdapter, with the grid, and it will allow it to be changed
 /// </summary>
 /// <param name="grid">the grid that needs to be adapted</param>
 public SeaGridAdapter(SeaGrid grid)
 {
     _MyGrid = grid;
     //_MyGrid.Changed += new EventHandler(MyGrid_Changed);
 }
예제 #6
0
 /// <summary>
 /// Create the SeaGridAdapter, with the grid, and it will allow it to be changed
 /// </summary>
 /// <param name="grid">the grid that needs to be adapted</param>
 public SeaGridAdapter(SeaGrid grid)
 {
     _MyGrid          = grid;
     _MyGrid.Changed += new EventHandler(MyGrid_Changed);
 }
예제 #7
0
        /// <summary>
        /// Draws a small field, showing the attacks made and the locations of the player's ships
        /// </summary>
        /// <param name="grid">the grid to show</param>
        /// <param name="thePlayer">the player to show the ships of</param>
        public static void DrawSmallField(SeaGrid grid, Player thePlayer)
        {
            const int SMALL_FIELD_LEFT = 39;
            const int SMALL_FIELD_TOP = 373;
            const int SMALL_FIELD_WIDTH = 166;
            const int SMALL_FIELD_HEIGHT = 166;
            const int SMALL_FIELD_CELL_WIDTH = 13;
            const int SMALL_FIELD_CELL_HEIGHT = 13;
            const int SMALL_FIELD_CELL_GAP = 4;

            DrawCustomField(grid, thePlayer, true, true, SMALL_FIELD_LEFT, SMALL_FIELD_TOP, SMALL_FIELD_WIDTH, SMALL_FIELD_HEIGHT, SMALL_FIELD_CELL_WIDTH, SMALL_FIELD_CELL_HEIGHT,
            SMALL_FIELD_CELL_GAP);
        }