burger_game 0.1.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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/lib/recipe.rb
CHANGED
@@ -25,6 +25,7 @@ class Recipe
|
|
25
25
|
# Collect recipe names (array of strings)
|
26
26
|
# and ingredient lists (array of arrays of hashes)
|
27
27
|
@@recipe_names = []
|
28
|
+
@@no_of_recipe = 0
|
28
29
|
@@ingredient_lists = []
|
29
30
|
@@all_recipes.each do |recipe|
|
30
31
|
@@recipe_names << recipe.keys[0]
|
@@ -32,6 +33,7 @@ class Recipe
|
|
32
33
|
@@ingredient_lists << list
|
33
34
|
end
|
34
35
|
end
|
36
|
+
@@no_of_recipe = @@recipe_names.length
|
35
37
|
|
36
38
|
def initialize
|
37
39
|
end
|
@@ -44,6 +46,10 @@ class Recipe
|
|
44
46
|
@@recipe_names
|
45
47
|
end
|
46
48
|
|
49
|
+
def self.no_of_recipe
|
50
|
+
@@no_of_recipe
|
51
|
+
end
|
52
|
+
|
47
53
|
def self.ingredient_lists
|
48
54
|
@@ingredient_lists
|
49
55
|
end
|
data/lib/screen_message.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Import Gems
|
2
2
|
require 'tty-box'
|
3
|
-
require 'tty-screen'
|
4
3
|
require 'tty-prompt'
|
4
|
+
require 'artii'
|
5
5
|
|
6
6
|
class ScreenMessage
|
7
7
|
# Constant variable for display formatting space
|
@@ -22,18 +22,11 @@ class ScreenMessage
|
|
22
22
|
msg = "You have entered an invalid value #{input}\nPlease enter the value in a valid format. Use -h or --help to view Help menu.\n"
|
23
23
|
end
|
24
24
|
|
25
|
-
def go_to_next
|
26
|
-
# Create instance of TTY Prompt
|
27
|
-
prompt = TTY::Prompt.new
|
28
|
-
|
29
|
-
prompt.select("Press enter to continue.", %w(Next))
|
30
|
-
end
|
31
|
-
|
32
25
|
# Method for displaying message frame
|
33
26
|
def msg_frame(title, msg, height = 10)
|
34
27
|
msg_box = TTY::Box.frame({
|
35
28
|
enable_color: true, # force to always color output
|
36
|
-
width:
|
29
|
+
width: 80,
|
37
30
|
height: height,
|
38
31
|
align: :center,
|
39
32
|
padding: 3,
|
@@ -73,9 +66,15 @@ class ScreenMessage
|
|
73
66
|
end
|
74
67
|
|
75
68
|
def display_welcome
|
69
|
+
# Create instance of Artii
|
70
|
+
artii = Artii::Base.new
|
76
71
|
title = " WELCOME "
|
77
|
-
msg = "Hello there... Welcome to
|
78
|
-
|
72
|
+
msg = "Hello there... Welcome to" + "\n\n"
|
73
|
+
msg += artii.asciify('Burger Game') + "\n\n"
|
74
|
+
msg += "We are going to build burgers for customers." + "\n"
|
75
|
+
msg += "Clear your mind, put on your best smile..." + "\n"
|
76
|
+
msg += "And... we're ready to stack 'em burgers!"
|
77
|
+
height = 24
|
79
78
|
|
80
79
|
# Format output using frame
|
81
80
|
msg_frame(title, msg, height)
|
@@ -83,8 +82,12 @@ class ScreenMessage
|
|
83
82
|
|
84
83
|
def display_instructions
|
85
84
|
title = " HOW TO PLAY "
|
86
|
-
msg = "Instructions:\n\n1. When shop's Menu is displayed, memorise burger names, ingredients and quantity needed, and ingredients stack order
|
87
|
-
|
85
|
+
msg = "Instructions:\n\n1. When shop's Menu is displayed, memorise \"burger names\", \"ingredients\" and \"quantity\" needed, and ingredients \"stack order\"." + "\n\n"
|
86
|
+
msg += "2. Customer's request will consists of the \"name of the burger\", and custom \"preferences\", such as 'no sauce' or 'extra 1 patty'." + "\n\n"
|
87
|
+
msg += "3. Select ingredient and quantity needed in order, from \"bottom\" of the stack \"to the top\". Enter \"0\" for requests that ask to leave some ingredients out because we need to keep the correct order of the stack." + "\n\n"
|
88
|
+
msg += "4. When you build the burger perfectly as per customer request, the happy customer will increase your reputation by 1 point and pay $10 for the burger. Otherwise, if you miss a thing or two, but still acceptable, the pay would be halved but no reputation points given. If you fail to make a decent burger for the customer, the angry customer will not pay and they will take 1 point off your reputation." + "\n\n"
|
89
|
+
msg += "5. Keep enough customers happy and earn money to meet the target (You Win). Be careful not to make too many customers angry and let your reputation get to 0 (Game Over)."
|
90
|
+
height = 32
|
88
91
|
|
89
92
|
# Format output using frame
|
90
93
|
msg_frame(title, msg, height)
|
@@ -92,8 +95,14 @@ class ScreenMessage
|
|
92
95
|
|
93
96
|
def display_prologue
|
94
97
|
title = " PROLOGUE "
|
95
|
-
msg = "Ruby Burger is dedicated in fulfilling the ever growing customers' demand of customised and personalised burgers.\n
|
96
|
-
|
98
|
+
msg = "Ruby Burger is dedicated in fulfilling the ever growing customers' demand of customised and personalised burgers.\n"
|
99
|
+
msg += "Our job is to build a burger following our shop's Menu recipes, while adjusting into different customers' preferences.\n"
|
100
|
+
msg += "In the next scene, we will memorise our Menu and recipes." + "\n\n"
|
101
|
+
msg += "Hint:\n"
|
102
|
+
msg += "Memorise \"burger names\", \"ingredients\" and \"quantity\" needed, and ingredients \"stack order\".\n"
|
103
|
+
msg += "Build burger from \"bottom up\". Select ingredients from the bottom of the stack to the top as seen in the recipes.\n"
|
104
|
+
msg += "Enter \"0\" for requests that ask to leave some ingredients to keep the correct order of the stack."
|
105
|
+
height = 22
|
97
106
|
|
98
107
|
# Format output using frame
|
99
108
|
msg_frame(title, msg, height)
|
@@ -115,10 +124,12 @@ class ScreenMessage
|
|
115
124
|
msg += " \\ ````` / | |" + "\n"
|
116
125
|
msg += " |``--........--'`| '.______.'" + "\n"
|
117
126
|
msg += "\\ / " + "\n"
|
118
|
-
msg += "jgs `'----------'` " + "\n\n"
|
127
|
+
msg += "jgs `'----------'` " + "\n\n\n"
|
119
128
|
|
120
|
-
msg += "-- all ASCII artwork copyrighted ©1996-01 --
|
121
|
-
msg += "
|
129
|
+
msg += "-- all ASCII artwork copyrighted ©1996-01 --" + "\n"
|
130
|
+
msg += "Joan G. Stark" + "\n"
|
131
|
+
msg += "-- All Rights Reserved --" + "\n\n"
|
132
|
+
msg += "\n~ END ~"
|
122
133
|
|
123
134
|
height = 35
|
124
135
|
|
@@ -127,13 +138,34 @@ class ScreenMessage
|
|
127
138
|
end
|
128
139
|
|
129
140
|
def display_game_over
|
141
|
+
# Create instance of Artii
|
142
|
+
artii = Artii::Base.new
|
130
143
|
title = " GAME OVER "
|
131
|
-
msg =
|
144
|
+
msg = artii.asciify('GAME OVER') + "\n\n"
|
145
|
+
msg += "Oh no! Everyone is leaving because you didn't stack the right burgers!" + "\n\n"
|
146
|
+
msg += "Owning a burger shop, especially a Ruby one, is tough.\n"
|
147
|
+
msg += "You need to practice hard (or just use the handicap ARGV in command line, read the instruction in the installation/usage guide in README.md).\n\nDon't give up! You can always try again next time!" + "\n\n"
|
132
148
|
msg += "You are lucky this is just a game..."
|
133
149
|
msg += "\n\n\n~ END ~"
|
134
|
-
height =
|
150
|
+
height = 30
|
135
151
|
|
136
152
|
# Format output using frame
|
137
153
|
msg_frame(title, msg, height)
|
138
154
|
end
|
155
|
+
|
156
|
+
def go_to_next
|
157
|
+
# Create instance of TTY Prompt
|
158
|
+
prompt = TTY::Prompt.new
|
159
|
+
|
160
|
+
input = prompt.select("Do you want to continue?") do |menu|
|
161
|
+
menu.choice "Next"
|
162
|
+
menu.choice "Exit"
|
163
|
+
end
|
164
|
+
|
165
|
+
if input == "Exit"
|
166
|
+
exit
|
167
|
+
else
|
168
|
+
input
|
169
|
+
end
|
170
|
+
end
|
139
171
|
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
require_relative '../burger_game'
|
2
|
+
require_relative '../lib/screen_message'
|
3
|
+
require_relative '../lib/recipe'
|
4
|
+
require_relative '../lib/player_option'
|
5
|
+
require_relative '../lib/customer_request'
|
6
|
+
require_relative '../lib/score_comparison'
|
7
|
+
require_relative '../lib/game_state'
|
8
|
+
|
9
|
+
# Test case for Feature 1
|
10
|
+
# and for MAIN FEATURES: Feature 7
|
11
|
+
describe ScreenMessage do
|
12
|
+
# This block runs before each test case defined in 'it' block
|
13
|
+
before(:each) do
|
14
|
+
@screen_message = ScreenMessage.new
|
15
|
+
end
|
16
|
+
|
17
|
+
it "check if display_welcome is defined" do
|
18
|
+
expect(@screen_message.display_welcome.class).to eq(String)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "check if display_instructions is defined" do
|
22
|
+
expect(@screen_message.display_instructions.class).to eq(String)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "check if display_prologue is defined" do
|
26
|
+
expect(@screen_message.display_prologue.class).to eq(String)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "check if display_win is defined" do
|
30
|
+
expect(@screen_message.display_win.class).to eq(String)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "check if display_win is defined" do
|
34
|
+
expect(@screen_message.display_game_over.class).to eq(String)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Test case for Feature 2
|
39
|
+
describe Recipe do
|
40
|
+
it "should display the recipe" do
|
41
|
+
recipe = Recipe.new
|
42
|
+
recipe_no = 1
|
43
|
+
expect(recipe.display_recipe(recipe_no).class).to eq(String)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Test case for Feature 3
|
48
|
+
# and for Feature 6
|
49
|
+
describe CustomerRequest do
|
50
|
+
# This block runs before each test case defined in 'it' block
|
51
|
+
before(:each) do
|
52
|
+
@customer = CustomerRequest.new
|
53
|
+
@customer_no = 1
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should display customer request" do
|
57
|
+
expect(@customer.display_request(@customer_no).class).to eq(String)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should display customer response" do
|
61
|
+
mood = "angry"
|
62
|
+
expect(@customer.display_response(@customer_no, mood).class).to eq(String)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Test case for MAIN FEATURES: Feature 4
|
67
|
+
describe PlayerOption do
|
68
|
+
# This block runs before each test case defined in 'it' block
|
69
|
+
before(:each) do
|
70
|
+
@player_selections = PlayerOption.new
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should launch the game" do
|
74
|
+
expect(@player_selections.launch_game.class).to be(TrueClass) | be(FalseClass)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should start the game" do
|
78
|
+
expect(@player_selections.start_game.class).to be(TrueClass) | be(FalseClass)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should get player's options" do
|
82
|
+
expect(@player_selections.get_selection.class).to eq(Array)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# Test case for MAIN FEATURES: Feature 5
|
87
|
+
describe ScoreComparison do
|
88
|
+
# This block runs before each test case defined in 'it' block
|
89
|
+
before(:each) do
|
90
|
+
player_recipe = [{ "Bun" => 1 }, { "Lettuce" => 2}, { "Grilled Chicken" => 2 }, { "Tomato Sauce" => 4 }, { "Cheese" => 3 }]
|
91
|
+
customer_no = 1
|
92
|
+
customer = CustomerRequest.new
|
93
|
+
@compare = ScoreComparison.new(player_recipe, customer.get_request(customer_no))
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should calculate score for player input and customer request comparison" do
|
97
|
+
expect(@compare.get_score).to be(4)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should get correct customer mood" do
|
101
|
+
expect(@compare.get_mood(@compare.get_score)).to eq("neutral")
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe GameState do
|
106
|
+
# This block runs before each test case defined in 'it' block
|
107
|
+
before(:each) do
|
108
|
+
player_recipe = [{ "Bun" => 1 }, { "Lettuce" => 2 }, { "Grilled Chicken" => 2 }, { "Tomato Sauce" => 4 }, { "Cheese" => 3 }]
|
109
|
+
customer_no = 1
|
110
|
+
customer = CustomerRequest.new
|
111
|
+
@compare = ScoreComparison.new(player_recipe, customer.get_request(customer_no))
|
112
|
+
@game_state = GameState.new
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should get correct current money amount" do
|
116
|
+
score = @compare.get_score
|
117
|
+
mood = @compare.get_mood(score)
|
118
|
+
expect(@compare.calculate_state(mood)[0]).to be(5.0)
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should get correct current reputation points" do
|
122
|
+
expect(@compare.calculate_state(@compare.get_mood(@compare.get_score))[1]).to be(10)
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should display game state" do
|
126
|
+
expect(@game_state.display_game_state.class).to eq(String)
|
127
|
+
end
|
128
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: burger_game
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
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-
|
12
|
-
dependencies:
|
11
|
+
date: 2021-05-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.1'
|
13
27
|
description: A simple text-based Ruby terminal game, that simulates a burger shop,
|
14
28
|
where you need to build the meal for the customers with different requests and preferences.
|
15
29
|
email: gcas012115@coderacademy.edu.au
|
@@ -17,13 +31,22 @@ executables: []
|
|
17
31
|
extensions: []
|
18
32
|
extra_rdoc_files: []
|
19
33
|
files:
|
20
|
-
- "./
|
34
|
+
- "./Gemfile"
|
35
|
+
- "./Gemfile.lock"
|
36
|
+
- "./LICENSE"
|
37
|
+
- "./burger_game.gemspec"
|
38
|
+
- "./burger_game.rb"
|
39
|
+
- "./burger_game.sh"
|
21
40
|
- "./lib/customer_request.rb"
|
41
|
+
- "./lib/data/customer_request.json"
|
42
|
+
- "./lib/data/customer_response.json"
|
43
|
+
- "./lib/data/recipe.json"
|
22
44
|
- "./lib/game_state.rb"
|
23
45
|
- "./lib/player_option.rb"
|
24
46
|
- "./lib/recipe.rb"
|
25
47
|
- "./lib/score_comparison.rb"
|
26
48
|
- "./lib/screen_message.rb"
|
49
|
+
- "./spec/burger_game_spec.rb"
|
27
50
|
homepage: https://rubygems.org/gems/burger_game
|
28
51
|
licenses:
|
29
52
|
- GPL-3.0
|
@@ -34,9 +57,9 @@ require_paths:
|
|
34
57
|
- lib
|
35
58
|
required_ruby_version: !ruby/object:Gem::Requirement
|
36
59
|
requirements:
|
37
|
-
- - "
|
60
|
+
- - "~>"
|
38
61
|
- !ruby/object:Gem::Version
|
39
|
-
version: '
|
62
|
+
version: '2.7'
|
40
63
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
64
|
requirements:
|
42
65
|
- - ">="
|