Ejemplo n.º 1
0
        private void NewTurn()
        {
            // find the next player and their tank
            currentTank   = currentGame.GetPlayerTank();
            currentPlayer = currentTank.GetPlayerNumber();
            //set the title of a form to current round of total rounds
            this.Text = string.Format("Tank battle - Round {0} of {1}", currentGame.CurrentRound(), currentGame.GetNumRounds());
            // set backcolor of controlpanel to currentplayers colour
            controlPanel.BackColor = currentPlayer.PlayerColour();
            // show the current player's name
            currentPlayerLabel.Text = currentPlayer.Name();
            // set angle to current gameplaytank's angle
            this.Aim(currentTank.GetTankAngle());
            //show current tank's power
            this.SetTankPower(currentTank.GetPower());
            //show current windspeed
            //postive values should state its a eastly wind while negative values come from windly west
            if (currentGame.GetWind() >= 0)
            {
                windspeedLabel.Text = string.Format("{0} E", currentGame.GetWind());
            }
            else
            {
                windspeedLabel.Text = string.Format("{0} W", (currentGame.GetWind() * -1)); // times by a negative number to shows a flat value for wind
            }
            //clear weapon choices in weaponSelect
            weaponSelect.Items.Clear();
            // find all weapons available to current tank
            foreach (string weapon in currentTank.GetTank().ListWeapons())
            {
                // add each weapon to selection choice of weaponSelect
                weaponSelect.Items.Add(weapon);
            }
            //set the current weapon to be used of current tank
            SetWeapon(currentTank.GetWeapon());

            if (currentPlayer is PlayerController)
            {
                // give controls for firing a weapon
                currentPlayer.BeginTurn(this, currentGame);
            }
            else if (currentPlayer is AIOpponent)
            {
                //run the firing command on currentplayer
                currentPlayer.BeginTurn(this, currentGame);
            }
        }
