burger_game 1.0.6 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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,37 @@
1
- Gem::Specification.new do |s|
2
- s.name = "burger_game"
3
- s.version = "1.0.6"
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
1
+ Gem::Specification.new do |s|
2
+ s.name = "burger_game"
3
+ s.version = "1.1.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.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
@@ -1,199 +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
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 [options]\nOR\nUsage (bash script - install game): install.sh [options]\nUsage (bash script - run game): burger_game.sh [options]\n\n"
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
199
  end