From: Martin DeMello Date: 2011-01-24T01:12:23+09:00 Subject: Re: Help! Please, I'm lost! On Sun, Jan 23, 2011 at 9:15 PM, Dark Haukka > > The answer well explained for a newbie, plz. Thanks. Here you go. We make a class to represent a die, with methods to roll it and display the top face. # -------------------------------------------------------------------- # represent a die class Die FACES = [-1, -1, 0, 0, 1, 1] # we will let the value be read, but not written to attr_reader :value def initialize # to begin with the die has not been rolled, and # hence has no value @value = nil end # set the value to a random face def roll r = rand(6) @value = FACES[r] end # return the face value of the die as a string def display_value case @value when -1; "-" when 0; "0" when 1; "+" else "NOT ROLLED!" end end end # play the game # loop until a valid number is entered n = 0 while true do puts "How many dice do you want to roll?" number = gets n = number.to_i # convert string to integer if n > 0 break end end # this creates an array of n Die objects dice = Array.new(n) { Die.new } # roll the dice dice.each {|die| die.roll} # display and total the dice total = 0 dice.each_with_index do |die, i| total += die.value puts "Die number #{i} shows: #{die.display_value}" end puts puts "Your total score is #{total}"