예제 #1
0
        /// <summary>
        /// begins a new round of gameplay. A game consists of multiple rounds, and a round consists of multiple turns.
        /// </summary>
        public void CommenceRound()
        {
            //Initialising a private field of Battle representing the current player to the value of the starting GenericPlayer field (see NewGame).
            currentPlayer = startingGenericPlayer;
            //Creating a new Battlefield, which is also stored as a private field of Battle.
            battlefield = new Battlefield();
            //Creating an array of GenericPlayer positions by calling CalculatePlayerPositions with the number of GenericPlayers playing the game
            int[] positions = CalculatePlayerPositions(GenericPlayers.Length);
            //Looping through each GenericPlayer and calling its BeginRound method.
            foreach (GenericPlayer genricPlayer in GenericPlayers)
            {
                genricPlayer.BeginRound(); //is only currently used for computer players
            }

            Rearrange(positions);//Shuffling that array of positions with the Rearrange method.

            GameplayTanks = new GameplayTank[GenericPlayers.Length];
            for (int i = 0; i < GameplayTanks.Length; i++)
            {
                GameplayTanks[i] = new GameplayTank(GenericPlayers[i], positions[i], battlefield.TankVerticalPosition(positions[i]), this);
            }
            Random random = new Random();

            windSpeed = random.Next(-100, 100); //create a wind that will be used to move the shell

            GameplayForm gameForm = new GameplayForm(this);

            gameForm.Show();
        }
예제 #2
0
        /// <summary>
        ///This method is called when it's this player's turn
        ///The player will need to call methods in gameplayForm
        ///such as SelectWeapon(), SetAngle(), SetForce() and finally Launch() to aim and fire the weapon.
        /// </summary>
        public override void NewTurn(GameplayForm gameplayForm, Battle currentGame)
        {
            GameplayTank gameplayTank = currentGame.GetCurrentGameplayTank();

            int numPlayers = currentGame.NumPlayers();
            //for each player find the first player who still exists and aim at them. //There has to be an easier way

            Random random = new Random();
            int    angle  = random.Next(-90, 91);
            int    power  = random.Next(25, 101);

            gameplayForm.SetForce(power);
            gameplayForm.SetAngle(angle);
            gameplayForm.Launch();
        }
예제 #3
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);
            }
        }
예제 #4
0
        /// <summary>
        /// used to handle firing the specified weapon from the tank playerTank.
        /// </summary>
        /// <param name="weapon">The weapon chosen from ListWeapons</param>
        /// <param name="playerTank">The tank that is shooting the weapons</param>
        /// <param name="currentGame">The battle the shot takes place in</param>
        public override void ShootWeapon(int weapon, GameplayTank playerTank, Battle currentGame)
        {
            float x = playerTank.XPos();
            float y = playerTank.GetY();

            //find the center of the tank
            x = x + Chassis.WIDTH / 2;
            y = y + Chassis.HEIGHT / 2;

            GenericPlayer player = playerTank.GetPlayerNumber();
            Boom          boom   = new Boom(100, 4, 4);
            Shell         shell  = new Shell(x, y, playerTank.GetTankAngle(), playerTank.GetTankPower(), 0.01f, boom, player);
            Shell         shell2 = new Shell(x, y, playerTank.GetTankAngle(), playerTank.GetTankPower() + 10, 0.01f, boom, player);
            Shell         shell3 = new Shell(x, y, playerTank.GetTankAngle(), playerTank.GetTankPower() - 10, 0.01f, boom, player);

            currentGame.AddWeaponEffect(shell);
            currentGame.AddWeaponEffect(shell2);
            currentGame.AddWeaponEffect(shell3);
        }
예제 #5
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);
        }
예제 #6
0
        private void NewTurn()
        {
            GameplayTank  tank   = currentGame.GetCurrentGameplayTank();
            GenericPlayer player = tank.GetPlayerNumber();

            //Sets the form caption
            Text = String.Format("Tank Battle - Round {0} of {1}", currentGame.GetCurrentRound(), currentGame.GetRounds());

            controlPanel.BackColor = player.GetColour();

            playerLabel.Text = player.PlayerName();

            SetAngle(tank.GetTankAngle());
            SetForce(tank.GetTankPower());

            int wind = currentGame.WindSpeed();

            if (wind >= 0)
            {
                windLabel.Text = String.Format("{0} E", wind);
            }
            else
            {
                windLabel.Text = String.Format("{0} W", Math.Abs(wind));
            }

            //Remove all the current selectable weapons and replace them with the current tanks weapons.
            weaponSelector.Items.Clear();
            String[] weapons = tank.GetTank().ListWeapons();
            foreach (String weapon in weapons)
            {
                weaponSelector.Items.Add(weapon);
            }
            //tank.SelectWeapon
            SelectWeapon(tank.GetCurrentWeapon());

            player.NewTurn(this, currentGame);
        }
예제 #7
0
        /// <summary>
        /// Begins a new round of gameplay , which consists of multiple turns
        /// </summary>
        public void StartRound()
        {
            int[] positions;

            int    minWindSpeed = -100;
            int    maxWindSPeed = 100;
            Random randomvalue  = new Random();

            currentPlayer  = startingPlayer; // sets the first turn to the starting player
            newBattlefield = new Battlefield();
            positions      = CalcPlayerLocations(Players.Length);

            foreach (GenericPlayer player in Players)
            {
                player.NewRound(); // setup each player for a new round
            }

            RandomReorder(positions);                                                         //shuffle array of positions
            Tanks = new GameplayTank[Players.Length];                                         // set the number of tanks to the number of players

            for (int i = 0; i < Tanks.Length; i++)                                            // initialising Tanks array
            {
                Tanks[i] = new GameplayTank(Players[i],                                       // the player
                                            positions[i],                                     // random Hoz position
                                            newBattlefield.PlaceTankVertically(positions[i]), // cals Vert position
                                            this                                              // reference to this class
                                            );
            }
            windSpeed       = randomvalue.Next(minWindSpeed, maxWindSPeed); // set the current windspeed
            roundBattleForm = new BattleForm(this);
            roundBattleForm.Show();
            // check to see if a player is human
            if (Players[currentPlayer] is PlayerController)
            {
                // activite controls for firing a weapon
                Players[currentPlayer].BeginTurn(roundBattleForm, this);
            }
        }
예제 #8
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);
            }
        }
예제 #9
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);
                }
            }
        }
예제 #10
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);
            }
        }
예제 #11
0
 public abstract void ActivateWeapon(int weapon, GameplayTank playerTank, Battle currentGame);
예제 #12
0
 public abstract void ShootWeapon(int weapon, GameplayTank playerTank, Battle currentGame);