Guest User

Untitled

a guest
May 17th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.08 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows.Forms;
  6.  
  7. namespace rollingDice
  8. {
  9.     class Dice
  10.     {
  11.  
  12.         private int _numOfDices;
  13.         private int _numOfRolls;
  14.  
  15.         Random random = new Random();
  16.  
  17.         private int _minDices = 1;
  18.         private int _maxDices = 3;
  19.         private int _minRolls = 1;
  20.         private int _maxRolls = 3000000;
  21.  
  22.  
  23.  
  24.         public int NumOfDices
  25.         {
  26.             set
  27.             {
  28.                 if (value >= _minDices && value <= _maxDices)
  29.                     _numOfDices = value;
  30.                 else
  31.                     MessageBox.Show("Niste vnesli pravilnega števila kock.");
  32.             }
  33.             get { return _numOfDices; }
  34.         }
  35.  
  36.         public int NumOfRolls
  37.         {
  38.             set
  39.             {
  40.                 if (value >= _minRolls && value <= _maxRolls)
  41.                     _numOfRolls = value;
  42.                 else
  43.                     MessageBox.Show("Niste vnesli pravilnega števila metov");
  44.             }
  45.             get { return _numOfRolls; }
  46.         }
  47.  
  48.         public Dice()
  49.         {
  50.             _numOfDices = 10;
  51.             _numOfRolls = -1;
  52.         }
  53.  
  54.         public Dice(int numOfDices, int numOfRolls)
  55.         {
  56.             _numOfDices = numOfDices;
  57.             _numOfRolls = numOfRolls;
  58.         }
  59.  
  60.         public void SetValues()
  61.         {
  62.             while (_numOfDices > _maxDices || _numOfDices < _minDices)
  63.             {
  64.                 Console.WriteLine("How many dices do you want to roll? (enter a number from " + _minDices.ToString() +
  65.                 " to " + _maxDices.ToString() + ": ");
  66.                 _numOfDices = int.Parse(Console.ReadLine());
  67.             }
  68.  
  69.  
  70.             while (_numOfRolls > _maxRolls || _numOfRolls < _minRolls)
  71.             {
  72.                 Console.WriteLine("How many times do you want to roll? (enter a number from " + _minRolls.ToString() +
  73.                 " to " + _maxRolls.ToString() + ": ");
  74.                 _numOfRolls = int.Parse(Console.ReadLine());
  75.             }
  76.  
  77.             RollDices();
  78.             WriteResults();
  79.         }
  80.         int[] Results;
  81.         public void RollDices()
  82.         {
  83.             Results = new int[_numOfDices * 6];
  84.  
  85.             for (int i = 0; i < _numOfDices * 6; i++)
  86.             {
  87.                 Results[i] = 0;
  88.             }
  89.  
  90.             for (int i = 0; i < _numOfRolls; i++)
  91.             {
  92.                 //popravi
  93.                 int x = 0;
  94.                 for (int ii = 0; ii < _numOfDices; ii++)
  95.                 {
  96.                     x += random.Next(1, 7);
  97.                 }
  98.                 Results[x - 1]++;
  99.             }
  100.         }
  101.  
  102.         public void WriteResults()
  103.         {
  104.             for (int i = 0; i < _numOfDices * 6; i++)
  105.             {
  106.                 float percents = 0f;
  107.                 percents = (float)((float)Results[i] / _numOfRolls) * 100;
  108.                 Console.WriteLine("[" + (i + 1).ToString() + "]\t" + Results[i] + "\t" + percents.ToString() + "%");
  109.             }
  110.         }
  111.  
  112.  
  113.     }
  114. }
Add Comment
Please, Sign In to add comment