burger_game 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +10 -10
- data/Gemfile.lock +60 -60
- data/LICENSE +674 -674
- data/README.md +662 -0
- data/bin/start_burger_game +10 -10
- data/burger_game.gemspec +38 -37
- data/lib/burger_game.rb +200 -198
- data/lib/customer_request.json +171 -171
- data/lib/customer_request.rb +131 -131
- data/lib/customer_response.json +81 -81
- data/lib/game_state.rb +60 -60
- data/lib/player_option.rb +85 -85
- data/lib/recipe.json +34 -34
- data/lib/recipe.rb +73 -73
- data/lib/score_comparison.rb +66 -66
- data/lib/screen_message.rb +170 -170
- data/spec/burger_game_spec.rb +127 -127
- metadata +2 -1
data/bin/start_burger_game
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'burger_game'
|
4
|
-
|
5
|
-
begin
|
6
|
-
BurgerGame.new *ARGV.dup
|
7
|
-
rescue StandardError => e
|
8
|
-
puts "Something went wrong."
|
9
|
-
puts "Error message: " + e.message
|
10
|
-
end
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'burger_game'
|
4
|
+
|
5
|
+
begin
|
6
|
+
BurgerGame.new *ARGV.dup
|
7
|
+
rescue StandardError => e
|
8
|
+
puts "Something went wrong."
|
9
|
+
puts "Error message: " + e.message
|
10
|
+
end
|
data/burger_game.gemspec
CHANGED
@@ -1,37 +1,38 @@
|
|
1
|
-
Gem::Specification.new do |s|
|
2
|
-
s.name = "burger_game"
|
3
|
-
s.version = "1.1.
|
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
|
-
"./
|
16
|
-
"./
|
17
|
-
"./lib/
|
18
|
-
"./lib/
|
19
|
-
"./lib/
|
20
|
-
"./lib/
|
21
|
-
"./lib/
|
22
|
-
"./lib/
|
23
|
-
"./lib/
|
24
|
-
"./lib/
|
25
|
-
"./lib/
|
26
|
-
"./
|
27
|
-
|
28
|
-
s.
|
29
|
-
s.
|
30
|
-
s.
|
31
|
-
s.add_runtime_dependency "
|
32
|
-
s.add_runtime_dependency "
|
33
|
-
s.add_runtime_dependency "
|
34
|
-
s.add_runtime_dependency "
|
35
|
-
s.add_runtime_dependency "
|
36
|
-
s.add_runtime_dependency "tty-
|
37
|
-
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "burger_game"
|
3
|
+
s.version = "1.1.1"
|
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
|
+
"./README.md",
|
16
|
+
"./bin/start_burger_game",
|
17
|
+
"./lib/burger_game.rb",
|
18
|
+
"./lib/customer_request.rb",
|
19
|
+
"./lib/game_state.rb",
|
20
|
+
"./lib/player_option.rb",
|
21
|
+
"./lib/recipe.rb",
|
22
|
+
"./lib/score_comparison.rb",
|
23
|
+
"./lib/screen_message.rb",
|
24
|
+
"./lib/customer_request.json",
|
25
|
+
"./lib/customer_response.json",
|
26
|
+
"./lib/recipe.json",
|
27
|
+
"./spec/burger_game_spec.rb"]
|
28
|
+
s.homepage = "https://rubygems.org/gems/burger_game"
|
29
|
+
s.license = "GPL-3.0"
|
30
|
+
s.required_ruby_version = "~> 2.7"
|
31
|
+
s.add_runtime_dependency "bundler", "~> 2.2"
|
32
|
+
s.add_runtime_dependency "artii", "~> 2.1"
|
33
|
+
s.add_runtime_dependency "colorize", "~> 0.8.1"
|
34
|
+
s.add_runtime_dependency "json", "~> 2.5"
|
35
|
+
s.add_runtime_dependency "rspec", "~> 3.10"
|
36
|
+
s.add_runtime_dependency "tty-box", "~> 0.7.0"
|
37
|
+
s.add_runtime_dependency "tty-prompt", "~> 0.23.1"
|
38
|
+
end
|
data/lib/burger_game.rb
CHANGED
@@ -1,199 +1,201 @@
|
|
1
|
-
# For command line argument
|
2
|
-
require 'optparse'
|
3
|
-
require 'ostruct'
|
4
|
-
|
5
|
-
require_relative './game_state'
|
6
|
-
require_relative './screen_message'
|
7
|
-
require_relative './recipe'
|
8
|
-
require_relative './customer_request'
|
9
|
-
require_relative './player_option'
|
10
|
-
require_relative './score_comparison'
|
11
|
-
|
12
|
-
class BurgerGame
|
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 (Gem's executable): start_burger_game [
|
27
|
-
|
28
|
-
opt.on("-h", "--help", "Print this Help menu for
|
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 }
|
36
|
-
end
|
37
|
-
|
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
|
44
|
-
exit
|
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
|
56
|
-
exit
|
57
|
-
end
|
58
|
-
|
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
|
68
|
-
|
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
|
80
|
-
|
81
|
-
# Ask user if they want to launch the game or exit
|
82
|
-
puts
|
83
|
-
launch_game = player_options.launch_game
|
84
|
-
|
85
|
-
# Exit command line if user select Exit
|
86
|
-
exit if launch_game === false
|
87
|
-
|
88
|
-
# Show welcome message
|
89
|
-
puts
|
90
|
-
puts screen.display_welcome
|
91
|
-
puts
|
92
|
-
screen.go_to_next
|
93
|
-
|
94
|
-
# Feature 1: Options to see instructions or to start the game
|
95
|
-
loop do
|
96
|
-
puts
|
97
|
-
start_game = player_options.start_game
|
98
|
-
|
99
|
-
break if start_game === true
|
100
|
-
|
101
|
-
# Show instructions
|
102
|
-
puts
|
103
|
-
puts screen.display_instructions
|
104
|
-
|
105
|
-
puts
|
106
|
-
screen.go_to_next
|
107
|
-
end
|
108
|
-
|
109
|
-
# Show prologue
|
110
|
-
puts
|
111
|
-
puts screen.display_prologue
|
112
|
-
|
113
|
-
puts
|
114
|
-
screen.go_to_next
|
115
|
-
|
116
|
-
# Loop game until WIN / GAME OVER
|
117
|
-
loop do
|
118
|
-
# Display current money and reputation status
|
119
|
-
puts game_state.display_game_state
|
120
|
-
|
121
|
-
puts
|
122
|
-
screen.go_to_next
|
123
|
-
|
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
|
131
|
-
|
132
|
-
# Loop to display all recipes
|
133
|
-
i = 0
|
134
|
-
loop do
|
135
|
-
puts show_menu.display_recipe(i)
|
136
|
-
|
137
|
-
puts
|
138
|
-
screen.go_to_next
|
139
|
-
|
140
|
-
i += 1
|
141
|
-
break if i > (no_of_recipe - 1)
|
142
|
-
end
|
143
|
-
|
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
|
153
|
-
|
154
|
-
puts
|
155
|
-
screen.go_to_next
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
#
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
puts
|
174
|
-
puts customer
|
175
|
-
|
176
|
-
puts
|
177
|
-
|
178
|
-
puts
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
1
|
+
# For command line argument
|
2
|
+
require 'optparse'
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
require_relative './game_state'
|
6
|
+
require_relative './screen_message'
|
7
|
+
require_relative './recipe'
|
8
|
+
require_relative './customer_request'
|
9
|
+
require_relative './player_option'
|
10
|
+
require_relative './score_comparison'
|
11
|
+
|
12
|
+
class BurgerGame
|
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 (Gem's executable): start_burger_game [OPTION]\nOR\nUsage (bash script - install game): install.sh [OPTION]\nUsage (bash script - run game): burger_game.sh [OPTION]\n\n"
|
27
|
+
|
28
|
+
opt.on("-h", "--help", "Print this Help menu for 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 }
|
36
|
+
end
|
37
|
+
|
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
|
44
|
+
exit
|
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
|
56
|
+
exit
|
57
|
+
end
|
58
|
+
|
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
|
68
|
+
|
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
|
80
|
+
|
81
|
+
# Ask user if they want to launch the game or exit
|
82
|
+
puts
|
83
|
+
launch_game = player_options.launch_game
|
84
|
+
|
85
|
+
# Exit command line if user select Exit
|
86
|
+
exit if launch_game === false
|
87
|
+
|
88
|
+
# Show welcome message
|
89
|
+
puts
|
90
|
+
puts screen.display_welcome
|
91
|
+
puts
|
92
|
+
screen.go_to_next
|
93
|
+
|
94
|
+
# Feature 1: Options to see instructions or to start the game
|
95
|
+
loop do
|
96
|
+
puts
|
97
|
+
start_game = player_options.start_game
|
98
|
+
|
99
|
+
break if start_game === true
|
100
|
+
|
101
|
+
# Show instructions
|
102
|
+
puts
|
103
|
+
puts screen.display_instructions
|
104
|
+
|
105
|
+
puts
|
106
|
+
screen.go_to_next
|
107
|
+
end
|
108
|
+
|
109
|
+
# Show prologue
|
110
|
+
puts
|
111
|
+
puts screen.display_prologue
|
112
|
+
|
113
|
+
puts
|
114
|
+
screen.go_to_next
|
115
|
+
|
116
|
+
# Loop game until WIN / GAME OVER
|
117
|
+
loop do
|
118
|
+
# Display current money and reputation status
|
119
|
+
puts game_state.display_game_state
|
120
|
+
|
121
|
+
puts
|
122
|
+
screen.go_to_next
|
123
|
+
|
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
|
131
|
+
|
132
|
+
# Loop to display all recipes
|
133
|
+
i = 0
|
134
|
+
loop do
|
135
|
+
puts show_menu.display_recipe(i)
|
136
|
+
|
137
|
+
puts
|
138
|
+
screen.go_to_next
|
139
|
+
|
140
|
+
i += 1
|
141
|
+
break if i > (no_of_recipe - 1)
|
142
|
+
end
|
143
|
+
|
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
|
153
|
+
|
154
|
+
puts
|
155
|
+
screen.go_to_next
|
156
|
+
|
157
|
+
ARGV.clear
|
158
|
+
|
159
|
+
# Feature 4: Selectable options for list of ingredients, so no manual entry (typing) is needed.
|
160
|
+
# Quantity input as integer within a pre-set range.
|
161
|
+
# Display player's options
|
162
|
+
player_recipe = player_options.get_selection
|
163
|
+
customer_recipe = customer.get_request(customer_no)
|
164
|
+
|
165
|
+
# Feature 5: Score calculation based on customer's request and preferences compared to player's input
|
166
|
+
# Calculate score
|
167
|
+
compare = ScoreComparison.new(player_recipe, customer_recipe)
|
168
|
+
score = compare.get_score
|
169
|
+
mood = compare.get_mood(score)
|
170
|
+
|
171
|
+
# Feautre 6: Get customers' responses from a JSON file
|
172
|
+
# Display customer's response
|
173
|
+
puts
|
174
|
+
puts "The customer wants to say something..."
|
175
|
+
puts
|
176
|
+
puts customer.display_response(customer_no, mood)
|
177
|
+
|
178
|
+
puts
|
179
|
+
screen.go_to_next
|
180
|
+
puts
|
181
|
+
|
182
|
+
# Update game state
|
183
|
+
compare.calculate_state(mood)
|
184
|
+
|
185
|
+
# Feature 7: Lose/win criteria based on reputation and money
|
186
|
+
# GAME OVER condition
|
187
|
+
if GameState.current_reputation == 0
|
188
|
+
puts screen.display_game_over
|
189
|
+
puts
|
190
|
+
break
|
191
|
+
end
|
192
|
+
|
193
|
+
# WIN condition
|
194
|
+
if GameState.current_money >= GameState.target_money
|
195
|
+
puts screen.display_win
|
196
|
+
puts
|
197
|
+
break
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
199
201
|
end
|