Пример #1
0
        //returns a double array of the number of times each is visited
        public double[] Analyze()
        {
            int[] visits         = new int[40];
            int   playerLocation = 0;
            int   currentLoops   = 1;
            int   totalVisits    = 0;

            double[] percentVisits = new double[40];

            for (int i = 0; i < 40; i++)
            {
                visits[i] = 0;
            }

            for (int i = 0; i < 40; i++)
            {
                percentVisits[i] = 0;
            }

            //loops for number of players
            for (int i = 0; i < players; i++)
            {
                do
                {
                    playerLocation = playerLocation + Roller.RollDice(2);

                    //loop rollover
                    if (playerLocation >= 40)
                    {
                        playerLocation = playerLocation % 40;
                        currentLoops++;
                    }

                    //marks the location as visited
                    visits[playerLocation]++;


                    //go to jail functionality
                    if (playerLocation == 30)
                    {
                        playerLocation = 10;
                        currentLoops++;
                    }
                }while (currentLoops <= 25);
            }
            for (int i = 0; i < 40; i++)
            {
                totalVisits = visits[i] + totalVisits;
            }
            for (int i = 0; i < 40; i++)
            {
                percentVisits[i] = ((double)visits[i] / (double)totalVisits) * (double)100;
            }
            return(percentVisits);
        }
Пример #2
0
        /// <summary>
        /// Кидаем кости для игрока, который находится в тюрьме, чтобы проверить дубли.
        /// </summary>
        private void btnRollDiceJail()
        {
            if (!playerArray[currentPlayer].getInJail())
            {
                return;
            }

            dice.RollDice();

            txtA.Text = dice.getNumber(1).ToString();
            txtB.Text = dice.getNumber(2).ToString();

            if (dice.isDoubles())
            {
                MessageBox.Show("Вы освобождены из тюрьмы!", "Тюрьма", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("Дубля не выпало!", "Тюрьма", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            playerArray[currentPlayer].move(dice.GetTotal(), dice.isDoubles());
        }
Пример #3
0
        private IEnumerator WaitForDiceRoll(System.Action <int> callback)
        {
            // wait for player to press space
            yield return(WaitForKeyPress(KeyCode.Space)); // wait for this function to return

            popUpWindow.SetActive(false);

            // Roll dice after player presses space
            dice.RollDice();
            while (DiceResult.diceNum == -1)
            {
                yield return(new WaitForSeconds(2));
            }

            callback(DiceResult.diceNum); // Use callback to do something with result
        }