// '' <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);

        Changed += new EventHandler(GameController.GridChanged);
    }
Beispiel #2
0
        public void SeaGridHitTileTest()
        {
            seaGrid = new SeaGrid(Ships);
            seaGrid.MoveShip(0, 0, ShipName.Tug, Direction.LeftRight);
            AttackResult ar = seaGrid.HitTile(0, 0);

            Assert.AreEqual(ar.Value, ResultOfAttack.Destroyed);
        }
Beispiel #3
0
    public void reset(SeaGrid pPlayerGrid, ISeaGrid pEnemyGrid)
    {
        _hits   = 0;
        _misses = 0;
        _shots  = 0;

        PlayerGrid = pPlayerGrid;
        EnemyGrid  = pEnemyGrid;
    }
Beispiel #4
0
 public void SeaGridItemTest()
 {
     seaGrid = new SeaGrid(Ships);
     //the sea grid should be empty. Check to make sure though.
     for (int x = 0; x < seaGrid.Width; x++)
     {
         for (int y = 0; y < seaGrid.Height; y++)
         {
             Assert.AreEqual(seaGrid.Item(x, y), TileView.Sea);
         }
     }
 }
Beispiel #5
0
        public void TestShipDeployed()
        {
            int     offset  = 0;
            SeaGrid seaGrid = new SeaGrid(_ships);

            foreach (KeyValuePair <ShipName, Ship> entry in _ships)
            {
                ShipName name = entry.Key;
                Ship     ship = entry.Value;
                seaGrid.MoveShip(0, offset++, name, Direction.UpDown);
                Assert.IsTrue(ship.IsDeployed);
            }
        }
Beispiel #6
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();
 }
Beispiel #7
0
        public void SeaGridInitTest()
        {
            //build an array of ships.
            foreach (ShipName s in System.Enum.GetValues(typeof(ShipName)))
            {
                if (s != ShipName.None)
                {
                    Ships.Add(s, new Ship(s));
                }
            }

            //now add the new seagrid
            seaGrid = new SeaGrid(Ships);
        }
Beispiel #8
0
        public void SetUp()
        {
            // initialize ships
            _ships.Clear();
            foreach (ShipName name in Enum.GetValues(typeof(ShipName)))
            {
                if (name != ShipName.None)
                {
                    _ships.Add(name, new Ship(name));
                }
            }

            // initialize seagrid
            _seaGrid = new SeaGrid(_ships);
        }
        public void AlldeployedProperty()
        {
            Ship ship1 = new Ship(ShipName.Battleship);

            Dictionary <ShipName, Ship> ships = new Dictionary <ShipName, Ship> {
                [ShipName.Battleship] = ship1
            };
            SeaGrid seagrid = new SeaGrid(ships);

            bool expected = false;

            bool actual = seagrid.AllDeployed;

            Assert.AreEqual(expected, actual, "correct value is false");
        }
Beispiel #10
0
    /// <summary>
    /// Player Constructor.
    /// Initializes a new instance of the Player class.
    /// </summary>
    public Player(BattleShipsGame controller)
    {
        // VBConversions Note: 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();
    }
Beispiel #11
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));
            }
        }
#pragma warning disable RECS0021 // Warns about calls to virtual member functions occuring in the constructor
        RandomizeDeployment();
#pragma warning restore RECS0021 // Warns about calls to virtual member functions occuring in the constructor
    }
Beispiel #12
0
        public FormGame()
        {
            InitializeComponent();
            //sea_user = new Море();
            //sea_pc = new Море();

            sea_user           = new  едактор();
            sea_user.ShowShip  = ShowUserShip;//инициализация делегатов
            sea_user.ShowFight = ShowUserFight;

            sea_pc           = new  едактор();
            sea_pc.ShowShip  = ShowPcShip;
            sea_pc.ShowFight = ShowPcFight;

            GridUser = new SeaGrid(grid_user);
            GridComp = new SeaGrid(grid_pc);

            // InitGrid(grid_user);
            // InitGrid(grid_pc);

            Restart();
            timer1.Enabled = true;//для ходов компьютера
        }
 /// <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);
 }
Beispiel #14
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);
 }
Beispiel #15
0
 Player()
 {
     _playerGrid = new SeaGrid(_Ships);
 }
Beispiel #16
0
 private void InitializeInstanceFields()
 {
     _Ships      = new Dictionary <ShipName, Ship>();
     _playerGrid = new SeaGrid(_Ships);
 }
Beispiel #17
0
 private void InitializePlayer(BattleShipsGame controller)
 {
     _game       = controller;
     _playerGrid = new SeaGrid(_Ships);
     RandomizeDeployment(_Ships);
 }
Beispiel #18
0
 public void SeaGridMoveShipTest()
 {
     seaGrid = new SeaGrid(Ships);
     seaGrid.MoveShip(0, 0, ShipName.Tug, Direction.LeftRight);
     Assert.AreEqual(seaGrid.Item(0, 0), TileView.Ship);
 }
Beispiel #19
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(// TODO: Warning!!!! NULL EXPRESSION DETECTED...
         .);
 }
Beispiel #20
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 += MyGrid_Changed;
 }