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

Class Method Details

.clear_messagesObject



87
88
89
# File 'lib/demigodGame/UiHandler.rb', line 87

def self.clear_messages()
  #system "clear" or system "cls"
end

.get_decisionObject

input #



93
94
95
# File 'lib/demigodGame/UiHandler.rb', line 93

def self.get_decision()
  gets.chomp()
end


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


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


68
69
70
71
72
# File 'lib/demigodGame/UiHandler.rb', line 68

def self.print_lost_message()
  puts "You ran out of resources! you lost!"
  puts "(one of youre resources turned negative)"
  puts
end


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


78
79
80
81
82
83
84
85
# File 'lib/demigodGame/UiHandler.rb', line 78

def self.print_tile_options(tile)
  puts (AVAILABLE)
  tile.options.each do |key|
    print ("#{key} - #{GameData::OPTIONS[key]},  ")
  end
  puts BACK
  print PROMPT
end


58
59
60
61
# File 'lib/demigodGame/UiHandler.rb', line 58

def self.print_turn_message
  puts "Choose a tile to work on. Enter 2 numbers with a space in between i.e. \"1 1\""
  print PROMPT
end


74
75
76
# File 'lib/demigodGame/UiHandler.rb', line 74

def self.print_win_message
  puts WIN
end

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