Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace rollingDice
- {
- class Dice
- {
- private int _numOfDices;
- private int _numOfRolls;
- Random random = new Random();
- private int _minDices = 1;
- private int _maxDices = 3;
- private int _minRolls = 1;
- private int _maxRolls = 3000000;
- public int NumOfDices
- {
- set
- {
- if (value >= _minDices && value <= _maxDices)
- _numOfDices = value;
- else
- MessageBox.Show("Niste vnesli pravilnega števila kock.");
- }
- get { return _numOfDices; }
- }
- public int NumOfRolls
- {
- set
- {
- if (value >= _minRolls && value <= _maxRolls)
- _numOfRolls = value;
- else
- MessageBox.Show("Niste vnesli pravilnega števila metov");
- }
- get { return _numOfRolls; }
- }
- public Dice()
- {
- _numOfDices = 10;
- _numOfRolls = -1;
- }
- public Dice(int numOfDices, int numOfRolls)
- {
- _numOfDices = numOfDices;
- _numOfRolls = numOfRolls;
- }
- public void SetValues()
- {
- while (_numOfDices > _maxDices || _numOfDices < _minDices)
- {
- Console.WriteLine("How many dices do you want to roll? (enter a number from " + _minDices.ToString() +
- " to " + _maxDices.ToString() + ": ");
- _numOfDices = int.Parse(Console.ReadLine());
- }
- while (_numOfRolls > _maxRolls || _numOfRolls < _minRolls)
- {
- Console.WriteLine("How many times do you want to roll? (enter a number from " + _minRolls.ToString() +
- " to " + _maxRolls.ToString() + ": ");
- _numOfRolls = int.Parse(Console.ReadLine());
- }
- RollDices();
- WriteResults();
- }
- int[] Results;
- public void RollDices()
- {
- Results = new int[_numOfDices * 6];
- for (int i = 0; i < _numOfDices * 6; i++)
- {
- Results[i] = 0;
- }
- for (int i = 0; i < _numOfRolls; i++)
- {
- //popravi
- int x = 0;
- for (int ii = 0; ii < _numOfDices; ii++)
- {
- x += random.Next(1, 7);
- }
- Results[x - 1]++;
- }
- }
- public void WriteResults()
- {
- for (int i = 0; i < _numOfDices * 6; i++)
- {
- float percents = 0f;
- percents = (float)((float)Results[i] / _numOfRolls) * 100;
- Console.WriteLine("[" + (i + 1).ToString() + "]\t" + Results[i] + "\t" + percents.ToString() + "%");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment