示例#1
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
            });
        }
示例#2
0
        public Winner(Battle game)
        {
            InitializeComponent();
            int    highscore = 0;
            String winner    = "";

            //for every player in the battle find out their score
            GenericPlayer[] genericPlayers = new GenericPlayer[game.NumPlayers()];

            for (int i = 0; i < genericPlayers.Length; i++)
            {
                GenericPlayer gp = game.GetPlayerNumber(i + 1);
                if (gp.GetScore() > highscore)
                {
                    highscore = gp.GetScore();
                    winner    = String.Format("{0} won!", gp.PlayerName());
                }
                else if (gp.GetScore() == highscore)
                {
                    winner = "Tie!";
                }
                playerWon.Text = winner;
                listBox.Items.Add(String.Format("{0} ({1} Wins)", gp.PlayerName(), gp.GetScore()));
            }
        }
示例#3
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");
     }
 }
示例#4
0
 /// <summary>
 /// shows a scoreboard to the player , before continuing or ending the fight.
 /// </summary>
 /// <param name="currentGame"></param>
 public Scoreboard(Battle currentGame)
 {
     InitializeComponent();       // make form
     continueFight = currentGame; // store game
     scores        = new int[continueFight.NumPlayers()];
     names         = new string[continueFight.NumPlayers()];
     for (int i = 1; i <= continueFight.NumPlayers(); i++)
     {
         scores[i - 1] = continueFight.GetPlayerNumber(i).GetVictories(); // gets the score of a player
         names[i - 1]  = continueFight.GetPlayerNumber(i).Name();         // gets the player's name
         // add each entry into a textbox
         playerScores.Items.Add(string.Format("{0} current score is {1}\n", names[i - 1], scores[i - 1]));
         // check if player has highest score
         if (scores[i - 1] > leader)
         {
             // set highscore to players score
             leaderIndex = i - 1;         // get players name index
             leader      = scores[i - 1]; // get their score for testing
         }
     }
     // set label to show leader of battle
     currentLeader.Text = string.Format("{0}", names[leaderIndex]);
 }
示例#5
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();
        }
示例#6
0
 public GameSetupForm(Battle game)
 {
     this.game  = game;
     numPlayers = game.NumPlayers();
     InitializeComponent();
 }