Class: UI
Instance Method Summary collapse
- #accept_input ⇒ Object
- #alert_user ⇒ Object
- #clear_position(x, y) ⇒ Object
- #close ⇒ Object
- #door?(x, y) ⇒ Boolean
-
#initialize ⇒ UI
constructor
A new instance of UI.
- #load_room(map) ⇒ Object
- #next_room ⇒ Object
- #wall?(x, y) ⇒ Boolean
- #write(x, y, string) ⇒ Object
Constructor Details
#initialize ⇒ UI
Returns a new instance of UI.
6 7 8 9 10 |
# File 'lib/roguelike/ui.rb', line 6 def initialize noecho curs_set(0) init_screen end |
Instance Method Details
#accept_input ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/roguelike/ui.rb', line 22 def accept_input inputs = %w(w a s d q) loop do input = getch return input if inputs.include?(input) end end |
#alert_user ⇒ Object
46 47 48 49 |
# File 'lib/roguelike/ui.rb', line 46 def alert_user beep flash end |
#clear_position(x, y) ⇒ Object
30 31 32 33 34 |
# File 'lib/roguelike/ui.rb', line 30 def clear_position(x, y) setpos(y, x) delch insch(' ') end |
#close ⇒ Object
12 13 14 15 |
# File 'lib/roguelike/ui.rb', line 12 def close close_screen exit end |
#door?(x, y) ⇒ Boolean
41 42 43 44 |
# File 'lib/roguelike/ui.rb', line 41 def door?(x, y) setpos(y, x) inch.chr =='#' end |
#load_room(map) ⇒ Object
51 52 53 54 |
# File 'lib/roguelike/ui.rb', line 51 def load_room(map) write(0, 0, map.layout) Game.instance.character.move(map.initial_x, map.initial_y) end |
#next_room ⇒ Object
56 57 58 59 60 61 |
# File 'lib/roguelike/ui.rb', line 56 def next_room clear next_room = Game.instance.map.number + 1 Game.instance.map.update_map(next_room) load_room(Game.instance.map) end |
#wall?(x, y) ⇒ Boolean
36 37 38 39 |
# File 'lib/roguelike/ui.rb', line 36 def wall?(x, y) setpos(y, x) inch.chr == '|' || inch.chr == '-' end |
#write(x, y, string) ⇒ Object
17 18 19 20 |
# File 'lib/roguelike/ui.rb', line 17 def write(x, y, string) setpos(y, x) addstr(string) end |