-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscore.rb
More file actions
99 lines (88 loc) · 1.84 KB
/
Copy pathscore.rb
File metadata and controls
99 lines (88 loc) · 1.84 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
class Score
attr_accessor :score
# initializes empty variables for usage
def initialize
@score = 0
@counted = []
@roll = []
@die = 0
end
# determines how many of the die are in the roll
def how_many?
@roll.count(@die)
end
# determines if the dice value has been counted yet.
def been_counted?
if @counted.count(@die) > 0
return true
else
@counted << @die
return false
end
end
# checks the value of a dice, for simpler syntax
def is_a?(num)
return @die == num
end
# score a dice with the value of 1
def score_one
if how_many? > 5
@score += 2000
elsif how_many? > 2
@score += 1000 + (how_many?-3)*100
else
@score += how_many?*100
end
end
# score a dice with the value of 5
def score_five
if how_many? > 5
@score += 1000
elsif how_many? > 2
@score += 500 + (how_many?-3)*50
else
@score += how_many?*50
end
end
# score a non-point die
def score_regular
if how_many? > 5
@score += @die*200
elsif how_many? > 2
@score += @die*100
end
end
# This method takes in the roll (6 die array)
# and returns the score of the dice
#
# Inputs: array of 6 numbers
#
# Outputs: score of said array
#
def score_dice(roll)
@score = 0
@roll = roll
# iterate through the roll array
roll.each do |num|
@die = num
# if this number hasn't been counted yet
if !been_counted?
if is_a?(1)
score_one
elsif is_a?(5)
score_five
else
score_regular
end
end
end
# return the score of these dice
@score
# reset the counted numbers
@counted = []
end
# output the score of the current roll to to the user
def show_score
puts "Current score for this roll is: #{@score}"
end
end