Created
October 11, 2009 22:26
-
-
Save pote/207925 to your computer and use it in GitHub Desktop.
Just a simple Dice throwing app - I plan on adding a Shoes GUI later :)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment