burger_game 0.1.1 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +10 -0
- data/Gemfile.lock +60 -0
- data/LICENSE +674 -0
- data/bin/start_burger_game +10 -0
- data/burger_game.gemspec +37 -0
- data/lib/burger_game.rb +149 -146
- data/lib/customer_request.json +172 -0
- data/lib/customer_request.rb +9 -2
- data/lib/customer_response.json +82 -0
- data/lib/player_option.rb +3 -3
- data/lib/recipe.json +35 -0
- data/lib/recipe.rb +7 -1
- data/lib/screen_message.rb +52 -20
- data/spec/burger_game_spec.rb +128 -0
- metadata +115 -6
data/burger_game.gemspec
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "burger_game"
|
3
|
+
s.version = "1.0.4"
|
4
|
+
s.summary = "A Ruby Burger Game"
|
5
|
+
s.description = "A simple text-based Ruby terminal game, that simulates a burger shop, where you need to build the meal for the customers with different requests and preferences."
|
6
|
+
s.authors = ["Jessica Gozali"]
|
7
|
+
s.email = "gcas012115@coderacademy.edu.au"
|
8
|
+
s.require_paths = ["lib"]
|
9
|
+
s.bindir = "bin"
|
10
|
+
s.executables = ["start_burger_game"]
|
11
|
+
s.files = ["./burger_game.gemspec",
|
12
|
+
"./Gemfile",
|
13
|
+
"./Gemfile.lock",
|
14
|
+
"./LICENSE",
|
15
|
+
"./bin/start_burger_game",
|
16
|
+
"./lib/burger_game.rb",
|
17
|
+
"./lib/customer_request.rb",
|
18
|
+
"./lib/game_state.rb",
|
19
|
+
"./lib/player_option.rb",
|
20
|
+
"./lib/recipe.rb",
|
21
|
+
"./lib/score_comparison.rb",
|
22
|
+
"./lib/screen_message.rb",
|
23
|
+
"./lib/customer_request.json",
|
24
|
+
"./lib/customer_response.json",
|
25
|
+
"./lib/recipe.json",
|
26
|
+
"./spec/burger_game_spec.rb"]
|
27
|
+
s.homepage = "https://rubygems.org/gems/burger_game"
|
28
|
+
s.license = "GPL-3.0"
|
29
|
+
s.required_ruby_version = "~> 2.7"
|
30
|
+
s.add_runtime_dependency "bundler", "~> 2.2"
|
31
|
+
s.add_runtime_dependency "artii", "~> 2.1"
|
32
|
+
s.add_runtime_dependency "colorize", "~> 0.8.1"
|
33
|
+
s.add_runtime_dependency "json", "~> 2.5"
|
34
|
+
s.add_runtime_dependency "rspec", "~> 3.10"
|
35
|
+
s.add_runtime_dependency "tty-box", "~> 0.7.0"
|
36
|
+
s.add_runtime_dependency "tty-prompt", "~> 0.23.1"
|
37
|
+
end
|
data/lib/burger_game.rb
CHANGED
@@ -10,187 +10,190 @@ require_relative './player_option'
|
|
10
10
|
require_relative './score_comparison'
|
11
11
|
|
12
12
|
class BurgerGame
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
13
|
+
def initialize(*args)
|
14
|
+
# Initialise
|
15
|
+
game_state = GameState.new
|
16
|
+
show_menu = Recipe.new
|
17
|
+
no_of_recipe = Recipe.no_of_recipe
|
18
|
+
screen = ScreenMessage.new
|
19
|
+
player_options = PlayerOption.new
|
20
|
+
customer = CustomerRequest.new
|
21
|
+
no_of_customer = CustomerRequest.no_of_customer
|
22
|
+
options = OpenStruct.new
|
23
|
+
|
24
|
+
# Handle command line argument
|
25
|
+
opt_parser = OptionParser.new do |opt|
|
26
|
+
opt.banner = "Usage: start_burger_game [options]"
|
27
|
+
|
28
|
+
opt.on("-h", "--help", "Print this Help menu for Ruby Burger Game.") do |arg|
|
29
|
+
puts opt
|
30
|
+
exit
|
31
|
+
end
|
32
|
+
|
33
|
+
opt.on("-m", "--money TARGET_MONEY", screen.display_h_money) { |arg| options.target_money = arg }
|
34
|
+
|
35
|
+
opt.on("-r", "--reputation MAX_REPUTATION", screen.display_h_reputation) { |arg| options.max_reputation = arg }
|
29
36
|
end
|
30
37
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
begin
|
38
|
-
opt_parser.parse!
|
39
|
-
rescue OptionParser::InvalidOption => e
|
40
|
-
puts "You have entered an invalid option. Please check the available options in our Help menu '-h' or '--help'."
|
41
|
-
puts e.message
|
42
|
-
exit
|
43
|
-
rescue OptionParser::MissingArgument => e
|
44
|
-
puts "You have not entered the argument for your option."
|
45
|
-
puts e.message
|
46
|
-
exit
|
47
|
-
rescue OptionParser::ParseError => e
|
48
|
-
puts "Error when parsing argument."
|
49
|
-
puts e.message
|
50
|
-
exit
|
51
|
-
rescue => e
|
52
|
-
puts "Something went wrong."
|
53
|
-
puts "Error message: " + e.message
|
54
|
-
exit
|
55
|
-
end
|
56
|
-
|
57
|
-
if (options.target_money)
|
58
|
-
if ((options.target_money.to_i >= 10 ) && (options.target_money.to_i <= 99 ))
|
59
|
-
puts "Change TARGET_MONEY to: $#{options.target_money}.00."
|
60
|
-
# Set target money in GameState
|
61
|
-
game_state.set_target_money(options.target_money.to_f)
|
62
|
-
else
|
63
|
-
puts screen.display_invalid("for TARGET_MONEY.")
|
38
|
+
# ERROR HANDLING for command line argument
|
39
|
+
begin
|
40
|
+
opt_parser.parse!(args)
|
41
|
+
rescue OptionParser::InvalidOption => e
|
42
|
+
puts "You have entered an invalid option. Please check the available options in our Help menu '-h' or '--help'."
|
43
|
+
puts e.message
|
64
44
|
exit
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
puts "
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
puts
|
45
|
+
rescue OptionParser::MissingArgument => e
|
46
|
+
puts "You have not entered the argument for your option."
|
47
|
+
puts e.message
|
48
|
+
exit
|
49
|
+
rescue OptionParser::ParseError => e
|
50
|
+
puts "Error when parsing argument."
|
51
|
+
puts e.message
|
52
|
+
exit
|
53
|
+
rescue => e
|
54
|
+
puts "Something went wrong."
|
55
|
+
puts "Error message: " + e.message
|
75
56
|
exit
|
76
57
|
end
|
77
|
-
end
|
78
58
|
|
79
|
-
|
80
|
-
|
81
|
-
|
59
|
+
if (options.target_money)
|
60
|
+
if ((options.target_money.to_i >= 10 ) && (options.target_money.to_i <= 99 ))
|
61
|
+
puts "Change TARGET_MONEY to: $#{options.target_money}.00."
|
62
|
+
# Set target money in GameState
|
63
|
+
game_state.set_target_money(options.target_money.to_f)
|
64
|
+
else
|
65
|
+
puts screen.display_invalid("for TARGET_MONEY.")
|
66
|
+
exit
|
67
|
+
end
|
82
68
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
69
|
+
end
|
70
|
+
if (options.max_reputation)
|
71
|
+
if ((options.max_reputation.to_i >= 1 ) && (options.max_reputation.to_i <= 10 ))
|
72
|
+
puts "Change MAX_REPUTATION to: #{options.max_reputation}."
|
73
|
+
# Set max reputation in GameState
|
74
|
+
game_state.set_max_reputation(options.max_reputation.to_i)
|
75
|
+
else
|
76
|
+
puts screen.display_invalid("for MAX_REPUTATION.")
|
77
|
+
exit
|
78
|
+
end
|
79
|
+
end
|
91
80
|
|
92
|
-
|
93
|
-
loop do
|
81
|
+
# Ask user if they want to launch the game or exit
|
94
82
|
puts
|
95
|
-
|
96
|
-
|
97
|
-
|
83
|
+
launch_game = player_options.launch_game
|
84
|
+
|
85
|
+
# Exit command line if user select Exit
|
86
|
+
exit if launch_game === false
|
98
87
|
|
99
|
-
# Show
|
88
|
+
# Show welcome message
|
100
89
|
puts
|
101
|
-
puts screen.
|
102
|
-
|
90
|
+
puts screen.display_welcome
|
103
91
|
puts
|
104
92
|
screen.go_to_next
|
105
|
-
end
|
106
93
|
|
107
|
-
|
108
|
-
|
109
|
-
|
94
|
+
# Feature 1: Options to see instructions or to start the game
|
95
|
+
loop do
|
96
|
+
puts
|
97
|
+
start_game = player_options.start_game
|
110
98
|
|
111
|
-
|
112
|
-
screen.go_to_next
|
99
|
+
break if start_game === true
|
113
100
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
101
|
+
# Show instructions
|
102
|
+
puts
|
103
|
+
puts screen.display_instructions
|
104
|
+
|
105
|
+
puts
|
106
|
+
screen.go_to_next
|
107
|
+
end
|
118
108
|
|
109
|
+
# Show prologue
|
119
110
|
puts
|
120
|
-
screen.
|
111
|
+
puts screen.display_prologue
|
121
112
|
|
122
|
-
# Feature 2: Formatted display for showing shop's menu
|
123
|
-
puts
|
124
|
-
puts "Ruby Burger's Menu"
|
125
|
-
puts
|
126
|
-
puts
|
127
|
-
puts "We have #{no_of_recipe} recipes. Try to remember the recipe name, the stack order of ingredients and the quantity. We will build the burger from bottom to top."
|
128
113
|
puts
|
114
|
+
screen.go_to_next
|
129
115
|
|
130
|
-
# Loop
|
131
|
-
i = 0
|
116
|
+
# Loop game until WIN / GAME OVER
|
132
117
|
loop do
|
133
|
-
|
118
|
+
# Display current money and reputation status
|
119
|
+
puts game_state.display_game_state
|
134
120
|
|
135
121
|
puts
|
136
122
|
screen.go_to_next
|
137
123
|
|
138
|
-
|
139
|
-
|
140
|
-
|
124
|
+
# Feature 2: Formatted display for showing shop's menu
|
125
|
+
puts
|
126
|
+
puts "Ruby Burger's Menu"
|
127
|
+
puts
|
128
|
+
puts
|
129
|
+
puts "We have #{no_of_recipe} recipes. Try to remember the recipe name, the stack order of ingredients and the quantity. We will build the burger from bottom to top."
|
130
|
+
puts
|
141
131
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
puts
|
147
|
-
# Randomise customer
|
148
|
-
customer_no = rand(0..9)
|
149
|
-
puts customer.display_request(customer_no)
|
150
|
-
puts
|
132
|
+
# Loop to display all recipes
|
133
|
+
i = 0
|
134
|
+
loop do
|
135
|
+
puts show_menu.display_recipe(i)
|
151
136
|
|
152
|
-
|
153
|
-
|
137
|
+
puts
|
138
|
+
screen.go_to_next
|
154
139
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
player_recipe = player_options.get_options
|
159
|
-
customer_recipe = customer.get_request(customer_no)
|
160
|
-
|
161
|
-
# Feature 5: Score calculation based on customer's request and preferences compared to player's input
|
162
|
-
# Calculate score
|
163
|
-
compare = ScoreComparison.new(player_recipe, customer_recipe)
|
164
|
-
score = compare.get_score
|
165
|
-
mood = compare.get_mood(score)
|
166
|
-
|
167
|
-
# Feautre 6: Get customers' responses from a JSON file
|
168
|
-
# Display customer's response
|
169
|
-
puts
|
170
|
-
puts "The customer wants to say something..."
|
171
|
-
puts
|
172
|
-
puts customer.display_response(customer_no, mood)
|
140
|
+
i += 1
|
141
|
+
break if i > (no_of_recipe - 1)
|
142
|
+
end
|
173
143
|
|
174
|
-
|
175
|
-
|
176
|
-
|
144
|
+
# Feature 3: Randomised customers with set of request (and associated preferences) and responses
|
145
|
+
# Display customer request
|
146
|
+
puts
|
147
|
+
puts "There is a customer in the queue..."
|
148
|
+
puts
|
149
|
+
# Randomise customer
|
150
|
+
customer_no = rand(no_of_customer)
|
151
|
+
puts customer.display_request(customer_no)
|
152
|
+
puts
|
177
153
|
|
178
|
-
|
179
|
-
|
154
|
+
puts
|
155
|
+
screen.go_to_next
|
180
156
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
157
|
+
# Feature 4: Selectable options for list of ingredients, so no manual entry (typing) is needed.
|
158
|
+
# Quantity input as integer within a pre-set range.
|
159
|
+
# Display player's options
|
160
|
+
player_recipe = player_options.get_selection
|
161
|
+
customer_recipe = customer.get_request(customer_no)
|
162
|
+
|
163
|
+
# Feature 5: Score calculation based on customer's request and preferences compared to player's input
|
164
|
+
# Calculate score
|
165
|
+
compare = ScoreComparison.new(player_recipe, customer_recipe)
|
166
|
+
score = compare.get_score
|
167
|
+
mood = compare.get_mood(score)
|
168
|
+
|
169
|
+
# Feautre 6: Get customers' responses from a JSON file
|
170
|
+
# Display customer's response
|
185
171
|
puts
|
186
|
-
|
187
|
-
|
172
|
+
puts "The customer wants to say something..."
|
173
|
+
puts
|
174
|
+
puts customer.display_response(customer_no, mood)
|
188
175
|
|
189
|
-
# WIN condition
|
190
|
-
if GameState.current_money >= GameState.target_money
|
191
|
-
puts screen.display_win
|
192
176
|
puts
|
193
|
-
|
177
|
+
screen.go_to_next
|
178
|
+
puts
|
179
|
+
|
180
|
+
# Update game state
|
181
|
+
compare.calculate_state(mood)
|
182
|
+
|
183
|
+
# Feature 7: Lose/win criteria based on reputation and money
|
184
|
+
# GAME OVER condition
|
185
|
+
if GameState.current_reputation == 0
|
186
|
+
puts screen.display_game_over
|
187
|
+
puts
|
188
|
+
break
|
189
|
+
end
|
190
|
+
|
191
|
+
# WIN condition
|
192
|
+
if GameState.current_money >= GameState.target_money
|
193
|
+
puts screen.display_win
|
194
|
+
puts
|
195
|
+
break
|
196
|
+
end
|
194
197
|
end
|
195
198
|
end
|
196
199
|
end
|
@@ -0,0 +1,172 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
" A Customer ":
|
4
|
+
[
|
5
|
+
{
|
6
|
+
"Normal Burger":
|
7
|
+
[
|
8
|
+
{"Cheese": 0}
|
9
|
+
]
|
10
|
+
},
|
11
|
+
{
|
12
|
+
"Request": "Hello! Can I please have a \"Normal Burger\" today?"
|
13
|
+
},
|
14
|
+
{
|
15
|
+
"Preference": "I don't like cheese, so, with no cheese please!"
|
16
|
+
}
|
17
|
+
]
|
18
|
+
},
|
19
|
+
{
|
20
|
+
" Captain Australia ":
|
21
|
+
[
|
22
|
+
{
|
23
|
+
"Questionable Burger":
|
24
|
+
[
|
25
|
+
{"Grilled Chicken": 5}
|
26
|
+
]
|
27
|
+
},
|
28
|
+
{
|
29
|
+
"Request": "G'day mate! Can I get \"Questionable Burger\" please?"
|
30
|
+
},
|
31
|
+
{
|
32
|
+
"Preference": "I'm so hungry, please put an extra patty in my burger! Ta!"
|
33
|
+
}
|
34
|
+
]
|
35
|
+
},
|
36
|
+
{
|
37
|
+
" John Citizen ":
|
38
|
+
[
|
39
|
+
{
|
40
|
+
"Healthy Burger":
|
41
|
+
[
|
42
|
+
{"Lettuce": 0}
|
43
|
+
]
|
44
|
+
},
|
45
|
+
{
|
46
|
+
"Request": "Hi there. I'm a healthy person you know.\nSo, can I have \"Healthy Burger\" please?"
|
47
|
+
},
|
48
|
+
{
|
49
|
+
"Preference": "And, with no veggies please. Yes, you heard me right, no veggies!"
|
50
|
+
}
|
51
|
+
]
|
52
|
+
},
|
53
|
+
{
|
54
|
+
" Jane Citizen ":
|
55
|
+
[
|
56
|
+
{
|
57
|
+
"Healthy Burger":
|
58
|
+
[
|
59
|
+
{"Grilled Chicken": 0}
|
60
|
+
]
|
61
|
+
},
|
62
|
+
{
|
63
|
+
"Request": "Hi... I'd like to have the \"Healthy Burger\" please."
|
64
|
+
},
|
65
|
+
{
|
66
|
+
"Preference": "I don't want the chicken. It reminds me of John..."
|
67
|
+
}
|
68
|
+
]
|
69
|
+
},
|
70
|
+
{
|
71
|
+
" Scott Morris ":
|
72
|
+
[
|
73
|
+
{
|
74
|
+
"Questionable Burger":
|
75
|
+
[
|
76
|
+
{"Cheese": 5}
|
77
|
+
]
|
78
|
+
},
|
79
|
+
{
|
80
|
+
"Request": "Good day! A quick question, can I have the \"Questionable Burger\" please?"
|
81
|
+
},
|
82
|
+
{
|
83
|
+
"Preference": "With extra two slices of cheese please.\nI hope it is not cheesy. Hahaha! *laughs at own attempt to be funny*"
|
84
|
+
}
|
85
|
+
]
|
86
|
+
},
|
87
|
+
{
|
88
|
+
" The Mighty Princess ":
|
89
|
+
[
|
90
|
+
{
|
91
|
+
"Healthy Burger":
|
92
|
+
[
|
93
|
+
{"Lettuce": 4}
|
94
|
+
]
|
95
|
+
},
|
96
|
+
{
|
97
|
+
"Request": "Oh, tell me dear citizen, can this Princess have the \"Healthy Burger\" please?"
|
98
|
+
},
|
99
|
+
{
|
100
|
+
"Preference": "Make it with extra one lettuce! I will reward you handsomely..."
|
101
|
+
}
|
102
|
+
]
|
103
|
+
},
|
104
|
+
{
|
105
|
+
" Donald T. ":
|
106
|
+
[
|
107
|
+
{
|
108
|
+
"Questionable Burger":
|
109
|
+
[
|
110
|
+
{"Lettuce": 0}
|
111
|
+
]
|
112
|
+
},
|
113
|
+
{
|
114
|
+
"Request": "I'm a busy man. Give the \"Questionable Burger\". Thanks."
|
115
|
+
},
|
116
|
+
{
|
117
|
+
"Preference": "Oh, and I'll have it without lettuce!\nNo lettuce!! *throws fist in the air*"
|
118
|
+
}
|
119
|
+
]
|
120
|
+
},
|
121
|
+
{
|
122
|
+
" Mickey M. ":
|
123
|
+
[
|
124
|
+
{
|
125
|
+
"Healthy Burger":
|
126
|
+
[
|
127
|
+
{"Tomato Sauce": 2}
|
128
|
+
]
|
129
|
+
},
|
130
|
+
{
|
131
|
+
"Request": "Hello... Hmm... I'm interested in trying the \"Healthy Burger\" please..."
|
132
|
+
},
|
133
|
+
{
|
134
|
+
"Preference": "I love tomato, so can I have double the sauce please?"
|
135
|
+
}
|
136
|
+
]
|
137
|
+
},
|
138
|
+
{
|
139
|
+
" Unicorn ":
|
140
|
+
[
|
141
|
+
{
|
142
|
+
"Questionable Burger":
|
143
|
+
[
|
144
|
+
{"Tomato Sauce": 0}
|
145
|
+
]
|
146
|
+
},
|
147
|
+
{
|
148
|
+
"Request": "Hiya! Can I have \"Questionable Burger\" please?"
|
149
|
+
},
|
150
|
+
{
|
151
|
+
"Preference": "Leave the tomato sauce out please.\nIt will ruin the colour balance of my rainbow."
|
152
|
+
}
|
153
|
+
]
|
154
|
+
},
|
155
|
+
{
|
156
|
+
" A Robot ":
|
157
|
+
[
|
158
|
+
{
|
159
|
+
"Normal Burger":
|
160
|
+
[
|
161
|
+
{"Grilled Chicken": 3}
|
162
|
+
]
|
163
|
+
},
|
164
|
+
{
|
165
|
+
"Request": "Beep... Can I have the.. Beep... \"Normal Burger\" please?"
|
166
|
+
},
|
167
|
+
{
|
168
|
+
"Preference": "Beep... With triple... Beep... Patty please..."
|
169
|
+
}
|
170
|
+
]
|
171
|
+
}
|
172
|
+
]
|