Example #1
0
        private void selectToRoll2(int iToRoll, int[] iDieRollArray, int[] iDieNumArray, Die dDie1, Die dDie2, Die dDie3, Button btnKeepDie1, Button btnKeepDie2, Button btnKeepDie3)
        {
            //If 2 dice are in sequence this method selects the die to roll and dice to keep

            int i;          // Used as a counter
            int iStart;     // Where to start looping from in the array
            int iStop;      // Where to stop looping in the array

            // Determine where to start/stop looping in the array depending on iToRoll value
            if (iToRoll == 2)
            {
                iStart = 0;
                iStop  = 1;
            }
            else
            {
                iStart = 1;
                iStop  = 2;
            }

            //Select the die to keep
            for (i = iStart; i <= iStop; i++)
            {
                if (iDieNumArray[i] == 1 && !dDie1.bDieKept)
                {
                    btnKeepDie1.PerformClick();
                }
                else if (iDieNumArray[i] == 2 && !dDie2.bDieKept)
                {
                    btnKeepDie2.PerformClick();
                }
                else if (iDieNumArray[i] == 3 && !dDie3.bDieKept)
                {
                    btnKeepDie3.PerformClick();
                }
            }

            //Select the die to roll
            if (iDieNumArray[iToRoll] == 1 && dDie1.bDieKept)
            {
                btnKeepDie1.PerformClick();
            }
            else if (iDieNumArray[iToRoll] == 2 && dDie2.bDieKept)
            {
                btnKeepDie2.PerformClick();
            }
            else if (iDieNumArray[iToRoll] == 3 && dDie3.bDieKept)
            {
                btnKeepDie3.PerformClick();
            }
        }
Example #2
0
        public void playRound(Button btnRoll, Button btnP2EndRound, Button btnKeepDie1, Button btnKeepDie2,
                              Button btnKeepDie3, Die dDie1, Die dDie2, Die dDie3, int iRound, Random rComp, ProgressBar pRoundProgress,
                              Label lblComputerProgress, GroupBox gbxGameOptions)
        {
            // The main method that plays a round for the program.
            // Uses a strategy that Jacobus and Francois created to play Lurgit with the highest chance of winning.
            // The program aims to roll as many sequence bonuses as possible in rounds 1 - 4.
            // In rounds 5 & 6 the program simply aims to roll the scoring number on all 3 dice.

            int  iWait;                 // Used to specify how long the program should wait between turns
            bool bEndRound = false;     // Used to determine when to end the round for the program

            gbxGameOptions.Enabled      = false;
            lblComputerProgress.Visible = true;
            pRoundProgress.Visible      = true;
            lblComputerProgress.Text    = "Computer Round Progress: Taking turn 1";
            pRoundProgress.Value        = 1;

            Application.DoEvents();

            System.Threading.Thread.Sleep(500);

            // On the first roll simply press the roll button to roll all 3 dice
            btnRoll.PerformClick();

            // Before the second turn determine dice to keep
            if (iRound <= 4) // If the round is 1 - 4 try for a sequence bonus
            {
                bEndRound = rollForSequence(dDie1, dDie2, dDie3, btnKeepDie1, btnKeepDie2, btnKeepDie3, btnRoll, iRound);
            }
            else    // If the round is 5 or 6 try for scoring number
            {
                bEndRound = rollForScore(dDie1, dDie2, dDie3, btnKeepDie1, btnKeepDie2, btnKeepDie3, btnRoll, iRound);
            }

            lblComputerProgress.Text = "Computer Round Progress: Taking turn 2";
            pRoundProgress.Value     = 2;

            Application.DoEvents();

            // If the program decides to roll again, roll the dice for turn 2
            if (bEndRound)
            {
                endRound(lblComputerProgress, pRoundProgress, btnP2EndRound, gbxGameOptions);
            }
            else
            {
                iWait = rComp.Next(1500, 2000);
                System.Threading.Thread.Sleep(iWait);
                btnRoll.PerformClick();
            }

            // Before the third turn determine dice to keep
            if (iRound <= 4)
            {
                bEndRound = rollForSequence(dDie1, dDie2, dDie3, btnKeepDie1, btnKeepDie2, btnKeepDie3, btnRoll, iRound);
            }
            else
            {
                bEndRound = rollForScore(dDie1, dDie2, dDie3, btnKeepDie1, btnKeepDie2, btnKeepDie3, btnRoll, iRound);
            }

            lblComputerProgress.Text = "Computer Round Progress: Taking turn 3";
            pRoundProgress.Value     = 3;

            Application.DoEvents();

            // If the program decides to roll again, roll the dice for turn 3
            if (bEndRound)
            {
                endRound(lblComputerProgress, pRoundProgress, btnP2EndRound, gbxGameOptions);
            }
            else
            {
                iWait = rComp.Next(1500, 2000);
                System.Threading.Thread.Sleep(iWait);
                btnRoll.PerformClick();
            }

            // End the program's round after all turns have been taken
            endRound(lblComputerProgress, pRoundProgress, btnP2EndRound, gbxGameOptions);
        }