/// <summary>
 /// Method called both externally when the 'Fire!' button is clicked.
 ///
 /// Author John Santias and Hoang Nguyen October 2017
 /// </summary>
 public void Attack()
 {
     currentControlledTank = currentGame.GetCurrentGameplayTank();
     currentControlledTank.Attack();
     controlPanel.Enabled = false;
     formTimer.Enabled    = true;
 }
        /// <summary>
        /// Newly-created method used to update form elemtns to reflect who the current player is. It involves
        /// a number of things like changing the colours, angles, power, round number etc.
        ///
        /// Author John Santias and Hoang Nguyen October 2017
        /// </summary>
        private void NewTurn()
        {
            currentControlledTank = currentGame.GetCurrentGameplayTank();
            currentOpponent       = currentControlledTank.GetPlayerNumber();
            Text = "Tank Battle - Round " + currentGame.GetRound() + " of " + currentGame.GetTotalRounds();
            controlPanel.BackColor = currentOpponent.GetColour();
            playerLabel.Text       = currentOpponent.Name();
            currentControlledTank.SetAimingAngle(angleSet);
            currentControlledTank.SetPower(powerSet);
            windSpeed = currentGame.GetWindSpeed();

            if (windSpeed > 0)
            {
                windStatusLabel.Text = windSpeed + " E";
            }
            else if (windSpeed < 0)
            {
                windStatusLabel.Text = -windSpeed + " W";
            }
            weaponComboBox.Items.Clear();
            currentTankModel = currentControlledTank.GetTank();
            string[] weapons = currentTankModel.WeaponList();

            for (int i = 0; i < weapons.Length; i++)
            {
                weaponComboBox.Items.Add(weapons[i]);
            }

            weaponSet = currentControlledTank.GetWeaponIndex();
            SetWeaponIndex(weaponSet);
            currentOpponent.BeginTurn(this, currentGame);
        }
Exemple #3
0
        private void PowerBar_Scroll(object sender, EventArgs e)
        {
            ControlledTank tank  = currentGame.GetPlayerTank();
            int            power = PowerBar.Value;

            tank.SetPower(power);
        }
Exemple #4
0
        private void WeaponSelect_SelectedIndexChanged(object sender, EventArgs e)
        {
            ControlledTank tank   = currentGame.GetPlayerTank();
            int            weapon = WeaponSelect.SelectedIndex;

            tank.SelectWeapon(weapon);
        }
        public void StartRound()
        {
            /// <summary>
            ///
            /// This method begins a new round of gameplay. A game consists of multiple rounds,
            /// and a round consists of multiple turns.
            ///
            /// </summary>

            Random rand = new Random();

            _playerLoc     = GetPlayerLocations(_numPlayers.Length);
            _currentPlayer = _startPlayer;
            _currentBattle = new Battlefield();
            _numTanks      = new ControlledTank[_numPlayers.Length];
            _wind          = rand.Next(-100, 100);

            foreach (TankController value in _numPlayers)
            {
                value.BeginRound();
            }
            Rearrange(_playerLoc);
            for (int i = 0; i < _numPlayers.Length; i++)
            {
                int xPos = _playerLoc[i];
                int yPos = _currentBattle.TankVerticalPosition(xPos);
                _numTanks[i] = new ControlledTank(_numPlayers[i], xPos, yPos, this);
            }
            BattleForm battle = new BattleForm(this);

            battle.Show();
            SetupForm setup = new SetupForm();

            setup.Show();
        }
Exemple #6
0
        /// <summary>
        /// Handles firing the specified weapon from the tank.
        ///
        /// Author John Santias and Hoang Nguyen October 2017
        /// </summary>
        /// <param name="weapon">int based on string returned from Weaponlist()</param>
        /// <param name="playerTank">Controlledtank associated with this</param>
        /// <param name="currentGame">the current Game being played</param>
        public override void FireWeapon(int weapon, ControlledTank playerTank, Gameplay currentGame)
        {
            float    centerPosX = (float)playerTank.GetX() + (WIDTH / 2), centerPosY = (float)playerTank.GetYPos() + (HEIGHT / 2);
            Opponent op    = playerTank.GetPlayerNumber();
            Blast    blast = new Blast(100, 4, 4);
            Shell    shell = new Shell(centerPosX, centerPosY, playerTank.GetAim(), playerTank.GetCurrentPower(), 0.01f, blast, op);

            currentGame.AddWeaponEffect(shell);
        }
