burger_game 0.1.1 → 1.0.0
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 +15 -0
- data/Gemfile.lock +60 -0
- data/LICENSE +674 -0
- data/burger_game.gemspec +29 -0
- data/{lib/burger_game.rb → burger_game.rb} +12 -11
- data/burger_game.sh +9 -0
- data/lib/customer_request.rb +7 -0
- data/lib/data/customer_request.json +172 -0
- data/lib/data/customer_response.json +82 -0
- data/lib/data/recipe.json +35 -0
- data/lib/player_option.rb +3 -3
- data/lib/recipe.rb +6 -0
- data/lib/screen_message.rb +52 -20
- data/spec/burger_game_spec.rb +128 -0
- metadata +29 -6
data/burger_game.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "burger_game"
|
3
|
+
s.version = "1.0.0"
|
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.files = ["./burger_game.gemspec",
|
10
|
+
"./burger_game.rb",
|
11
|
+
"./burger_game.sh",
|
12
|
+
"./Gemfile",
|
13
|
+
"./Gemfile.lock",
|
14
|
+
"./LICENSE",
|
15
|
+
"./spec/burger_game_spec.rb",
|
16
|
+
"./lib/customer_request.rb",
|
17
|
+
"./lib/game_state.rb",
|
18
|
+
"./lib/player_option.rb",
|
19
|
+
"./lib/recipe.rb",
|
20
|
+
"./lib/score_comparison.rb",
|
21
|
+
"./lib/screen_message.rb",
|
22
|
+
"./lib/data/customer_request.json",
|
23
|
+
"./lib/data/customer_response.json",
|
24
|
+
"./lib/data/recipe.json"]
|
25
|
+
s.homepage = "https://rubygems.org/gems/burger_game"
|
26
|
+
s.license = "GPL-3.0"
|
27
|
+
s.required_ruby_version = "~> 2.7"
|
28
|
+
s.add_runtime_dependency "bundler", ">= 2.1"
|
29
|
+
end
|
@@ -2,21 +2,22 @@
|
|
2
2
|
require 'optparse'
|
3
3
|
require 'ostruct'
|
4
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'
|
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
11
|
|
12
12
|
class BurgerGame
|
13
13
|
# Initialise
|
14
14
|
game_state = GameState.new
|
15
15
|
show_menu = Recipe.new
|
16
|
-
no_of_recipe = Recipe.
|
16
|
+
no_of_recipe = Recipe.no_of_recipe
|
17
17
|
screen = ScreenMessage.new
|
18
18
|
player_options = PlayerOption.new
|
19
19
|
customer = CustomerRequest.new
|
20
|
+
no_of_customer = CustomerRequest.no_of_customer
|
20
21
|
options = OpenStruct.new
|
21
22
|
|
22
23
|
# Handle command line argument
|
@@ -78,7 +79,7 @@ class BurgerGame
|
|
78
79
|
|
79
80
|
# Ask user if they want to launch the game or exit
|
80
81
|
puts
|
81
|
-
launch_game = player_options.
|
82
|
+
launch_game = player_options.launch_game
|
82
83
|
|
83
84
|
# Exit command line if user select Exit
|
84
85
|
exit if launch_game === false
|
@@ -92,7 +93,7 @@ class BurgerGame
|
|
92
93
|
# Feature 1: Options to see instructions or to start the game
|
93
94
|
loop do
|
94
95
|
puts
|
95
|
-
start_game = player_options.
|
96
|
+
start_game = player_options.start_game
|
96
97
|
|
97
98
|
break if start_game === true
|
98
99
|
|
@@ -145,7 +146,7 @@ class BurgerGame
|
|
145
146
|
puts "There is a customer in the queue..."
|
146
147
|
puts
|
147
148
|
# Randomise customer
|
148
|
-
customer_no = rand(
|
149
|
+
customer_no = rand(no_of_customer)
|
149
150
|
puts customer.display_request(customer_no)
|
150
151
|
puts
|
151
152
|
|
@@ -155,7 +156,7 @@ class BurgerGame
|
|
155
156
|
# Feature 4: Selectable options for list of ingredients, so no manual entry (typing) is needed.
|
156
157
|
# Quantity input as integer within a pre-set range.
|
157
158
|
# Display player's options
|
158
|
-
player_recipe = player_options.
|
159
|
+
player_recipe = player_options.get_selection
|
159
160
|
customer_recipe = customer.get_request(customer_no)
|
160
161
|
|
161
162
|
# Feature 5: Score calculation based on customer's request and preferences compared to player's input
|
data/burger_game.sh
ADDED
data/lib/customer_request.rb
CHANGED
@@ -34,11 +34,13 @@ class CustomerRequest
|
|
34
34
|
@@customer_responses = JSON.parse(response_file)
|
35
35
|
|
36
36
|
# Collect customer names (array of strings)
|
37
|
+
# and number of customers
|
37
38
|
# and customer recipe names request (array of strings)
|
38
39
|
# and customer ingredient changes (array of hashes)
|
39
40
|
# and customer requests text (array of strings)
|
40
41
|
# and customer preferences text (array of strings)
|
41
42
|
@@customer_names = []
|
43
|
+
@@no_of_customer = 0
|
42
44
|
@@customer_recipe_names = []
|
43
45
|
@@customer_ingredient_changes = []
|
44
46
|
@@customer_requests_text = []
|
@@ -52,6 +54,7 @@ class CustomerRequest
|
|
52
54
|
@@customer_preferences_text << request[2].values.join
|
53
55
|
end
|
54
56
|
end
|
57
|
+
@@no_of_customer = @@customer_names.length
|
55
58
|
|
56
59
|
# Collect customer responses (array of arrays of hashes)
|
57
60
|
@@responses = []
|
@@ -62,6 +65,10 @@ class CustomerRequest
|
|
62
65
|
def initialize
|
63
66
|
end
|
64
67
|
|
68
|
+
def self.no_of_customer
|
69
|
+
@@no_of_customer
|
70
|
+
end
|
71
|
+
|
65
72
|
def get_request(customer_no)
|
66
73
|
# Get all original recipes for base recipes (array of hashes)
|
67
74
|
base_recipes = Recipe.all_recipes
|
@@ -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
|
+
]
|
@@ -0,0 +1,82 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
" A Customer ":
|
4
|
+
{
|
5
|
+
"happy": "*Customer seems happy*\nOh what a lovely burger you gave me!\nThank you!",
|
6
|
+
"neutral": "You sure you don't miss a thing or two in this burger...?",
|
7
|
+
"angry": "*Customer is angry*\nHey, I don't think I ordered this...\n*Customer pushes the burger back to you*"
|
8
|
+
}
|
9
|
+
},
|
10
|
+
{
|
11
|
+
" Captain Australia ":
|
12
|
+
{
|
13
|
+
"happy": "*Customer seems happy*\nWOW! That's one bloody awesome burger!\nBetter than Maccas for sure! Ta!",
|
14
|
+
"neutral": "Hey mate, you sure this burger is mine..?\n*Captain thinks you are being dodgy...*",
|
15
|
+
"angry": "*Customer is angry*\n... Are you sure YOU want ME to PAY for THIS..?\n*Captain is flexing his muscle while looking directly into your soul...*"
|
16
|
+
}
|
17
|
+
},
|
18
|
+
{
|
19
|
+
" John Citizen ":
|
20
|
+
{
|
21
|
+
"happy": "*Customer seems happy*\nWonderful! Now, this is what you call a burger-to-die-for!",
|
22
|
+
"neutral": "Excuse me, this burger seems unsophisticated to me...",
|
23
|
+
"angry": "*Customer is angry*\nHorrible!! I hope you close down!"
|
24
|
+
}
|
25
|
+
},
|
26
|
+
{
|
27
|
+
" Jane Citizen ":
|
28
|
+
{
|
29
|
+
"happy": "*Customer seems happy*\nWoo-hoo! This burger will give me strength to face John tomorrow!",
|
30
|
+
"neutral": "Ermm... This burger looks wrong..?\nBut I already gave half of it to John...",
|
31
|
+
"angry": "*Customer is angry*\nNoooo... Why are you being mean?\nYou are not John... *Jane covers her face and walks away*"
|
32
|
+
}
|
33
|
+
},
|
34
|
+
{
|
35
|
+
" Scott Morris ":
|
36
|
+
{
|
37
|
+
"happy": "*Customer seems happy*\nOh wow, you made a delicously-hand-stacked burger!\nLet me shake your hands!",
|
38
|
+
"neutral": "I thought this burger was mine...\nBut, it looks like it belongs to someone else..?",
|
39
|
+
"angry": "*Customer is angry*\nStop it! Just! Stop! It!\nThis is ridiculous! This is un-Australian!"
|
40
|
+
}
|
41
|
+
},
|
42
|
+
{
|
43
|
+
" The Mighty Princess ":
|
44
|
+
{
|
45
|
+
"happy": "*Customer seems happy*\nAww.. You've done well, my dear law abiding citizen.\nHere, claim your reward! *throws you a gold bullion*",
|
46
|
+
"neutral": "Is this what they call a burger..?\nOr, is it just me being too entitled..?\n*The Mighty Princess looks confused*",
|
47
|
+
"angry": "*Customer is angry*\nYOU! *gestures angrily* I'm the Princess! You do what I say!\n*The Mighty Princess starts climbing the counter top...*"
|
48
|
+
}
|
49
|
+
},
|
50
|
+
{
|
51
|
+
" Donald T. ":
|
52
|
+
{
|
53
|
+
"happy": "*Customer seems happy*\nYou did it! You are now a member of my fans club!\nHere, take my money!",
|
54
|
+
"neutral": "Meh, I could build a better burger shop in this area.\n*Donald T. shrugs his shoulders*",
|
55
|
+
"angry": "*Customer is angry*\nWHAT IS THIS! I'm going to build a wall here.\nAnd, YOU are going to pay for it!"
|
56
|
+
}
|
57
|
+
},
|
58
|
+
{
|
59
|
+
" Mickey M. ":
|
60
|
+
{
|
61
|
+
"happy": "*Customer seems happy*\nOh boy! This is nice! Thank you, burger shop owner!\n*Mickey M. leaves a signature on the counter top*",
|
62
|
+
"neutral": "Hmm... I think this burger is not what I'm after...\n*Mickey M. shakes his head. He looks confused*",
|
63
|
+
"angry": "*Customer is angry*\nOoh... I'm glad I didn't ask my wife to try this burger!\nAnd, no! I don't know Donald T.! *Mickey M. tries to look angry*"
|
64
|
+
}
|
65
|
+
},
|
66
|
+
{
|
67
|
+
" Unicorn ":
|
68
|
+
{
|
69
|
+
"happy": "*Customer seems happy*\nYay! A burger for me! Thank you!\nI'm going to paint a rainbow for you!",
|
70
|
+
"neutral": "Eh? This doesn't look like my order..?\n*Unicorn's rainbow looks fading*",
|
71
|
+
"angry": "*Customer is angry*\nEeeekk!\n*Unicorn dashes out of the store crying out rainbow tears*"
|
72
|
+
}
|
73
|
+
},
|
74
|
+
{
|
75
|
+
" A Robot ":
|
76
|
+
{
|
77
|
+
"happy": "*Customer seems happy*\nBeep... Good... You restore my faith in humanity...\n*Robot pays in bitcoins*",
|
78
|
+
"neutral": "Oily.. Beep... No likey... Beep..",
|
79
|
+
"angry": "*Customer is angry*\nBEEE-EEP! BEEEEEEE-EEP! EEEEEEPPPP!\n*Robot malfunctions and grows into a giant robot*"
|
80
|
+
}
|
81
|
+
}
|
82
|
+
]
|
@@ -0,0 +1,35 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"Normal Burger":
|
4
|
+
[
|
5
|
+
{"Bun": 1},
|
6
|
+
{"Tomato Sauce": 1},
|
7
|
+
{"Lettuce": 1},
|
8
|
+
{"Grilled Chicken": 1},
|
9
|
+
{"Cheese": 1},
|
10
|
+
{"Bun": 1}
|
11
|
+
]
|
12
|
+
},
|
13
|
+
{
|
14
|
+
"Healthy Burger":
|
15
|
+
[
|
16
|
+
{"Bun": 1},
|
17
|
+
{"Cheese": 1},
|
18
|
+
{"Tomato Sauce": 1},
|
19
|
+
{"Grilled Chicken": 2},
|
20
|
+
{"Lettuce": 3},
|
21
|
+
{"Bun": 1}
|
22
|
+
]
|
23
|
+
},
|
24
|
+
{
|
25
|
+
"Questionable Burger":
|
26
|
+
[
|
27
|
+
{"Bun": 1},
|
28
|
+
{"Cheese": 3},
|
29
|
+
{"Tomato Sauce": 4},
|
30
|
+
{"Grilled Chicken": 4},
|
31
|
+
{"Lettuce": 2},
|
32
|
+
{"Bun": 1}
|
33
|
+
]
|
34
|
+
}
|
35
|
+
]
|
data/lib/player_option.rb
CHANGED
@@ -9,7 +9,7 @@ class PlayerOption
|
|
9
9
|
@prompt = TTY::Prompt.new
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
12
|
+
def launch_game
|
13
13
|
player_response = @prompt.select("Do you want to launch the game?") do |menu|
|
14
14
|
menu.choice "Launch Game"
|
15
15
|
menu.choice "Exit"
|
@@ -22,7 +22,7 @@ class PlayerOption
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
def
|
25
|
+
def start_game
|
26
26
|
player_response = @prompt.select("What would you like to do?") do |menu|
|
27
27
|
menu.choice "View 'How to Play'"
|
28
28
|
menu.choice "Start Game"
|
@@ -35,7 +35,7 @@ class PlayerOption
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
def
|
38
|
+
def get_selection
|
39
39
|
# Get ingredient names (array of strings)
|
40
40
|
ingredient_names = []
|
41
41
|
Recipe.ingredient_lists[0].each do |list|
|