daily pastebin goal
3%
SHARE
TWEET

Untitled

a guest Mar 13th, 2018 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Dice
  2.  
  3.   def initialize(sides)
  4.     @sides = sides
  5.   end
  6.  
  7.   def throw(times)
  8.     rolls = []
  9.     times.times do |c|
  10.       rolls << rand(@sides) + 1
  11.     end
  12.     rolls
  13.   end
  14. end
  15.  
  16. loop do
  17.   puts "*******************************************************"
  18.   puts "************Select dice and Number of rolls************"
  19.   puts "*******************************************************"
  20.   puts "******************************** type exit to close****"
  21.   print "Sides: "
  22.   sides = gets.chomp.strip
  23.   if sides == "exit" then
  24.     exit = true
  25.   else
  26.     print "Number of Rolls: "
  27.     number = gets.chomp.to_i
  28.     print "Any Modifiers? "
  29.     modifier = gets.chomp.to_i
  30.     rolls = []
  31.     d = Dice.new(sides)  
  32.     rolls = d.throw(number)
  33.     puts "Results:"
  34.     total = 0
  35.     rolls.each do |c|
  36.       total = total+c+modifier
  37.       puts "******** #{(c+modifier).to_s}"
  38.     end
  39.     puts "--------------------------"
  40.     puts "Average: #{(total.to_f/rolls.size)}"
  41.     puts "Total: #{total}"
  42.     gets
  43.   end
  44.   break if exit == true
  45. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top