//public Opponent[] players;

        private void nextPlayerButton_Click(object sender, EventArgs e)
        {
            //setupGame = new SetupGameForm();

            //playerAmount = setupGame.getPlayerAmount();
            //roundAmount = setupGame.getRoundAmount();

            //game = new Gameplay(playerAmount, roundAmount);

            //players = new Opponent[setupGame.playerAmount];

            //for (int i = 0; i < players.Length; i++) {
            //    players[i] = new HumanOpponent("Player " + i, TankModel.GetTank(1), Gameplay.GetTankColour(1));
            //}

            //for (int i = 0; i < players.Length; i++) {
            //    game.SetPlayer(i + 1, players[i]);
            //}

            game = new Gameplay(2, 1);

            Opponent player1 = new HumanOpponent("Player 1", TankModel.GetTank(1), Gameplay.GetTankColour(1));
            Opponent player2 = new HumanOpponent("Player 2", TankModel.GetTank(1), Gameplay.GetTankColour(2));

            game.SetPlayer(1, player1);
            game.SetPlayer(2, player2);

            game.NewGame();
        }
 /// <summary>
 /// Changes the players in the array playersArray so that they are either playercontrolled or AIControlled
 /// Checks the AI or Human button checked with playerNameBox
 /// Author Greyden Scott & Sean O'Connell October 2017
 /// Written, edited and tested by both team members
 /// </summary>
 private void nextPlayerButton_Click_1(object sender, EventArgs e)
 {
     if (AIRButton.Checked)
     {
         //Create player with AIController
         playersArray[whichPlayer] = new AIPlayer(playerNameBox.Text, TankModel.GetTank(1), Gameplay.GetColour(whichPlayer + 1));
     }
     else
     {
         //Create player with PlayerController
         playersArray[whichPlayer] = new PlayerController(playerNameBox.Text, TankModel.GetTank(1), Gameplay.GetColour(whichPlayer + 1));
     }
     this.Close();
 }
        /// <summary>
        ///
        /// When this button is pressed, the next player can select their
        /// name, tank and controller. When all players have selected their loadouts
        /// the game will begin.
        ///
        /// Author John Santias and Hoang Nguyen October 2017
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void nextPlayerButton_Click(object sender, EventArgs e)
        {
            playerNames.Add(playerNameInput.Text);
            if (humanRadioButton.Checked)
            {
                humans[player - 1] = "human";
            }
            else if (aiRadioButton.Checked)
            {
                AIs[player - 1] = "Ai";
            }

            // If not all players have not assign player name, tank types and controller
            if (player != playerAmount)
            {
                player++;
                PlayerLabel.Text     = "Player #" + player + "'s name:";
                playerNameInput.Text = "Player " + player;
                BackColor            = Gameplay.GetTankColour(player);

                // If all players have put in their details, game starts
            }
            else if (player == playerAmount)
            {
                Gameplay game = new Gameplay(playerAmount, roundAmount);

                //create human players
                for (int i = 0; i < playerAmount; i++)
                {
                    if (humans[i] == "human")
                    {
                        Opponent a = new HumanOpponent(playerNames[i], TankModel.GetTank(1), Gameplay.GetTankColour(i + 1));
                        game.SetPlayer(i + 1, a);
                    }
                    else if (AIs[i] == "Ai")
                    {
                        Opponent a = new AIOpponent(playerNames[i], TankModel.GetTank(1), Gameplay.GetTankColour(i + 1));
                        game.SetPlayer(i + 1, a);
                    }
                }
                game.NewGame();
                Close();
            }
        }
Beispiel #4
0
        /// <summary>
        /// used to move to the next player
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void NextPlayer_Click(object sender, EventArgs e)
        {
            string playerName;
            int    tankChoice = 1;

            //check that a choice has been made for both controller and tank
            if (!(humanChoice.Checked || computerChoice.Checked))
            {
                MessageBox.Show("Looks like you haven't setup a controller for this player \n please choose either human or computer");
                return;
            }
            if (!(basicTank.Checked || HeavyTank.Checked || quickFireTank.Checked || armoredTank.Checked))
            {
                MessageBox.Show("Looks like you haven't setup a tank for this player \n please select one to continue");
                return;
            }
            //find the choice of tank for this player
            if (basicTank.Checked)
            {
                tankChoice = 1;
            }
            if (quickFireTank.Checked)
            {
                tankChoice = 2;
            }
            if (HeavyTank.Checked)
            {
                tankChoice = 3;
            }
            if (armoredTank.Checked)
            {
                tankChoice = 4;
            }
            //stub more choices to come for future references

            //find the player's name
            if (inputtedName.Text == "")
            {
                // if no name inputted then go to basic name
                playerName = string.Format("Player {0}", setupPlayers + 1);
            }
            else
            {
                //if name inputted then set player to that name
                playerName = inputtedName.Text;
            }

            // add player to array of GenericPlayers
            if (humanChoice.Checked)
            {
                // Human player made
                Players[setupPlayers] = new PlayerController(playerName, TankModel.GetTank(tankChoice), Battle.TankColour(setupPlayers + 1));
            }
            if (computerChoice.Checked)
            {
                Players[setupPlayers] = new AIOpponent(playerName, TankModel.GetTank(tankChoice), Battle.TankColour(setupPlayers + 1));
            }

            // add entry of new player into the game
            currentBattle.SetPlayer(setupPlayers + 1, Players[setupPlayers]);

            // now move to the next player to setup

            setupPlayers++;

            //check to see if the next player is the last player
            if (setupPlayers + 1 == totalPlayers)
            {
                //change the nextplayer text to show that it will start the game on next click
                NextPlayer.Text      = "Start Game!!!";
                NextPlayer.ForeColor = Color.Red;
            }
            //check to see if all players are setup
            if (setupPlayers == totalPlayers)
            {
                //start the game
                currentBattle.NewGame();
                this.Dispose();
                return;
            }

            //reset for next player
            Reset();
        }