burger_game 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +60 -60
- data/bin/start_burger_game +10 -0
- data/burger_game.gemspec +7 -5
- data/lib/burger_game.rb +199 -0
- data/lib/customer_request.rb +2 -2
- data/lib/recipe.rb +1 -1
- data/spec/burger_game_spec.rb +1 -1
- metadata +7 -5
- data/burger_game.rb +0 -197
- data/burger_game.sh +0 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9d52a5d94f7d1b56618795a6b30f53a47bfbabd544ac77c16d43624c5e441287
|
|
4
|
+
data.tar.gz: 49f4a85966a80fb77d136e8efb9c06c142f9ea2a40ee5483f757017013a56dd6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 189aef2ffb2ac2c53c8d6bb3c779e43950716eb45358212ad6b22ebbddbfc83c820f24f7b3b376c1282ee20b06180f27eb4d3a37ff02f9a12c31d196485ee665
|
|
7
|
+
data.tar.gz: cb00f3947dbf5b1c98dab783c2dfa445d55b8c5d87b656b35401e3b66b19726782e1cdadd867d04fdb3c5ca5199b86845f1038566cc4109f7f6327e432f7441f
|
data/Gemfile.lock
CHANGED
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
GEM
|
|
2
|
-
remote: https://rubygems.org/
|
|
3
|
-
specs:
|
|
4
|
-
artii (2.1.2)
|
|
5
|
-
colorize (0.8.1)
|
|
6
|
-
diff-lcs (1.4.4)
|
|
7
|
-
json (2.5.1)
|
|
8
|
-
pastel (0.8.0)
|
|
9
|
-
tty-color (~> 0.5)
|
|
10
|
-
rspec (3.10.0)
|
|
11
|
-
rspec-core (~> 3.10.0)
|
|
12
|
-
rspec-expectations (~> 3.10.0)
|
|
13
|
-
rspec-mocks (~> 3.10.0)
|
|
14
|
-
rspec-core (3.10.1)
|
|
15
|
-
rspec-support (~> 3.10.0)
|
|
16
|
-
rspec-expectations (3.10.1)
|
|
17
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
|
18
|
-
rspec-support (~> 3.10.0)
|
|
19
|
-
rspec-mocks (3.10.2)
|
|
20
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
|
21
|
-
rspec-support (~> 3.10.0)
|
|
22
|
-
rspec-support (3.10.2)
|
|
23
|
-
strings (0.2.1)
|
|
24
|
-
strings-ansi (~> 0.2)
|
|
25
|
-
unicode-display_width (>= 1.5, < 3.0)
|
|
26
|
-
unicode_utils (~> 1.4)
|
|
27
|
-
strings-ansi (0.2.0)
|
|
28
|
-
tty-box (0.7.0)
|
|
29
|
-
pastel (~> 0.8)
|
|
30
|
-
strings (~> 0.2.0)
|
|
31
|
-
tty-cursor (~> 0.7)
|
|
32
|
-
tty-color (0.6.0)
|
|
33
|
-
tty-cursor (0.7.1)
|
|
34
|
-
tty-prompt (0.23.1)
|
|
35
|
-
pastel (~> 0.8)
|
|
36
|
-
tty-reader (~> 0.8)
|
|
37
|
-
tty-reader (0.9.0)
|
|
38
|
-
tty-cursor (~> 0.7)
|
|
39
|
-
tty-screen (~> 0.8)
|
|
40
|
-
wisper (~> 2.0)
|
|
41
|
-
tty-screen (0.8.1)
|
|
42
|
-
unicode-display_width (2.0.0)
|
|
43
|
-
unicode_utils (1.4.0)
|
|
44
|
-
wisper (2.0.1)
|
|
45
|
-
|
|
46
|
-
PLATFORMS
|
|
47
|
-
ruby
|
|
48
|
-
x64-mingw32
|
|
49
|
-
x86_64-linux
|
|
50
|
-
|
|
51
|
-
DEPENDENCIES
|
|
52
|
-
artii (~> 2.1)
|
|
53
|
-
colorize (~> 0.8.1)
|
|
54
|
-
json (~> 2.5)
|
|
55
|
-
rspec (~> 3.10)
|
|
56
|
-
tty-box (~> 0.7.0)
|
|
57
|
-
tty-prompt (~> 0.23.1)
|
|
58
|
-
|
|
59
|
-
BUNDLED WITH
|
|
60
|
-
2.2.17
|
|
1
|
+
GEM
|
|
2
|
+
remote: https://rubygems.org/
|
|
3
|
+
specs:
|
|
4
|
+
artii (2.1.2)
|
|
5
|
+
colorize (0.8.1)
|
|
6
|
+
diff-lcs (1.4.4)
|
|
7
|
+
json (2.5.1)
|
|
8
|
+
pastel (0.8.0)
|
|
9
|
+
tty-color (~> 0.5)
|
|
10
|
+
rspec (3.10.0)
|
|
11
|
+
rspec-core (~> 3.10.0)
|
|
12
|
+
rspec-expectations (~> 3.10.0)
|
|
13
|
+
rspec-mocks (~> 3.10.0)
|
|
14
|
+
rspec-core (3.10.1)
|
|
15
|
+
rspec-support (~> 3.10.0)
|
|
16
|
+
rspec-expectations (3.10.1)
|
|
17
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
18
|
+
rspec-support (~> 3.10.0)
|
|
19
|
+
rspec-mocks (3.10.2)
|
|
20
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
21
|
+
rspec-support (~> 3.10.0)
|
|
22
|
+
rspec-support (3.10.2)
|
|
23
|
+
strings (0.2.1)
|
|
24
|
+
strings-ansi (~> 0.2)
|
|
25
|
+
unicode-display_width (>= 1.5, < 3.0)
|
|
26
|
+
unicode_utils (~> 1.4)
|
|
27
|
+
strings-ansi (0.2.0)
|
|
28
|
+
tty-box (0.7.0)
|
|
29
|
+
pastel (~> 0.8)
|
|
30
|
+
strings (~> 0.2.0)
|
|
31
|
+
tty-cursor (~> 0.7)
|
|
32
|
+
tty-color (0.6.0)
|
|
33
|
+
tty-cursor (0.7.1)
|
|
34
|
+
tty-prompt (0.23.1)
|
|
35
|
+
pastel (~> 0.8)
|
|
36
|
+
tty-reader (~> 0.8)
|
|
37
|
+
tty-reader (0.9.0)
|
|
38
|
+
tty-cursor (~> 0.7)
|
|
39
|
+
tty-screen (~> 0.8)
|
|
40
|
+
wisper (~> 2.0)
|
|
41
|
+
tty-screen (0.8.1)
|
|
42
|
+
unicode-display_width (2.0.0)
|
|
43
|
+
unicode_utils (1.4.0)
|
|
44
|
+
wisper (2.0.1)
|
|
45
|
+
|
|
46
|
+
PLATFORMS
|
|
47
|
+
ruby
|
|
48
|
+
x64-mingw32
|
|
49
|
+
x86_64-linux
|
|
50
|
+
|
|
51
|
+
DEPENDENCIES
|
|
52
|
+
artii (~> 2.1)
|
|
53
|
+
colorize (~> 0.8.1)
|
|
54
|
+
json (~> 2.5)
|
|
55
|
+
rspec (~> 3.10)
|
|
56
|
+
tty-box (~> 0.7.0)
|
|
57
|
+
tty-prompt (~> 0.23.1)
|
|
58
|
+
|
|
59
|
+
BUNDLED WITH
|
|
60
|
+
2.2.17
|
data/burger_game.gemspec
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
Gem::Specification.new do |s|
|
|
2
2
|
s.name = "burger_game"
|
|
3
|
-
s.version = "1.0.
|
|
3
|
+
s.version = "1.0.2"
|
|
4
4
|
s.summary = "A Ruby Burger Game"
|
|
5
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
6
|
s.authors = ["Jessica Gozali"]
|
|
7
7
|
s.email = "gcas012115@coderacademy.edu.au"
|
|
8
8
|
s.require_paths = ["lib"]
|
|
9
|
+
s.bindir = "bin"
|
|
10
|
+
s.executables = ["start_burger_game"]
|
|
9
11
|
s.files = ["./burger_game.gemspec",
|
|
10
|
-
"./burger_game.rb",
|
|
11
|
-
"./burger_game.sh",
|
|
12
12
|
"./Gemfile",
|
|
13
13
|
"./Gemfile.lock",
|
|
14
14
|
"./LICENSE",
|
|
15
|
-
"./
|
|
15
|
+
"./bin/start_burger_game",
|
|
16
|
+
"./lib/burger_game.rb",
|
|
16
17
|
"./lib/customer_request.rb",
|
|
17
18
|
"./lib/game_state.rb",
|
|
18
19
|
"./lib/player_option.rb",
|
|
@@ -21,7 +22,8 @@ Gem::Specification.new do |s|
|
|
|
21
22
|
"./lib/screen_message.rb",
|
|
22
23
|
"./lib/data/customer_request.json",
|
|
23
24
|
"./lib/data/customer_response.json",
|
|
24
|
-
"./lib/data/recipe.json"
|
|
25
|
+
"./lib/data/recipe.json",
|
|
26
|
+
"./spec/burger_game_spec.rb"]
|
|
25
27
|
s.homepage = "https://rubygems.org/gems/burger_game"
|
|
26
28
|
s.license = "GPL-3.0"
|
|
27
29
|
s.required_ruby_version = "~> 2.7"
|
data/lib/burger_game.rb
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
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: 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 }
|
|
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
|
+
# 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
|
|
171
|
+
puts
|
|
172
|
+
puts "The customer wants to say something..."
|
|
173
|
+
puts
|
|
174
|
+
puts customer.display_response(customer_no, mood)
|
|
175
|
+
|
|
176
|
+
puts
|
|
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
|
|
197
|
+
end
|
|
198
|
+
end
|
|
199
|
+
end
|
data/lib/customer_request.rb
CHANGED
|
@@ -5,7 +5,7 @@ class CustomerRequest
|
|
|
5
5
|
# ERROR HANDLING for reading files
|
|
6
6
|
begin
|
|
7
7
|
# Read customer_request.JSON file
|
|
8
|
-
customer_file = File.read('./
|
|
8
|
+
customer_file = File.read('./data/customer_request.json')
|
|
9
9
|
rescue Errno::ENOENT => e
|
|
10
10
|
puts "Could not find customer_request.json file. Please put customer_request.json in the 'data' directory."
|
|
11
11
|
puts e.message
|
|
@@ -18,7 +18,7 @@ class CustomerRequest
|
|
|
18
18
|
|
|
19
19
|
begin
|
|
20
20
|
# Read customer_response.JSON file
|
|
21
|
-
response_file = File.read('./
|
|
21
|
+
response_file = File.read('./data/customer_response.json')
|
|
22
22
|
rescue Errno::ENOENT => e
|
|
23
23
|
puts "Could not find customer_response.json file. Please put customer_response.json in the 'data' directory."
|
|
24
24
|
puts e.message
|
data/lib/recipe.rb
CHANGED
|
@@ -8,7 +8,7 @@ class Recipe
|
|
|
8
8
|
# ERROR HANDLING for reading files
|
|
9
9
|
begin
|
|
10
10
|
# Read recipe.JSON file
|
|
11
|
-
file = File.read('./
|
|
11
|
+
file = File.read('./data/recipe.json')
|
|
12
12
|
rescue Errno::ENOENT => e
|
|
13
13
|
puts "Could not find recipe.json file. Please put recipe.json in the 'data' directory."
|
|
14
14
|
puts e.message
|
data/spec/burger_game_spec.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: burger_game
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jessica Gozali
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2021-05-
|
|
11
|
+
date: 2021-05-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -111,16 +111,17 @@ dependencies:
|
|
|
111
111
|
description: A simple text-based Ruby terminal game, that simulates a burger shop,
|
|
112
112
|
where you need to build the meal for the customers with different requests and preferences.
|
|
113
113
|
email: gcas012115@coderacademy.edu.au
|
|
114
|
-
executables:
|
|
114
|
+
executables:
|
|
115
|
+
- start_burger_game
|
|
115
116
|
extensions: []
|
|
116
117
|
extra_rdoc_files: []
|
|
117
118
|
files:
|
|
118
119
|
- "./Gemfile"
|
|
119
120
|
- "./Gemfile.lock"
|
|
120
121
|
- "./LICENSE"
|
|
122
|
+
- "./bin/start_burger_game"
|
|
121
123
|
- "./burger_game.gemspec"
|
|
122
|
-
- "./burger_game.rb"
|
|
123
|
-
- "./burger_game.sh"
|
|
124
|
+
- "./lib/burger_game.rb"
|
|
124
125
|
- "./lib/customer_request.rb"
|
|
125
126
|
- "./lib/data/customer_request.json"
|
|
126
127
|
- "./lib/data/customer_response.json"
|
|
@@ -131,6 +132,7 @@ files:
|
|
|
131
132
|
- "./lib/score_comparison.rb"
|
|
132
133
|
- "./lib/screen_message.rb"
|
|
133
134
|
- "./spec/burger_game_spec.rb"
|
|
135
|
+
- bin/start_burger_game
|
|
134
136
|
homepage: https://rubygems.org/gems/burger_game
|
|
135
137
|
licenses:
|
|
136
138
|
- GPL-3.0
|
data/burger_game.rb
DELETED
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
# For command line argument
|
|
2
|
-
require 'optparse'
|
|
3
|
-
require 'ostruct'
|
|
4
|
-
|
|
5
|
-
require_relative './lib/game_state'
|
|
6
|
-
require_relative './lib/screen_message'
|
|
7
|
-
require_relative './lib/recipe'
|
|
8
|
-
require_relative './lib/customer_request'
|
|
9
|
-
require_relative './lib/player_option'
|
|
10
|
-
require_relative './lib/score_comparison'
|
|
11
|
-
|
|
12
|
-
class BurgerGame
|
|
13
|
-
# Initialise
|
|
14
|
-
game_state = GameState.new
|
|
15
|
-
show_menu = Recipe.new
|
|
16
|
-
no_of_recipe = Recipe.no_of_recipe
|
|
17
|
-
screen = ScreenMessage.new
|
|
18
|
-
player_options = PlayerOption.new
|
|
19
|
-
customer = CustomerRequest.new
|
|
20
|
-
no_of_customer = CustomerRequest.no_of_customer
|
|
21
|
-
options = OpenStruct.new
|
|
22
|
-
|
|
23
|
-
# Handle command line argument
|
|
24
|
-
opt_parser = OptionParser.new do |opt|
|
|
25
|
-
opt.banner = "Usage: main.rb [options]"
|
|
26
|
-
|
|
27
|
-
opt.on("-h", "--help", "Print this Help menu for Ruby Burger Game.") do |arg|
|
|
28
|
-
puts opt
|
|
29
|
-
exit
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
opt.on("-m", "--money TARGET_MONEY", screen.display_h_money) { |arg| options.target_money = arg }
|
|
33
|
-
|
|
34
|
-
opt.on("-r", "--reputation MAX_REPUTATION", screen.display_h_reputation) { |arg| options.max_reputation = arg }
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
# ERROR HANDLING for command line argument
|
|
38
|
-
begin
|
|
39
|
-
opt_parser.parse!
|
|
40
|
-
rescue OptionParser::InvalidOption => e
|
|
41
|
-
puts "You have entered an invalid option. Please check the available options in our Help menu '-h' or '--help'."
|
|
42
|
-
puts e.message
|
|
43
|
-
exit
|
|
44
|
-
rescue OptionParser::MissingArgument => e
|
|
45
|
-
puts "You have not entered the argument for your option."
|
|
46
|
-
puts e.message
|
|
47
|
-
exit
|
|
48
|
-
rescue OptionParser::ParseError => e
|
|
49
|
-
puts "Error when parsing argument."
|
|
50
|
-
puts e.message
|
|
51
|
-
exit
|
|
52
|
-
rescue => e
|
|
53
|
-
puts "Something went wrong."
|
|
54
|
-
puts "Error message: " + e.message
|
|
55
|
-
exit
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
if (options.target_money)
|
|
59
|
-
if ((options.target_money.to_i >= 10 ) && (options.target_money.to_i <= 99 ))
|
|
60
|
-
puts "Change TARGET_MONEY to: $#{options.target_money}.00."
|
|
61
|
-
# Set target money in GameState
|
|
62
|
-
game_state.set_target_money(options.target_money.to_f)
|
|
63
|
-
else
|
|
64
|
-
puts screen.display_invalid("for TARGET_MONEY.")
|
|
65
|
-
exit
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
end
|
|
69
|
-
if (options.max_reputation)
|
|
70
|
-
if ((options.max_reputation.to_i >= 1 ) && (options.max_reputation.to_i <= 10 ))
|
|
71
|
-
puts "Change MAX_REPUTATION to: #{options.max_reputation}."
|
|
72
|
-
# Set max reputation in GameState
|
|
73
|
-
game_state.set_max_reputation(options.max_reputation.to_i)
|
|
74
|
-
else
|
|
75
|
-
puts screen.display_invalid("for MAX_REPUTATION.")
|
|
76
|
-
exit
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
# Ask user if they want to launch the game or exit
|
|
81
|
-
puts
|
|
82
|
-
launch_game = player_options.launch_game
|
|
83
|
-
|
|
84
|
-
# Exit command line if user select Exit
|
|
85
|
-
exit if launch_game === false
|
|
86
|
-
|
|
87
|
-
# Show welcome message
|
|
88
|
-
puts
|
|
89
|
-
puts screen.display_welcome
|
|
90
|
-
puts
|
|
91
|
-
screen.go_to_next
|
|
92
|
-
|
|
93
|
-
# Feature 1: Options to see instructions or to start the game
|
|
94
|
-
loop do
|
|
95
|
-
puts
|
|
96
|
-
start_game = player_options.start_game
|
|
97
|
-
|
|
98
|
-
break if start_game === true
|
|
99
|
-
|
|
100
|
-
# Show instructions
|
|
101
|
-
puts
|
|
102
|
-
puts screen.display_instructions
|
|
103
|
-
|
|
104
|
-
puts
|
|
105
|
-
screen.go_to_next
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
# Show prologue
|
|
109
|
-
puts
|
|
110
|
-
puts screen.display_prologue
|
|
111
|
-
|
|
112
|
-
puts
|
|
113
|
-
screen.go_to_next
|
|
114
|
-
|
|
115
|
-
# Loop game until WIN / GAME OVER
|
|
116
|
-
loop do
|
|
117
|
-
# Display current money and reputation status
|
|
118
|
-
puts game_state.display_game_state
|
|
119
|
-
|
|
120
|
-
puts
|
|
121
|
-
screen.go_to_next
|
|
122
|
-
|
|
123
|
-
# Feature 2: Formatted display for showing shop's menu
|
|
124
|
-
puts
|
|
125
|
-
puts "Ruby Burger's Menu"
|
|
126
|
-
puts
|
|
127
|
-
puts
|
|
128
|
-
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."
|
|
129
|
-
puts
|
|
130
|
-
|
|
131
|
-
# Loop to display all recipes
|
|
132
|
-
i = 0
|
|
133
|
-
loop do
|
|
134
|
-
puts show_menu.display_recipe(i)
|
|
135
|
-
|
|
136
|
-
puts
|
|
137
|
-
screen.go_to_next
|
|
138
|
-
|
|
139
|
-
i += 1
|
|
140
|
-
break if i > (no_of_recipe - 1)
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
# Feature 3: Randomised customers with set of request (and associated preferences) and responses
|
|
144
|
-
# Display customer request
|
|
145
|
-
puts
|
|
146
|
-
puts "There is a customer in the queue..."
|
|
147
|
-
puts
|
|
148
|
-
# Randomise customer
|
|
149
|
-
customer_no = rand(no_of_customer)
|
|
150
|
-
puts customer.display_request(customer_no)
|
|
151
|
-
puts
|
|
152
|
-
|
|
153
|
-
puts
|
|
154
|
-
screen.go_to_next
|
|
155
|
-
|
|
156
|
-
# Feature 4: Selectable options for list of ingredients, so no manual entry (typing) is needed.
|
|
157
|
-
# Quantity input as integer within a pre-set range.
|
|
158
|
-
# Display player's options
|
|
159
|
-
player_recipe = player_options.get_selection
|
|
160
|
-
customer_recipe = customer.get_request(customer_no)
|
|
161
|
-
|
|
162
|
-
# Feature 5: Score calculation based on customer's request and preferences compared to player's input
|
|
163
|
-
# Calculate score
|
|
164
|
-
compare = ScoreComparison.new(player_recipe, customer_recipe)
|
|
165
|
-
score = compare.get_score
|
|
166
|
-
mood = compare.get_mood(score)
|
|
167
|
-
|
|
168
|
-
# Feautre 6: Get customers' responses from a JSON file
|
|
169
|
-
# Display customer's response
|
|
170
|
-
puts
|
|
171
|
-
puts "The customer wants to say something..."
|
|
172
|
-
puts
|
|
173
|
-
puts customer.display_response(customer_no, mood)
|
|
174
|
-
|
|
175
|
-
puts
|
|
176
|
-
screen.go_to_next
|
|
177
|
-
puts
|
|
178
|
-
|
|
179
|
-
# Update game state
|
|
180
|
-
compare.calculate_state(mood)
|
|
181
|
-
|
|
182
|
-
# Feature 7: Lose/win criteria based on reputation and money
|
|
183
|
-
# GAME OVER condition
|
|
184
|
-
if GameState.current_reputation == 0
|
|
185
|
-
puts screen.display_game_over
|
|
186
|
-
puts
|
|
187
|
-
break
|
|
188
|
-
end
|
|
189
|
-
|
|
190
|
-
# WIN condition
|
|
191
|
-
if GameState.current_money >= GameState.target_money
|
|
192
|
-
puts screen.display_win
|
|
193
|
-
puts
|
|
194
|
-
break
|
|
195
|
-
end
|
|
196
|
-
end
|
|
197
|
-
end
|