class Game
Public Class Methods
new(credentials, detector)
click to toggle source
# File lib/minitest/game/game.rb, line 2 def initialize(credentials, detector) @credentials = credentials @detector = detector start_game end
Private Instance Methods
beginning()
click to toggle source
# File lib/minitest/game/game.rb, line 70 def beginning say("'Hello there! Welcome to the world of Naga! My name is Oak. People call me the Naga Prof!") choose do |menu| menu.prompt = "> " menu.choice(:look) { say("You find yourself in the main office of Naga. The man standing in front of you is wearing a red shirt but not with a lab coat.") } menu.choices(:ask) { say("'You're joking, right?', you ask.\n'I mean... I've got the red shirt, just not the lab coat.', he replies.") } menu.choices(:laugh) { say("You laugh and then reminisce of the days of capturing creatures, enslaving them and making them fight. Your smile soon fades.") } menu.choices(:silence) { say("You remain silent. 'Not the talkative kind I see. No worries, I'm sure you'll find a way to ease yourself in.'") } menu.default = :silence end say("You've arrived at Naga, a bespoke software development company, your new workplace. It's 9.04am on a Monday.\nYou love Mondays.") say("'Okay, my name is not really Oak. It's actually Ash. Pleased to meet you.'") choose do |menu| menu.prompt = "> " menu.choice(:talk) { say("'Pleased to meet you.', you reply.") } menu.choices(:ask) { say("'You're joking again, right?', you ask.\n'Nope! My name is actually Ash.', he replies.") } menu.choices(:silence) { say("You remain silent.") } menu.default = :silence end say("Ash explains that for the first couple of days of your internship you'll be shadowing him.") say("'Here's your desk. Right next to mine for the time being.'") choose do |menu| menu.prompt = "> " menu.choice(:look) { say("You notice it's small or 'smol' but there's still space to fit a couple of things.") } menu.choices(:talk) { say("You don't know what to say so you just smile politely.") } menu.choices(:silence) { say("You remain silent.") } menu.default = :silence end say("'It's a tradition here at Naga for a newbie to select a mug for themselves to train... I mean keep. There are 3 mugs here! (When I was younger, I was a serious mug collector.)'") collected = false picked_mug = nil while !collected do choose do |menu| menu.prompt = "> " menu.shell = true menu.confirm = true green_mug = Item.get("Green Mug", @credentials) red_mug = Item.get("Red Mug", @credentials) blue_mug = Item.get("Blue Mug", @credentials) menu.choice(green_mug.name, green_mug.description + " Level: " + green_mug.level.to_s) do |_command, details| Inventory.add_to_desk(green_mug, @credentials) collected = true picked_mug = green_mug say("'When this mug gets angry... You don't want to see it angry.', says Ash.") end menu.choice(red_mug.name, red_mug.description + " Level: " + red_mug.level.to_s) do |_command, details| Inventory.add_to_desk(red_mug, @credentials) collected = true picked_mug = red_mug say("'You're not too dissimilar to others, most people pick the red mug as well.', says Ash.") end menu.choice(blue_mug.name, blue_mug.description + " Level: " + blue_mug.level.to_s) do |_command, details| Inventory.add_to_desk(blue_mug, @credentials) collected = true picked_mug = blue_mug say("'Hey, my favourite colour is blue! Good choice newbie.', says Ash.") end end end say("'Do you want to give a nickname to " + picked_mug.name.upcase + "?'") choose do |menu| menu.prompt = "> " menu.choice(:yes) { say("'I was joking...', replies Ash.") } menu.choices(:no) { say("You decided against nicknaming your mug.") } menu.choices(:silence) { say("You remain silent.\nAsh smirks.") } menu.default = :silence end say("'Wait!', exclaims Ash. 'Let's check out our mugs!'") continue = ask("> [Hit Enter to continue] ") say(".\n.\n.") say("The Enter button loses 100HP and Ash wants to fight!") continue = ask("> ") say(".\n.\n.") continue = ask("> ") say("*BTFW* The Creator laughs. 'If all of this has gone over your head, I'm sincerely sorry. If it hasn't, then good on you.'") continue = ask("> ") say("*BTFW* 'First off, terrible writing I know. But go with it, it'll get worse.'") continue = ask("> ") say("*BTFW* 'Also, BTFW stands for Breaking the Fourth Wall. Not anything else...'") continue = ask("> ") say("*BTFW* 'Anyway, I just wanted to let you know about that mug you just received. If you sign in using our web application and go to your Inventory (or your Profile), you'll see that you have now added an item to your Desk. K bye.'") continue = ask("> ") say("'Anyway, ignore the Creator. They know nothing about unit testing or anything for that matter.' says Ash.") say("'So enough with the chit chat, from now onwards, we're unit testing!'") continue = ask("> ") say("*BTFW* 'What Ash really means is that you'll be unit testing as well as collecting loot, unlocking achievements and going places!' exclaims the Creator. 'Okay, goodbye for real.'") say("'Let's get to it!'") say(".\n.\n.") continue = ask("> ") completed_beginning end
completed_beginning()
click to toggle source
# File lib/minitest/game/game.rb, line 173 def completed_beginning url = NagaApiClient.BASE_URL + "/users/beginning" options = { headers: { "Content-Type" => "application/x-www-form-urlencoded" } } options[:body] = "email=" + @credentials[:email] + "&authentication_token=" + @credentials[:authentication_token] response = HTTParty.post(url, options) if response["error"] STDERR.puts(("\nError: " + response["error"]).colorize(:red)) STDERR.puts(("Unable to confirm completion of the beginning.").colorize(:red)) end end
completed_beginning?()
click to toggle source
# File lib/minitest/game/game.rb, line 166 def completed_beginning? options = { headers: { "Content-Type" => "application/json" } } url = NagaApiClient.BASE_URL + "users/beginning?authentication_token=" + @credentials[:authentication_token] + "&email=" + @credentials[:email] response = HTTParty.get(url, options) response.parsed_response["beginning"] end
item_achievements(item)
click to toggle source
# File lib/minitest/game/game.rb, line 214 def item_achievements(item) @detector.bluebeard(item) @detector.purple_rain(item) @detector.i_am_legendary(item) end
main()
click to toggle source
# File lib/minitest/game/game.rb, line 19 def main say("You stand at the Fast Travel station outside the office.") say("'Welcome to the Fast Travel station at Naga! Where would you like to go?'") selected = false current_location = nil # Output location options while !selected do choose do |menu| menu.prompt = "> " menu.shell = true Location.all.each do |location| menu.choice(location.name, location.description) do |_command, details| say(location.to_s) selected = true current_location = location end end end end # Output places in chosen location choose do |menu| menu.prompt = "> " current_location.places.each do |place| menu.choice(place.name, place.description) { say("You travelled to #{place.name}.")} end end # Call for item drop item = Item.drop(@credentials) if item say(item.to_s) say("Do you want to add it to your desk or backpack or leave it?") choose do |menu| menu.prompt = "> " menu.confirm = true menu.choice(:desk) do |_command, details| Inventory.add_to_desk(item, @credentials) item_achievements(item) end menu.choice(:backpack) do |_command, details| Inventory.add(item, @credentials) item_achievements(item) end menu.choice("leave it") do |_command, details| say("You leave the item behind.") end menu.default = "leave it" end end say("After some time of exploring, you go home.") end
run()
click to toggle source
# File lib/minitest/game/game.rb, line 184 def run url = NagaApiClient.BASE_URL + "/users/run" options = { headers: { "Content-Type" => "application/x-www-form-urlencoded" } } options[:body] = "email=" + @credentials[:email] + "&authentication_token=" + @credentials[:authentication_token] response = HTTParty.post(url, options) if response["error"] STDERR.puts(("\nError: " + response["error"]).colorize(:red)) elsif response["warning"] runs = response["runs"] max_runs = response["max_runs"] level = response["level"] if response["warning"] == "Runs available" if response["level_up"] puts "You just grew a level!".colorize(:black).colorize( :background => :green ) puts "You are now " + response["level"]["number"] + " and have " + response["level"]["xp"] + "." end puts "Level #{level["number"]} (#{level["name"]})".colorize(:blue) puts "#{level["xp"]} XP / #{level["total_xp"]} XP".colorize(:green) puts "You used up #{runs} / #{max_runs} energy bars today.".colorize(:magenta) puts "=" *80 return true else puts "Level #{level["number"].to_s} (#{level["name"]})".colorize(:blue) puts "#{level["xp"]} XP / #{level["total_xp"]} XP".colorize(:green) puts "Sorry! You don't have anymore energy bars for today, you've reached your maximum amount of #{max_runs} energy bars. Come back tomorrow when you've regenerated to collect more loot!".colorize(:red) return false end end end
start_game()
click to toggle source
# File lib/minitest/game/game.rb, line 10 def start_game if run if !completed_beginning? beginning end main end end