-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdice.rb
More file actions
44 lines (36 loc) · 763 Bytes
/
Copy pathdice.rb
File metadata and controls
44 lines (36 loc) · 763 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
class Dice
attr_reader :dice
# Initial roll is 6 dice because it's at the start of a turn
def initialize
@dice = []
end
# This method randomly rolls n number of dice.
#
# Input: n - number of dice to roll
#
# Output - array of n numbers ranging from 1 to 6
def roll(n)
@dice = (1..n).map { rand(6) + 1 }
end
# outputs the user's roll
def show_dice
puts "Your roll is: "
puts @dice.to_s
end
# Checks if roll has point dice
def has_points?
if @dice.count(1) > 0 || @dice.count(5) > 0
return true
else
return false
end
end
# determines if user has hot dice.
def hot_dice?
if @dice.count(1) + @dice.count(5) == 6
return true
else
return false
end
end
end