Class: Zarta::Screen
- Inherits:
-
Object
- Object
- Zarta::Screen
- Defined in:
- lib/zarta/main.rb
Overview
Writes the current game screen. No idea why I didn’t just do all this stuff in the Engine class. Look how empty that thing is. You probably didn’t even see it up there.
Instance Method Summary collapse
-
#handle_stairs ⇒ Object
Another function that could be handed off to the Room class.
-
#initialize(dungeon) ⇒ Screen
constructor
A new instance of Screen.
-
#next_rooms_prompt ⇒ Object
Not one to be left out, this guy could also piss off somewhere else.
-
#refresh ⇒ Object
When the player moves into a new room, this function checks if anything has spawned in it and calls the appropriate functions.
Constructor Details
#initialize(dungeon) ⇒ Screen
Returns a new instance of Screen.
87 88 89 90 91 92 93 94 |
# File 'lib/zarta/main.rb', line 87 def initialize(dungeon) @dungeon = dungeon @player = @dungeon.player @room = @dungeon.room @prompt = TTY::Prompt.new refresh end |
Instance Method Details
#handle_stairs ⇒ Object
Another function that could be handed off to the Room class. Like that whale of a beast needs more methods. Maybe it would make more sense to move some functionality into the Engine class.
115 116 117 118 119 120 121 122 |
# File 'lib/zarta/main.rb', line 115 def handle_stairs Zarta::HUD.new(@dungeon) puts 'You see stairs leading down here.' return unless @prompt.yes?('Go down?') @dungeon.level += 1 @dungeon.room = Zarta::Room.new(@dungeon) refresh end |
#next_rooms_prompt ⇒ Object
Not one to be left out, this guy could also piss off somewhere else. Seems like this class is doomed. When I can get round to it, that is. So maybe it will be ok…
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/zarta/main.rb', line 127 def next_rooms_prompt = [] @dungeon.room.new_rooms @dungeon.room.next_rooms.each do |room| << room.description end Zarta::HUD.new(@dungeon) puts 'You see these rooms ahead of you,' next_room_choice = @prompt.select('Choose one:', ) @dungeon.room.next_rooms.each do |room| return room if next_room_choice == room.description end end |
#refresh ⇒ Object
When the player moves into a new room, this function checks if anything has spawned in it and calls the appropriate functions. Looking at it now, it seems that all of this fucnctionality could be off-handed to the room class. I’m just creating HUD objects in any function where I need to refresh it anyway. Feels redundant.
101 102 103 104 105 106 107 108 109 110 |
# File 'lib/zarta/main.rb', line 101 def refresh loop do Zarta::HUD.new(@dungeon) @player.handle_enemy if @dungeon.room.enemy.is_a?(Zarta::Enemy) @player.handle_weapon if @dungeon.room.weapon.is_a?(Zarta::Weapon) handle_stairs if @dungeon.room.stairs @dungeon.room = next_rooms_prompt end end |