Esempio n. 1
0
        private void nextButton_Click(object sender, EventArgs e)
        {
            bool humanPLayer = false; //is human player

            if (human.Checked == true)
            {
                humanPLayer = true;
            }

            //int tankType = int.Parse(tank1.Text); //how to find as a group

            if (playerNumber <= numPlayers)
            {
                if (humanPLayer)
                {
                    GenericPlayer player = new PlayerController(nameBox.Text, Chassis.GetTank(tankType), Battle.PlayerColour(playerNumber));
                    game.RegisterPlayer(playerNumber, player);
                }
                else
                {
                    GenericPlayer player = new ComputerPlayer(nameBox.Text, Chassis.GetTank(tankType), Battle.PlayerColour(playerNumber));
                    game.RegisterPlayer(playerNumber, player);
                }


                if (playerNumber == numPlayers - 1)
                {
                    nextButton.Text = "Done!";
                }
                playerNumber++;
                playerLabel.Text = String.Format("Player #{0}'s name", playerNumber);
                nameBox.Text     = String.Format("Player {0}", playerNumber);
            }
            if (playerNumber > numPlayers)
            {
                Hide();
                game.NewGame();
            }
        }
Esempio n. 2
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();
        }