示例#1
0
        private void Btn_Exit_Click(object sender, EventArgs e)
        {
            //Exit game function from abstract class
            BikeRaceFunctions bikeRaceFunctions = new BikeRaceFunctions();

            bikeRaceFunctions.ExitGame();
        }
示例#2
0
        private void btnGo_Click(object sender, EventArgs e)
        {
            //Moving all the bikes
            int timeTaken_2 = moveBike(pictureBox2);
            int timeTaken_3 = moveBike(pictureBox3);
            int timeTaken_4 = moveBike(pictureBox4);
            int timeTaken_5 = moveBike(pictureBox5);

            int[] timeArray = { timeTaken_2, timeTaken_3, timeTaken_4, timeTaken_5 };
            int   smallest  = timeTaken_2;

            int i = 0;

            while (i != timeArray.Length)
            {
                if (timeArray[i] < smallest)
                {
                    smallest = timeArray[i];
                }

                i++;
            }


            //Pushing a message box when the race finishes
            switch (Array.IndexOf(timeArray, smallest))
            {
            case 0:
                MessageBox.Show("The Winner is Bike #1", "Race Finished!");
                if (currentBettor.getBike() == 1)
                {
                    currentBettor.declareWinner();
                }
                break;

            case 1:
                MessageBox.Show("The Winner is Bike #2", "Race Finished!");
                if (currentBettor.getBike() == 2)
                {
                    currentBettor.declareWinner();
                }
                break;

            case 2:
                MessageBox.Show("The Winner is Bike #3", "Race Finished!");
                if (currentBettor.getBike() == 3)
                {
                    currentBettor.declareWinner();
                }
                break;

            case 3:
                MessageBox.Show("The Winner is Bike #4", "Race Finished!");
                if (currentBettor.getBike() == 4)
                {
                    currentBettor.declareWinner();
                }
                break;
            }

            //Disbale options to select the current bettor if he has no balance left
            if (currentBettor.totalAmount == 0)
            {
                switch (currentBettor.name)
                {
                case "Roe":
                    radioButton1.Checked = false;
                    radioButton1.Enabled = false;
                    break;

                case "Sam":
                    radioButton2.Checked = false;
                    radioButton2.Enabled = false;
                    break;

                case "Sahil":
                    radioButton3.Checked = false;
                    radioButton3.Enabled = false;
                    break;
                }
            }

            //If the player has 0 balance, he is knocked out, thus remove from the ArrayList
            if (currentBettor.totalAmount == 0)
            {
                allPlayers.Remove(currentBettor);
            }

            //Enable Go Button
            btnGo.Enabled = false;

            //Reposition all the bikes to their initial point
            restorePosition(pictureBox2);
            restorePosition(pictureBox3);
            restorePosition(pictureBox4);
            restorePosition(pictureBox5);

            //Update balance of each player
            player1Balance.Text = p1.totalAmount.ToString();
            player2Balance.Text = p2.totalAmount.ToString();
            player3Balance.Text = p3.totalAmount.ToString();

            //If only one player is left in the ArrayList, he is the winner
            if (allPlayers.Count == 1)
            {
                Player player = (Player)allPlayers[0];
                MessageBox.Show(player.name.ToString() + " wins the game! Click OK to restart.", "Congratulations!");

                //Restart Game function from abstract class
                BikeRaceFunctions bikeRaceFunctions = new BikeRaceFunctions();
                bikeRaceFunctions.RestartGame();
            }
        }