Ejemplo n.º 2
0
        private string weaponName = "Iron shell"; // used to storage the tank's weapon

        /// <summary>
        /// Fire a specified weapon from the tank
        /// </summary>
        /// <param name="weapon">Weapon selected</param>
        /// <param name="playerTank">The tank firing</param>
        /// <param name="currentGame">The current battle</param>
        public override void ActivateWeapon(int weapon, GameplayTank playerTank, Battle currentGame)
        {
            float         tankX;        // used to storage the firing position of a tank
            float         tankY;
            GenericPlayer firingPlayer; //used to storage owner of tank
            int           damage, explosionRadius, earthDestruction;

            // get the current position of tank
            tankX = playerTank.GetX();
            tankY = playerTank.Y();
            // find the centre of tank by add half the width and height
            tankX = tankX + TankModel.WIDTH / 2;
            tankY = tankY + TankModel.HEIGHT / 2;
            // get the firing player of tank
            firingPlayer = playerTank.GetPlayerNumber();
            // create new explosion
            Explosion basicExplosion;

            //set power of weapon
            damage           = 100; // damage done by bullet
            explosionRadius  = 4;   //size of explosion
            earthDestruction = 4;   //damage to area around explosion
            basicExplosion   = new Explosion(damage,
                                             explosionRadius,
                                             earthDestruction);
            //create new bullet
            Bullet basicBullet;

            basicBullet = new Bullet(tankX,
                                     tankY,
                                     playerTank.GetTankAngle(),
                                     playerTank.GetPower(),
                                     0.01f, //gravity
                                     basicExplosion,
                                     firingPlayer)
            ;
            //add bullet to games current effects to continue flying through the environment
            currentGame.AddEffect(basicBullet);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Fire a specified weapon from the tank
        /// </summary>
        /// <param name="weapon">Weapon selected</param>
        /// <param name="playerTank">The tank firing</param>
        /// <param name="currentGame">The current battle</param>
        public override void ActivateWeapon(int weapon, GameplayTank playerTank, Battle currentGame)
        {
            float         tankX;                         // used to storage the firing position of a tank
            float         tankY;
            GenericPlayer firingPlayer;                  //used to storage owner of tank
            int           damage, explosionRadius, earthDestruction;
            Random        unaccurateShot = new Random(); // used to make the missles fly off course a bit

            // get the current position of tank
            tankX = playerTank.GetX();
            tankY = playerTank.Y();
            // find the centre of tank by add half the width and height
            tankX = tankX + TankModel.WIDTH / 2;
            tankY = tankY + TankModel.HEIGHT / 2;
            // get the firing player of tank
            firingPlayer = playerTank.GetPlayerNumber();
            //set power of weapon
            damage           = 80; // damage done by bullet
            explosionRadius  = 4;  //size of explosion
            earthDestruction = 4;  //damage to area around explosion

            //check which sort of shot to fire;
            if ((WeaponChoice)weapon == WeaponChoice.IronShell)
            {
                //fire a normal shot
                //create a explosion for the shot
                Explosion basicExplosion;
                basicExplosion = new Explosion(damage,
                                               explosionRadius,
                                               earthDestruction);
                //create new bullet
                Bullet basicBullet;
                basicBullet = new Bullet(tankX,
                                         tankY,
                                         playerTank.GetTankAngle(),
                                         playerTank.GetPower(),
                                         0.01f, //gravity
                                         basicExplosion,
                                         firingPlayer)
                ;
                //add bullet to games current effects to continue flying through the environment
                currentGame.AddEffect(basicBullet);
            }
            if ((WeaponChoice)weapon == WeaponChoice.PierceShot)
            {
                //fire a shot which will pierce the first thing it hits and cause a second explosion

                //fire a piecre shot with a weaker strength
                int weakerStr = 60;
                int makePercentageOfOrginial = 100;
                //create a explosion for the shot
                Explosion pierceExplosion;

                pierceExplosion = new Explosion((damage * weakerStr) / makePercentageOfOrginial,
                                                (explosionRadius * weakerStr) / makePercentageOfOrginial,
                                                (earthDestruction * weakerStr) / makePercentageOfOrginial
                                                );
                //create new bullet
                PierceBullet pierceBullet;
                pierceBullet = new PierceBullet(tankX,
                                                tankY,
                                                playerTank.GetTankAngle(),
                                                playerTank.GetPower(),
                                                0.01f, //gravity
                                                pierceExplosion,
                                                firingPlayer)
                ;
                //add bullet to games current effects to continue flying through the environment
                currentGame.AddEffect(pierceBullet);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Fire a specified weapon from the tank
        /// </summary>
        /// <param name="weapon">Weapon selected</param>
        /// <param name="playerTank">The tank firing</param>
        /// <param name="currentGame">The current battle</param>
        public override void ActivateWeapon(int weapon, GameplayTank playerTank, Battle currentGame)
        {
            float         tankX;                         // used to storage the firing position of a tank
            float         tankY;
            GenericPlayer firingPlayer;                  //used to storage owner of tank
            int           damage, explosionRadius, earthDestruction;
            Random        unaccurateShot = new Random(); // used to make the missles fly off course a bit

            // get the current position of tank
            tankX = playerTank.GetX();
            tankY = playerTank.Y();
            // find the centre of tank by add half the width and height
            tankX = tankX + TankModel.WIDTH / 2;
            tankY = tankY + TankModel.HEIGHT / 2;
            // get the firing player of tank
            firingPlayer = playerTank.GetPlayerNumber();
            //set power of weapon
            damage           = 5;  // damage done by bullet
            explosionRadius  = 10; //size of explosion
            earthDestruction = 10; //damage to area around explosion

            //check which sort of shot to fire
            if ((WeaponChoice)weapon == WeaponChoice.BigBang)
            {
                //create a explosion for the bullet
                Explosion firstExplosion;
                firstExplosion = new Explosion(damage,
                                               explosionRadius,
                                               earthDestruction);
                //create a bullet for the shot
                Bullet firstBullet;
                firstBullet = new Bullet(tankX,
                                         tankY,
                                         playerTank.GetTankAngle(),
                                         playerTank.GetPower(),
                                         0.03f,
                                         firstExplosion,
                                         playerTank.GetPlayerNumber()
                                         );
                //add the bullet to the battle environment
                currentGame.AddEffect(firstBullet);
            }
            if ((WeaponChoice)weapon == WeaponChoice.SmallBangs)
            {
                //this weapon choice fires multiple 1-3 smaller bullets
                Random shotsFired    = new Random();
                int    numberOfShots = shotsFired.Next(1, 4);
                //create a explosion for the bullet
                Explosion firstExplosion;
                //create a weaker shot than a normal shot
                int makeWeaker = 60;
                int makePertcentageOfOrginalValue = 100;
                firstExplosion = new Explosion((damage * makeWeaker) / makePertcentageOfOrginalValue,
                                               (explosionRadius * makeWeaker) / makePertcentageOfOrginalValue,
                                               (earthDestruction * makeWeaker) / makePertcentageOfOrginalValue)
                ;
                //create a bullet for the shot
                Bullet firstBullet;
                firstBullet = new Bullet(tankX,
                                         tankY,
                                         playerTank.GetTankAngle(),
                                         playerTank.GetPower(),
                                         0.01f,
                                         firstExplosion,
                                         playerTank.GetPlayerNumber()
                                         );
                //add the bullet to the battle environment
                currentGame.AddEffect(firstBullet);

                if (numberOfShots > 1)
                {
                    //fire a second shot
                    //create a explosion for the bullet
                    Explosion secondExplosion;
                    secondExplosion = new Explosion((damage * makeWeaker) / makePertcentageOfOrginalValue,
                                                    (explosionRadius * makeWeaker) / makePertcentageOfOrginalValue,
                                                    (earthDestruction * makeWeaker) / makePertcentageOfOrginalValue)
                    ;
                    //create a bullet for the shot
                    Bullet secondBullet;
                    secondBullet = new Bullet(tankX,
                                              tankY,
                                              playerTank.GetTankAngle(),
                                              playerTank.GetPower(),
                                              0.015f,
                                              secondExplosion,
                                              playerTank.GetPlayerNumber()
                                              );
                    //add the bullet to the battle environment
                    currentGame.AddEffect(secondBullet);
                }
                if (numberOfShots > 2)
                {
                    //fire a third shot
                    //create a explosion for the bullet
                    Explosion thirdExplosion;
                    thirdExplosion = new Explosion((damage * makeWeaker) / makePertcentageOfOrginalValue,
                                                   (explosionRadius * makeWeaker) / makePertcentageOfOrginalValue,
                                                   (earthDestruction * makeWeaker) / makePertcentageOfOrginalValue)
                    ;
                    //create a bullet for the shot
                    Bullet thirdBullet;
                    thirdBullet = new Bullet(tankX,
                                             tankY,
                                             playerTank.GetTankAngle(),
                                             playerTank.GetPower(),
                                             0.02f,
                                             thirdExplosion,
                                             playerTank.GetPlayerNumber()
                                             );
                    //add the bullet to the battle environment
                    currentGame.AddEffect(thirdBullet);
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Fire a specified weapon from the tank
        /// </summary>
        /// <param name="weapon">Weapon selected</param>
        /// <param name="playerTank">The tank firing</param>
        /// <param name="currentGame">The current battle</param>
        public override void ActivateWeapon(int weapon, GameplayTank playerTank, Battle currentGame)
        {
            float         tankX;                         // used to storage the firing position of a tank
            float         tankY;
            GenericPlayer firingPlayer;                  //used to storage owner of tank
            int           damage, explosionRadius, earthDestruction;
            Random        unaccurateShot = new Random(); // used to make the missles fly off course a bit

            // get the current position of tank
            tankX = playerTank.GetX();
            tankY = playerTank.Y();
            // find the centre of tank by add half the width and height
            tankX = tankX + TankModel.WIDTH / 2;
            tankY = tankY + TankModel.HEIGHT / 2;
            // get the firing player of tank
            firingPlayer = playerTank.GetPlayerNumber();
            //set power of weapon
            damage           = 50; // damage done by bullet
            explosionRadius  = 3;  //size of explosion
            earthDestruction = 2;  //damage to area around explosion

            //check which sort of shot to fire
            if ((WeaponChoice)weapon == WeaponChoice.DoubleTap)
            {
                // fire two to semi accurate missiles
                // create explosions for missiles
                Explosion firstExplosion;
                Explosion secondExplosion;
                firstExplosion = new Explosion(damage,
                                               explosionRadius,
                                               earthDestruction);
                secondExplosion = new Explosion(damage,
                                                explosionRadius,
                                                earthDestruction);
                //create new missile bullets
                Bullet firstMissile;
                Bullet secondMissile;
                firstMissile = new Bullet(tankX,
                                          tankY,
                                          playerTank.GetTankAngle() + (unaccurateShot.Next(-2, 3)),
                                          playerTank.GetPower() + (unaccurateShot.Next(-3, 4)),
                                          0.01f, //gravity
                                          firstExplosion,
                                          firingPlayer)
                ;
                secondMissile = new Bullet(tankX,
                                           tankY,
                                           playerTank.GetTankAngle() + (unaccurateShot.Next(-2, 3)),
                                           playerTank.GetPower() + (unaccurateShot.Next(-3, 4)),
                                           0.01f, //gravity
                                           secondExplosion,
                                           firingPlayer)
                ;
                //add bullet to games current effects to continue flying through the environment
                currentGame.AddEffect(firstMissile);
                currentGame.AddEffect(secondMissile);
            }
            if ((WeaponChoice)weapon == WeaponChoice.Barrage)
            {
                // fire four missiles but they are very inaccurate shots
                //create explosions
                Explosion firstExplosion;
                Explosion secondExplosion;
                Explosion thridExplosion;
                Explosion fourthExplosion;
                firstExplosion = new Explosion(damage,
                                               explosionRadius,
                                               earthDestruction);
                secondExplosion = new Explosion(damage,
                                                explosionRadius,
                                                earthDestruction);
                thridExplosion = new Explosion(damage,
                                               explosionRadius,
                                               earthDestruction);
                fourthExplosion = new Explosion(damage,
                                                explosionRadius,
                                                earthDestruction);
                //create new missile bullets
                Bullet firstMissile;
                Bullet secondMissile;
                Bullet thridMissile;
                Bullet fourthMissile;
                firstMissile = new Bullet(tankX,
                                          tankY,
                                          playerTank.GetTankAngle() + (unaccurateShot.Next(-4, 9)),
                                          playerTank.GetPower() + (unaccurateShot.Next(-4, 9)),
                                          0.01f, //gravity
                                          firstExplosion,
                                          firingPlayer)
                ;
                secondMissile = new Bullet(tankX,
                                           tankY,
                                           playerTank.GetTankAngle() + (unaccurateShot.Next(-4, 9)),
                                           playerTank.GetPower() + (unaccurateShot.Next(-4, 9)),
                                           0.01f, //gravity
                                           secondExplosion,
                                           firingPlayer)
                ;
                thridMissile = new Bullet(tankX,
                                          tankY,
                                          playerTank.GetTankAngle() + (unaccurateShot.Next(-4, 9)),
                                          playerTank.GetPower() + (unaccurateShot.Next(-4, 9)),
                                          0.01f, //gravity
                                          thridExplosion,
                                          firingPlayer)
                ;
                fourthMissile = new Bullet(tankX,
                                           tankY,
                                           playerTank.GetTankAngle() + (unaccurateShot.Next(-4, 9)),
                                           playerTank.GetPower() + (unaccurateShot.Next(-4, 9)),
                                           0.01f, //gravity
                                           fourthExplosion,
                                           firingPlayer)
                ;
                //add bullet to games current effects to continue flying through the environment
                currentGame.AddEffect(firstMissile);
                currentGame.AddEffect(secondMissile);
                currentGame.AddEffect(thridMissile);
                currentGame.AddEffect(fourthMissile);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// allows the use of a keyboard to control the firing of a tank
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="keypressed"></param>
        private void BattleForm_KeyDown(object sender, KeyEventArgs keypressed)
        {
            if (keypressed.KeyCode == Keys.Enter)
            {
                // if enter was hit then the player wants to fire their bullet
                if (controlPanel.Enabled)
                {
                    //if a human player is active then allow a shot to be fired
                    Fire();
                }
            }
            if (keypressed.KeyCode == Keys.Left)
            {
                // if key pressed was left then reduce firing angle
                // but check it doesnt go outside bounds of -90
                if (currentTank.GetTankAngle() - 5 >= -90)
                {
                    currentTank.Aim(currentTank.GetTankAngle() - 5);
                    currentTank.Paint(gameplayGraphics.Graphics, displayPanel.Size);
                }
                // update form with new angle
                angleUpDown.Value = (decimal)currentTank.GetTankAngle();
            }

            if (keypressed.KeyCode == Keys.Right)
            {
                // if key pressed was right then increase firing angle
                //but check it doesn't go outsides bounds of 90
                if (currentTank.GetTankAngle() + 5 <= 90)
                {
                    currentTank.Aim(currentTank.GetTankAngle() + 5);
                    currentTank.Paint(gameplayGraphics.Graphics, displayPanel.Size);
                }
                //update form with new angle
                angleUpDown.Value = (decimal)currentTank.GetTankAngle();
            }
            if (keypressed.KeyCode == Keys.Up)
            {
                //if the key pressed was up then increase firing power
                // but check it doesn't go outside bounds of 100%
                if (currentTank.GetPower() + 2 <= 100)
                {
                    currentTank.SetTankPower(currentTank.GetPower() + 2);
                }
                //update form with new power setting
                powerTrack.Value = (currentTank.GetPower());
                powerLabel.Text  = string.Format("Power: {0}", currentTank.GetPower());
            }
            if (keypressed.KeyCode == Keys.Down)
            {
                //if the key pressed was up then decrease firing power
                // but check it doesn't go outside bounds of 0%
                if (currentTank.GetPower() - 1 >= 0)
                {
                    currentTank.SetTankPower(currentTank.GetPower() - 2);
                }
                //update form with new power setting
                powerTrack.Value = (currentTank.GetPower());
                powerLabel.Text  = string.Format("Power: {0}", currentTank.GetPower());
            }
        }