Exemplo n.º 1
0
        private void Roll2_Click(object sender, EventArgs e)
        {
            //Clear picture in picture box
            clear();
            //Random dice value
            Random num2         = new Random();
            int    diceQuantity = 0;

            try
            {
                if (tbxDice2.Text.Equals(""))
                {
                    MessageBox.Show("Please enter an number");
                    return;
                }
                else if (Convert.ToInt32(tbxDice2.Text) > 6 || Convert.ToInt32(tbxDice2.Text) == 0)
                {
                    MessageBox.Show("NO MORE THAN SIX DICE OR DICE QUANTITY IS 0");
                    return;
                }
                else
                {
                    //user input dice quantity and define how many element in array
                    diceQuantity = Convert.ToInt32(tbxDice2.Text);
                    dice         = new int[diceQuantity];
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\r\n Please don't input character");
                return;
            }
            //Display turn
            tbxOutput.AppendText("Turn " + turn.ToString() + "\r\n");
            //Declear each element in array
            for (int x = 0; x < dice.Length; x++)
            {
                dice[x] = num2.Next(1, 7);
            }
            //display animation
            DiceAnimation animationDice = new DiceAnimation();

            animationDice.Ainmation(picBoxes, diceQuantity, dice);
            //Reset index of picturebox
            n = 0;
            //Display game result
            tbxOutput.AppendText(player2 + "'s dice values are");
            //Run function to decide result
            ruleGame(player2, player1, dice, ref scorePlayer2, lblplayer2Score, ref player2Winturn, ref player1Winturn, lblplayer2Winturn, lblplayer1Winturn);
            //Record turn
            turn++;
            if (over == true)
            {
                //Change order
                rdPlayer1.Checked = true;
            }
        }
Exemplo n.º 2
0
        //Player1name mean that player who are playing. Player2Name mean that player who are waiting for next turn.
        //winTurn1, winTurn2,lblone and lblTwo are same reason.
        //ref for change value in scorePlayer1 or scorePlayer2
        private void systemPlayer()
        {
            //Delay time of showing picture
            System.Threading.Thread.Sleep(5000);
            //Clear picture in picture box
            clear();
            //Random dice value
            Random num2         = new Random();
            Random quantity     = new Random();
            int    diceQuantity = 0;

            //Decide dice quantity by value of goal
            if (goal > 75)
            {
                //Decide dice quantity by system score
                if (scoreSystem == 0)
                {
                    diceQuantity = 6;
                    dice         = new int[diceQuantity];
                }
                else if (scoreSystem > (goal - 10))
                {
                    diceQuantity = 1;
                    dice         = new int[diceQuantity];
                }
                else if (scoreSystem > (goal / 2))
                {
                    diceQuantity = 4;
                    dice         = new int[diceQuantity];
                }
                else
                {
                    diceQuantity = quantity.Next(4, 6);
                    dice         = new int[diceQuantity];
                }
            }
            else if (goal < 75)
            {
                //Decide dice quantity by system score
                if (scoreSystem == 0)
                {
                    diceQuantity = 4;
                    dice         = new int[diceQuantity];
                }
                else if (scoreSystem > (goal - 10))
                {
                    diceQuantity = 1;
                    dice         = new int[diceQuantity];
                }
                else
                {
                    diceQuantity = quantity.Next(4, 6);
                    dice         = new int[diceQuantity];
                }
            }
            //Display turn
            tbxOutput.AppendText("Turn " + turn.ToString() + "\r\n");
            lblsystemDice.Text = diceQuantity.ToString();
            //Application.DoEvents();
            tbxOutput.AppendText("System running.....\r\n");
            //Slow down to prevent display too fast
            System.Threading.Thread.Sleep(3000);
            //Declear each element in array
            for (int x = 0; x < dice.Length; x++)
            {
                dice[x] = num2.Next(1, 7);
            }
            //Updata information
            Application.DoEvents();
            //Display animation
            DiceAnimation animationDice = new DiceAnimation();

            animationDice.Ainmation(picBoxes, diceQuantity, dice);
            //Display game result
            tbxOutput.AppendText(systemName + " throws " + diceQuantity + " dice(s)\r\n");
            //Slow down to prevent display too fast
            System.Threading.Thread.Sleep(1000);
            tbxOutput.AppendText(systemName + "'s dice values are");
            //Slow down to prevent display too fast
            System.Threading.Thread.Sleep(1000);
            //Run function to decide result
            ruleGame(systemName, player1, dice, ref scoreSystem, lblsystemScore, ref systemWinturn, ref player1Winturn, lblsystemWinturn, lblplayer1Winturn);
            //Reset index
            n = 0;
            //Record turn
            turn++;
            if (over == true)
            {
                //Change order
                rdPlayer1.Checked = true;
            }
        }