Module: UiHandler
- Defined in:
- lib/demigodGame/UiHandler.rb
Constant Summary collapse
- NEW_GAME =
"Welcome to Demigod! What size would you want your world to be?"
- PROMPT =
'>'
- NO_TILE =
"There is no such tile"
- NOT_ENOUGH_FOOD =
"Your people lack food! Some have died of starvation!"
- RAISE_WARNING =
"Warning: Raising the ground here will destroy the existing building!"
- BACK =
"Press enter on an empty line to go back"
- INVALID =
"That's an invalid move!"
- LOST =
"You ran out of resources, I guess you lose..."
- WIN =
"The dragon shrine is built and so the dragons grant you all the powers of immortality"
- AVAILABLE =
"Available moves are: "
- RESOURCES =
"Not enough resources!"
Class Method Summary collapse
- .clear_messages ⇒ Object
-
.get_decision ⇒ Object
input #.
- .print_error(error_str = "An error has occured") ⇒ Object
- .print_hash(hash) ⇒ Object
- .print_lost_message ⇒ Object
- .print_status(resources, buildings) ⇒ Object
- .print_tile_options(tile) ⇒ Object
- .print_turn_message ⇒ Object
- .print_win_message ⇒ Object
-
.print_world(world) ⇒ Object
output #.
Class Method Details
.clear_messages ⇒ Object
87 88 89 |
# File 'lib/demigodGame/UiHandler.rb', line 87 def self.() #system "clear" or system "cls" end |
.get_decision ⇒ Object
input #
93 94 95 |
# File 'lib/demigodGame/UiHandler.rb', line 93 def self.get_decision() gets.chomp() end |
.print_error(error_str = "An error has occured") ⇒ Object
63 64 65 66 |
# File 'lib/demigodGame/UiHandler.rb', line 63 def self.print_error(error_str="An error has occured") puts "Oops! #{error_str}" puts end |
.print_hash(hash) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/demigodGame/UiHandler.rb', line 51 def self.print_hash(hash) hash. each do |name, amount| print "#{name}: #{amount} | " if name != :luck end puts end |
.print_lost_message ⇒ Object
68 69 70 71 72 |
# File 'lib/demigodGame/UiHandler.rb', line 68 def self.() puts "You ran out of resources! you lost!" puts "(one of youre resources turned negative)" puts end |
.print_status(resources, buildings) ⇒ Object
45 46 47 48 49 |
# File 'lib/demigodGame/UiHandler.rb', line 45 def self.print_status(resources, buildings) print_hash resources print_hash buildings puts end |
.print_tile_options(tile) ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/demigodGame/UiHandler.rb', line 78 def self.(tile) puts (AVAILABLE) tile..each do |key| print ("#{key} - #{GameData::OPTIONS[key]}, ") end puts BACK print PROMPT end |
.print_turn_message ⇒ Object
58 59 60 61 |
# File 'lib/demigodGame/UiHandler.rb', line 58 def self. puts "Choose a tile to work on. Enter 2 numbers with a space in between i.e. \"1 1\"" print PROMPT end |
.print_win_message ⇒ Object
74 75 76 |
# File 'lib/demigodGame/UiHandler.rb', line 74 def self. puts WIN end |
.print_world(world) ⇒ Object
output #
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/demigodGame/UiHandler.rb', line 22 def self.print_world(world) puts print ' -' (world.size).times { |i| print "-#{i+1}--"} puts row_number = 1 world.tiles.each do |row| print "#{row_number}" row.each do |tile| print "| #{tile.to_s}" print " " if tile.to_s.length == 1 end puts '|' row_number += 1 end print ' -' (world.size).times { |i| print "----"} puts '' end |