-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasides.rb
More file actions
76 lines (67 loc) · 2 KB
/
Copy pathasides.rb
File metadata and controls
76 lines (67 loc) · 2 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
require_relative 'yesorno.rb'
class Asides
attr_reader :asides
# Creates an empty array to store the dice
def initialize
@asides = []
end
def clear
@asides = []
end
# displays the set-aside dice to the user
def show_asides
puts "Your set aside dice are: "
puts @asides.to_s
end
# determines if user has set-aside dice or not
def has_asides?
if @asides.length > 0
return true
else
return false
end
end
# shoves all dice in the roll into the asides
def hot_dice(roll)
while roll.length > 0
asides << roll.shift
end
end
def ask_user
puts "Would you like to set aside dice, or cash out your points?"
puts "Enter y to set dice aside, or n to cash out"
end
# This method takes in the roll array and the asides
# and sets aside point dice that the user specifies
#
# Outputs: roll array - numbers user sets aside
# asides array + numbers user sets aside
def set_aside(roll)
ans = YesOrNo.new
# prompt user for number to set aside
puts "Pick a 1 or 5 from your roll. Your roll is : "
puts roll.to_s
# add the number to asides, remove from the roll array
put_aside(roll)
# if user still has 1s or 5s and more than 1 die, ask if they'd like to set more aside
if (roll.count(1) > 0 or roll.count(5) > 0) and roll.length > 1
puts "Would you like to set any more numbers aside?"
set_aside(roll) if ans.yes?
end
puts "\n\n"
end
# This method actually sets the dice aside so the user can call
# this from outside the class without having to follow the prompts
# (for testing)
def put_aside(roll)
begin
puts "Enter the number of the point die you'd like to set aside (1 or 5):"
num = gets.to_i
if (num != 1 && num != 5 || roll.count(num) == 0)
puts "You entered a non-point die, or a die you don't have"
end
end while (num != 1 && num != 5 || roll.count(num) == 0)
@asides << num
roll.delete_at(roll.index(num))
end
end