This is my code for a dice that shows a direction. It shows either north, south, east or west when rolled. I m trying to figure out a way to count how many times each one of these appears anytime I roll the dice.
有人有什么想法吗?
class Dice
#def initialize()
#end
def roll
@dice = Array[ north , south , east , west ] # makes dice with four sides (directions)
@dice_index = 0 + rand(4) # gets the random index of the array
puts @dice[@dice_index] # prints random direction like a dice
end
def stats
puts @dice_index
north_count =0;
south_count =0;
east_count=0;
west_count=0;
end
end
game_dice = Dice.new
game_dice.roll
game_dice.stats