Repository navigation
Expand file tree
/
Copy pathfancycount.rb
More file actions
129 lines (106 loc) · 2.44 KB
/
Copy pathfancycount.rb
File metadata and controls
129 lines (106 loc) · 2.44 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
class Menu
@@kounters = ["Moose", "Multiplier", "Addifier"]
def self.welcome_sequence
puts "You are now using Fancy Count, perfect for your fancy counting needs."
puts "What is your name?"
@@player = gets.chomp
puts ""
puts "Hello, #{@@player}"
selecter_sequence
end
def self.selecter_sequence
puts "---------------"
menu_options
selection
playagain?
end
def self.menu_options
puts "Please choose from one of the following counter options:"
@@kounters.each {|v| puts " #{v}"}
end
def self.selection
@@user_choice = gets.chomp.capitalize
puts ""
if @@kounters.include?(@@user_choice)
puts "You selected the #{@@user_choice} counter!"
case @@user_choice
when "Moose"
Moose.countmenu
when "Multiplier"
Multiplier.countmenu
when "Addifier"
Addifier.countmenu
end
thanker
else
puts "Your selection was not understood."
end
end
def self.countcaller
counter = gets.chomp
counter.countmenu
end
def self.thanker
puts "Thanks for playing, #{@@player}!"
puts ""
end
def self.playagain?
puts "#{@@player}, would you like to play again?"
affirmative = ["Yes", "Y", "yes", "y", "YES"]
answer = gets.chomp
if affirmative.include?(answer)
selecter_sequence
else
puts "Goodbye, #{@@player}!"
end
end
end
class Kounter
end
class Multiplier < Kounter
def self.countmenu
puts "Select your multiplier. Enter a number:"
input = gets.chomp
if input.match(/^[-+]?[0-9]*\.?[0-9]+$/)
puts "Let's count!..."
multiplier = input.to_f
count(multiplier)
else
puts "That was not a valid number."
end
end
def self.count(multiplier)
(1..10).each do |n|
puts "#{n}. #{ n * multiplier.to_f}"
end
end
end
class Moose < Kounter
def self.countmenu
puts "Let's count!..."
count
end
def self.count
(1..10).each {|n| puts " " + n.to_s + " Moose!"}
end
end
class Addifier < Kounter
def self.countmenu
puts "Select your addifier. Enter a number:"
input = gets.chomp
if input.match(/^[-+]?[0-9]*\.?[0-9]+$/)
puts "Let's count!..."
self.count(input.to_f)
else
puts "That was not a valid number."
end
end
def self.count(input)
helpcount = input
(1..10).each do |n|
helpcount = n + helpcount
puts helpcount
end
end
end
Menu.welcome_sequence