Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Dice
- def initialize(sides)
- @sides = sides
- end
- def throw(times)
- rolls = []
- times.times do |c|
- rolls << rand(@sides) + 1
- end
- rolls
- end
- end
- loop do
- puts "*******************************************************"
- puts "************Select dice and Number of rolls************"
- puts "*******************************************************"
- puts "******************************** type exit to close****"
- print "Sides: "
- sides = gets.chomp.strip
- if sides == "exit" then
- exit = true
- else
- print "Number of Rolls: "
- number = gets.chomp.to_i
- print "Any Modifiers? "
- modifier = gets.chomp.to_i
- rolls = []
- d = Dice.new(sides)
- rolls = d.throw(number)
- puts "Results:"
- total = 0
- rolls.each do |c|
- total = total+c+modifier
- puts "******** #{(c+modifier).to_s}"
- end
- puts "--------------------------"
- puts "Average: #{(total.to_f/rolls.size)}"
- puts "Total: #{total}"
- gets
- end
- break if exit == true
- end
Add Comment
Please, Sign In to add comment