Class: Degica::Game
- Inherits:
-
Object
- Object
- Degica::Game
- Defined in:
- lib/degica/game.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Game
constructor
A new instance of Game.
- #start ⇒ Object
- #welcome_message ⇒ Object
Constructor Details
#initialize ⇒ Game
Returns a new instance of Game.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/degica/game.rb', line 3 def initialize # setup rooms rooms = RoomLoader.load # spawn actor in random room starting_room = rooms.sample @actor = Actor.new(starting_room) # game objects @@objects = OpenStruct.new(rooms: rooms, actor: @actor) # generate starting room starting_room.generate! end |
Class Method Details
.objects ⇒ Object
18 19 20 |
# File 'lib/degica/game.rb', line 18 def self.objects @@objects end |
Instance Method Details
#start ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/degica/game.rb', line 42 def start loop do input = Readline.readline("#{prompt}> ", true) exit if input == "exit" begin context = Context.new(@actor) case output = context.instance_eval(input) when String # remove quotes in console i.e. > "string" puts output when Actionable @actor.focus = output = output.describe puts unless .nil? when NilClass puts @actor.describe else puts CodeRay.scan(output.inspect, :ruby).terminal end rescue Exception => e puts e. end puts end end |
#welcome_message ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/degica/game.rb', line 22 def ANSI.clear_screen puts "Welcome to" puts ANSI.highlight(File.read(Degica.root + '/data/images/degica_quest.txt'), :yellow) puts "Welcome, brave ruby warrior!" puts "Please enter a username:" username = Readline.readline("> ", true) begin RestClient.post "https://meio9thjhi.execute-api.ap-northeast-1.amazonaws.com/production", {username: username}.to_json unless ENV['SKIP'] rescue SocketError nil end puts "Welcome (#{username})! An epic adventure awaits you.\n".highlight puts "\n" + @actor.describe + "\n" puts "Type (actions) to see what actions you can perform.".highlight end |