Exemple #7
0
        private void AngleNo_ValueChanged(object sender, EventArgs e)
        {
            ControlledTank tank  = currentGame.GetPlayerTank();
            float          angle = (float)AngleNo.Value;

            tank.SetAimingAngle(angle);
            DrawGameplay();
            displayPanel.Invalidate();
        }
Exemple #8
0
        public void Launch()
        {
            /// <summary>
            ///
            /// This method is called both externally (by the computer player when it wants to fire)
            /// and by the 'Fire!' button when it is clicked. It does the following:
            ///
            /// </summary>

            ControlledTank _tank = currentGame.GetPlayerTank();

            _tank.Launch();
            controlPanel.Enabled = false;
            timer1.Enabled       = true;
        }
Exemple #9
0
        private void NewTurn()
        {
            /// <summary>
            ///
            /// This newly-created method is used to update form elements to reflect who the current player is.
            ///
            /// </summary>

            ControlledTank _tank   = currentGame.GetPlayerTank();
            Tank           _type   = _tank.GetTank();
            TankController _player = _tank.GetPlayerById();

            float angle = _tank.GetTankAngle();
            int   power = _tank.GetTankPower();

            Text        = "Round" + currentGame.GetCurrentRound() + "of" + currentGame.GetCurrentRound();
            BackColor   = _player.TankColour();
            Player.Text = _player.Name();
            SetAimingAngle(angle);
            SetPower(power);

            if (currentGame.Wind() >= 0)
            {
                WindSpeed.Text = currentGame.Wind() + "E";
            }
            else
            {
                WindSpeed.Text = currentGame.Wind() + "W";
            }
            WeaponSelect.Items.Clear();

            string[] avaliableWeapons = _type.ListWeapons();

            for (int i = 0; i < avaliableWeapons.Length; i++)
            {
                WeaponSelect.Items.Add(avaliableWeapons[i]);
            }
            SelectWeapon(WeaponSelect.SelectedIndex);
            _player.NewTurn(this, currentGame);
        }
Exemple #10
0
        /// <summary>
        /// Begins new round of gamplay. A game consists of multiple rounds and rounds consists of multiple
        /// turns. The method initialises the private field of Gameplay setting currentplayer to starting
        /// opponent. Creates new Terrain and an shuffled array of opponent's positions. Tanks are then placed
        /// on their positions. The wind speed of the game is set.
        /// Finally, the gameplay form is shown and game is ready to be played.
        ///
        /// Author John Santias September 2017
        /// </summary>
        public void BeginRound()
        {
            currentPlayer = opponent;
            newTerrain    = new Terrain();
            int[] thepos = CalculatePlayerPositions(theOppo.Length);

            for (int i = 0; i < theOppo.Length - 1; i++)
            {
                theOppo[i].StartRound();
            }

            Shuffle(thepos);
            theTank = new ControlledTank[theOppo.Length];
            for (int i = 0; i < theTank.Length; i++)
            {
                theTank[i] = new ControlledTank(theOppo[i], thepos[i], newTerrain.TankYPosition(thepos[i]), this);
            }

            GetWindSpeed();

            GameplayForm newForm = new GameplayForm(this);

            newForm.Show();
        }
Exemple #11
0
 /// <summary>
 ///
 /// This abstract method is used to handle firing the specified weapon from the tank playerTank.
 ///
 /// </summary>
 /// <param name="weapon"> Weapon index </param>
 /// <param name="playerTank"> The playerTank in reference to ControlledTank </param>
 /// <param name="currentGame"> The currentGame in reference to Gameplay </param>
 public abstract void FireWeapon(int weapon, ControlledTank playerTank, Gameplay currentGame);