示例#1
0
 /// <summary>
 /// runs when a AI tank hits another tank , storing the power and angle
 /// </summary>
 /// <param name="angle">the angle in which a shot was fired</param>
 /// <param name="power">the amount of power behide the shot fired</param>
 public override void ReportHit(float x, float y)
 {
     // record a fired shot it
     firedShotLandingX.Add(x);
     fireShotLandingY.Add(y);
     // check all players alive in fight and see hit locations matches
     try
     {
         for (int playerNum = 1; playerNum < currentFight.NumPlayers(); playerNum++)
         {
             // check that player is alive and shot didnt hit the tank it came from
             if (!(currentFight.GetPlayerTank() == currentFight.GetBattleTank(playerNum)) &&
                 currentFight.GetBattleTank(playerNum).TankExists())
             {
                 // check X location of player ( give or take -10 or 5 )
                 for (int rangeCheck = 0; rangeCheck < 10; rangeCheck++)
                 {
                     if (currentFight.GetBattleTank(playerNum).GetX() == (int)x + rangeCheck ||
                         currentFight.GetBattleTank(playerNum).GetX() == (int)x - rangeCheck)
                     {
                         this.shotHit.Add(true);
                         break;
                     }
                 }
             }
         }
     }
     catch (IndexOutOfRangeException error)
     {
         MessageBox.Show("Error handling players in AIOpponent.ReportHit");
     }
 }
示例#2
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);
            }
        }
示例#3
0
 /// <summary>
 /// used to work out how to hit the last target if the wind changed
 /// </summary>
 /// <param name="currentGame"></param>
 private void CalForWind(Battle currentGame)
 {
     // retake the shot but check for wind change
     // check to see if the wind is blowing more to east
     if (windOfLastTurn > currentGame.GetWind())
     {
         //check firing angle
         // if angle is positive , bullet will travel farer
         // but if angle is negative the bullet will travel less
         if (currentGame.GetPlayerTank().GetTankAngle() > 0)
         {
             // reduce power to hit tank
             currentGame.GetPlayerTank().SetTankPower((currentGame.GetPlayerTank().GetPower() * 98) / 100);
         }
         else
         {
             // increase power to hit tank
             currentGame.GetPlayerTank().SetTankPower((currentGame.GetPlayerTank().GetPower() * 102) / 100);
         }
     }
     else
     {
         // the wind is blowing more to west
         //check angle
         if (currentGame.GetPlayerTank().GetTankAngle() <= 0)
         {
             // tank is firing with the wind , reduce power
             currentGame.GetPlayerTank().SetTankPower((currentGame.GetPlayerTank().GetPower() * 98) / 100);
         }
         else
         {
             // tank is firing against the wind , increase power
             currentGame.GetPlayerTank().SetTankPower((currentGame.GetPlayerTank().GetPower() * 102) / 100);
         }
     }
 }
示例#4
0
        private int[] CalMinAndMaxAngle(int min, int max, Battle currentGame)
        {
            // check where the tank is , if it close to the edge make sure to fire to the inside of battlfeild
            for (int inrange = 0; inrange < 5; inrange++)
            {
                if (currentGame.GetPlayerTank().GetX() == (Battlefield.WIDTH / currentGame.NumPlayers() / 2 + inrange) ||
                    currentGame.GetPlayerTank().GetX() == (Battlefield.WIDTH / currentGame.NumPlayers() / 2 - inrange))
                {
                    // player is on the left hand side of map , should only shoot to the right
                    min = 1;
                }
                if (currentGame.GetPlayerTank().GetX() == ((Battlefield.WIDTH - (Battlefield.WIDTH / currentGame.NumPlayers()) / 2) + inrange) ||
                    currentGame.GetPlayerTank().GetX() == ((Battlefield.WIDTH - (Battlefield.WIDTH / currentGame.NumPlayers()) / 2) - inrange)
                    )
                {
                    // player is on the right side of map , should only shoot to the left
                    max = -5;
                }
            }
            //check if there are other players to the left
            int playersToLeft = 0;

            for (int playerNum = 1; playerNum <= currentGame.NumPlayers(); playerNum++)
            {
                // check to see if a player is left of current player
                if (currentGame.GetPlayerTank().GetX() > currentGame.GetBattleTank(playerNum).GetX()
                    &&
                    currentGame.GetBattleTank(playerNum).TankExists())
                {
                    //increment to show that a player is to the left
                    playersToLeft++;
                }
            }
            // if no player to left exist set minimun angle to 1
            min = (playersToLeft == 0) ? (1) : (min);
            //check if there are other players to the right
            int playersToRight = 0;

            for (int playerNum = 1; playerNum <= currentGame.NumPlayers(); playerNum++)
            {
                // check to see if a player is right of current player
                if (currentGame.GetPlayerTank().GetX() < currentGame.GetBattleTank(playerNum).GetX()
                    &&
                    currentGame.GetBattleTank(playerNum).TankExists())
                {
                    //increment to show that a player is to the right
                    playersToRight++;
                }
            }
            // if no player to right exist set maximun angle to 1
            max = (playersToRight == 0) ? (-5) : (max);
            return(new int[2] {
                min, max
            });
        }