Class: Dungeon

Inherits:
Object
  • Object
show all
Defined in:
lib/places.rb

Instance Method Summary collapse

Constructor Details

#initializeDungeon

can get here from town, initialize just gives a one time (per visit) message



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/places.rb', line 57

def initialize

  map = <<-MAP
0 1 2 3 4 5 6 7 8 9
0| | |r| | |w| |c| | |
1| | | | |w|c| | | | |
2|r| | |c| |i| | |w| |
3| | |c| | | |i| | | |
4| |w| | | | | | | | |
5|w|c|i| | | | | | | |
6| | | |i| | | |w| |r|
7|c| | | | | |w| | |i|
8| | |w| | | | | | |c|
9| | | | | | |r|i|c| |
MAP
  @map = map.split("\n")[1..map.length].map {|line| line.split('|')[1..map.length]}
  @dungeon_map = DungeonMap.new @map
  puts # formatting
  rand_greet = dice(3)
  rand_greet = "You have entered the dungeon! DUM DUM DUM!!" if rand_greet == 1
  rand_greet = "Stepping into the dungeon, you prepare for adventure." if rand_greet == 2
  rand_greet = "As you enter the dungeon, you notice strange markings along the walls..." if rand_greet == 3
  puts rand_greet
end

Instance Method Details

#choicesObject



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/places.rb', line 82

def choices
  move = 0
  load_data
  room_id = 0     # start at room 0
  until move == "t" and room_id == 0
    puts # formatting
    puts bar_top.yellow
    puts stat_bar(@player.name, @player.xp, @player.lvl, @player.coin, @player.cur_hp, @player.cur_mana)
    puts bar_low.yellow
    puts # formatting
    c = @dungeon_map.choices room_id
    c.add('t', 'Go back to town.') if room_id == 0
    if @player.class.to_s == "Wizard" and
      @player.spell_buff == false
      c.add('f', "Conjure Wizard Familar")
    end
    move = c.prompt
    # apply food buff
    @player.cur_hp = @player.cur_hp + @player.lvl if @player.buff_food == true
    # prevent food buff from raising current health points above maximum
    @player.cur_hp = @player.hp if @player.cur_hp > @player.hp
    # now apply drink buff
    @player.cur_mana = @player.cur_mana + @player.lvl if @player.buff_drink == true
    # prevent drink buff from raising current mana points above maximum
    @player.cur_mana = @player.mana if @player.cur_mana > @player.mana
    new_room_id = @dungeon_map.door_to room_id, move
    if new_room_id != room_id
      room_id = new_room_id
      puts # formatting
      rand_msg = dice(3)
      rand_msg = "You walk further into the dark, dank, dirty, dungeon, smirking slightly at your awesome alliteration ability." if rand_msg == 1
      rand_msg = "You feel a slight draft and your torch flickers briefly..." if rand_msg == 2
      rand_msg = "More strange markings, they seem to mean something, but what and who wrote them?" if rand_msg == 3
      puts rand_msg
      puts # formatting
      random_encounter
    elsif move == "t"  # back to town
      puts # formatting
      puts "You make it back to town in one piece!"
      puts # formatting
      # remove food buffs from player when they leave the dungeon
      @player.buff_food = false
      @player.buff_drink = false
      if @player.class.to_s == "Wizard" and @player.spell_buff == true
        puts "Drako wishes you well and fades away, ready to help another day."
        puts #formatting
        @player.spell_buff = false
      end
      save_data
      return
    # wizard familiar
    elsif move == "f" and
          @player.class.to_s == "Wizard" and
          @player.spell_buff == false
      puts # formatting
      puts "#{@player.name} concentrates intently while waving the magic wand and casting the spell..."
      puts # formatting
      puts "A tiny dragon appears and curls up on your shoulder, snoring loudly."
      @player.spell_buff = true
      @player.cur_mana = @player.cur_mana - @player.lvl*2
      save_data
    end
  end
end