Class: Game

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/roguelike/game.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGame

Returns a new instance of Game.



6
7
8
9
10
# File 'lib/roguelike/game.rb', line 6

def initialize
  @map
  @ui = UI.instance
  @character = Character.new("@", nil, nil)
end

Instance Attribute Details

#characterObject (readonly)

Returns the value of attribute character.



4
5
6
# File 'lib/roguelike/game.rb', line 4

def character
  @character
end

#mapObject

Returns the value of attribute map.



5
6
7
# File 'lib/roguelike/game.rb', line 5

def map
  @map
end

#map_nameObject

Returns the value of attribute map_name.



5
6
7
# File 'lib/roguelike/game.rb', line 5

def map_name
  @map_name
end

#uiObject (readonly)

Returns the value of attribute ui.



4
5
6
# File 'lib/roguelike/game.rb', line 4

def ui
  @ui
end

Instance Method Details

#run(map_name) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/roguelike/game.rb', line 12

def run(map_name)
  self.map = Map.new(map_name, 1)
  set_character_position
  ui.write(0, 0, map.layout)
  ui.write(character.x_pos, character.y_pos, character.avatar)
  loop do
    accept_input
  end
end