Top Level Namespace
Defined Under Namespace
Modules: Inn, Shop Classes: AbandHouse, AbandTavern, Armour, Character, Demon, Den_east, Den_north, Den_northeast, Den_west, DenoShadow, Ghoul, GrandChurch, Hamlet1, Human, Imp, Keyitem, Maps, MddltnInn, Middle_ton, Middleton_church, Middleton_shop, Northshire_house, Northshire_inn, Northshire_shop, Northshire_tavern, Northshre, Orc, Player, Purse, Ridge_dale, RidgedaleArmour, RidgedaleInn, RidgedaleItems, RidgedaleTavern, RidgedaleWeapons, Siren, Spector, Spellbook, Troll, Undead, Weapon
Constant Summary collapse
- Ridgedalemap =
Maps.new('ridgedale', Ridgedale)
- Northshiremap =
Maps.new('northshire', Northshire)
- DenofShadowsmap =
Maps.new('den of shadows', Den_of_Shadows)
- Middletonmap =
Maps.new('middleton', Middleton)
- Hamletmap =
Maps.new('deserted hamlet', Hamlet)
- Map_id =
{ 'hamlet' => Hamletmap, 'middleton' => Middletonmap, 'den of shadows' => DenofShadowsmap}
- BookofHeal =
Spellbook.new('book of heal', 'heal')
- BookofHoly =
Spellbook.new('book of holy', 'holy')
- Spellbook_id =
{ 'book of heal' => BookofHeal, 'book of holy' => BookofHoly}
- Book_of_mysteries =
Keyitem.new('book of mysteries')
- Key_Items =
{'book of mysteries' => Book_of_mysteries}
- Items_price =
{'potion' => 50, 'mana' => 70, 'rejuvinate' => 350, 'xpotion' => 150}
- Items =
['potion', 'mana', 'rejuvinate', 'xpotion']
- None =
Armour.new('', 0, '')
- Hat =
Armour.new('hat' , 1, 'head gear')
- Leather =
Armour.new('leather vest' , 3, 'body gear')
- Shield =
Armour.new('wicker shield' , 2, 'shield')
- Shoes =
Armour.new('leather shoes' , 1, 'foot gear')
- Gloves =
Armour.new('leather gloves', 1, 'gloves')
- Chain_Helm =
Armour.new('chain helmet', 5, 'head gear')
- Chain_Mail =
Armour.new('chain mail', 10, 'body gear')
- Steel_Buckler =
Armour.new('steel buckler', 7, 'shield')
- Boots =
Armour.new('heavy boots', 5, 'foot gear')
- Chain_Gloves =
Armour.new('chain gauntlets', 5, 'gloves')
- Plate_Helm =
Armour.new('plated helmet', 13, 'head gear')
- Plate_Mail =
Armour.new('plate mail', 17, 'body gear')
- Tower_Shield =
Armour.new('tower shield', 15, 'shield')
- Plate_Boots =
Armour.new('plated boots', 13, 'foot gear')
- Plate_Gloves =
Armour.new('plated gauntlets', 13, 'gloves')
- Armour_id =
{Hat.name => Hat, Leather.name => Leather, Shield.name => Shield, Shoes.name => Shoes, Gloves.name => Gloves, Chain_Helm.name => Chain_Helm, Chain_Mail.name => Chain_Mail, Steel_Buckler.name => Steel_Buckler, Boots.name => Boots, Chain_Gloves.name => Chain_Gloves, Plate_Helm.name => Plate_Helm, Plate_Mail.name => Plate_Mail, Tower_Shield.name => Tower_Shield, Plate_Boots.name => Plate_Boots, Plate_Gloves.name => Plate_Gloves}
- Armour_price =
{'hat' => 15, 'leather vest' => 45, 'leather gloves' => 15, 'wicker shield' => 30, 'leather shoes' => 15, 'chain helmet' => 125, 'chain mail' => 250, 'steel buckler' => 200, 'heavy boots' => 125, 'chain gauntlets' => 125, 'plated helmet' => 300, 'plate mail' => 500, 'tower shield' => 375, 'plated boots' => 300, 'plated gauntlets' => 300}
- Abnd_tavern =
AbandTavern.new
- Abnd_house =
AbandHouse.new
- Hamletloc =
[Abnd_tavern, Abnd_house]
- Hamlet =
Hamlet1.new
- Spells_price =
{'heal' => 100 , 'holy' => 200, 'flame' => 500}
- Club =
Weapon.new('club', 5)
- Sword =
Weapon.new('sword', 10)
- Axe =
Weapon.new('axe', 15)
- Claymore =
Weapon.new('claymore',20)
- Weapon_id =
{'club' => Club, 'sword' => Sword , 'axe' => Axe , 'claymore' => Claymore }
- Weapons_price =
{'club' => 50, 'sword' => 500, 'axe' => 1000, 'claymore' => 2000}
- Commands_outside =
['use','inventory', 'equip', 'move', 'travel', 'look', 'stats', 'party']
- Commands_fight =
['use','cast','hit','inventory']
- RestlessSpirit =
Ghoul.new('Restless Spirit', 50, 4, 20)
- Bal =
Demon.new('Bal', 1500, 250000000000000000000000000000000000000000000000000000000000000000000000, 1000)
- Mddltn_church =
Middleton_church.new
- Mddltn_inn =
MddltnInn.new
- Mddltn_shop =
Middleton_shop.new
- Middletonloc =
[Middleton_church]
- Middleton =
Middle_ton.new
- Ridgedale =
Ridge_dale.new
- Martin =
Character.new('Martin', 6, 10, 7, 5, 3, 449, Club, Hat, Leather, Shield)
- NorthshireHouse =
Northshire_house.new
- NorthshireTavern =
Northshire_tavern.new
- NorthshireShop =
Northshire_shop.new
- NorthshireInn =
Northshire_inn.new
- Northshire =
Northshre.new
- DenNorth =
Den_north.new
- DenNortheast =
Den_northeast.new
- DenWest =
Den_west.new
- DenEast =
Den_east.new
- Den_of_Shadowsloc =
[DenNorth, DenNortheast, DenWest, DenEast]
- Den_of_Shadows =
DenoShadow.new
Instance Method Summary collapse
- #buy ⇒ Object
- #cast(spell_book = $player.spells) ⇒ Object
- #equip(player = $player) ⇒ Object
- #experience(player, exp) ⇒ Object
- #fight(monster = rand_monster, player = $player) ⇒ Object
- #fire(offense = $player, defense = @monster) ⇒ Object
- #flame(offense = $player, defense = @monster) ⇒ Object
- #heal(user = $player) ⇒ Object
- #hit(offense = $player, defense = @monster) ⇒ Object
- #holy(offense = $player, defense = @monster) ⇒ Object
- #inventory(player = $player) ⇒ Object
- #level_up?(player) ⇒ Boolean
- #look ⇒ Object
- #loot ⇒ Object
- #mana(user = $player) ⇒ Object
- #move ⇒ Object
- #party ⇒ Object
- #potion(user = $player) ⇒ Object
- #rand_monster ⇒ Object
- #rejuvinate(user = $player) ⇒ Object
- #sell ⇒ Object
- #shop ⇒ Object
- #sleep ⇒ Object
- #stats ⇒ Object
- #take ⇒ Object
- #timer(num = 1) ⇒ Object
- #travel ⇒ Object
- #use(inventory = $player.inventory) ⇒ Object
- #xpotion(user = $player) ⇒ Object
Instance Method Details
#buy ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/shop.rb', line 13 def buy inventory = [self.weapons, self.items, self.spells, self.armour] puts 'What would you like to purchase?' puts '' puts '-'*10 puts 'items'.center(10) puts '-'*10 @items.each_key do |key| puts key.to_s + ' - ' + @items[key].to_s + ' gold' end puts '-'*10 puts 'spells'.center(10) puts '-'*10 @spells.each_key do |key| puts key.to_s + ' - ' + @spells[key].to_s + ' gold' end puts '-'*10 puts 'weapons'.center(10) puts '-'*10 @weapons.each_key do |key| puts "#{key.to_s.upcase} - #{@weapons[key].to_s} gold" puts "Damage rating: #{Weapon_id[key].damage.to_s}" end puts '-'*10 puts 'armour' puts '-'*10 @armour.each_key do |key| puts "#{key.to_s.upcase} - #{@armour[key].to_s} gold" puts "Defense rating: #{Armour_id[key]..to_s}" puts "Armour type: #{Armour_id[key].type.to_s}" end puts '' purchase = '' while true purchase = gets.chomp break if purchase == 'back' if(@items.include? purchase) || (@weapons.include? purchase) || (@spells.include? purchase) || (@armour.include? purchase) inventory.each do |invtry| if (invtry.each_key.include? purchase) && (Player1.gold >= invtry[purchase]) Player1.inventory << purchase if @items.include? purchase Player1.inventory << Weapon_id[purchase] if @weapons.include? purchase Player1.inventory << Armour_id[purchase] if @armour.include? purchase Player1.spells << purchase if @spells.include? purchase Player1.gold -= invtry[purchase] elsif (invtry.each_key.include? purchase) && (Player1.gold < invtry[purchase]) puts 'You do not have enough gold' end end puts '' puts 'you have ' + Player1.gold.to_s + ' left.' puts '' puts 'Would you like anything else?' puts '' else puts 'No such item in inventory' end end end |
#cast(spell_book = $player.spells) ⇒ Object
126 127 128 129 130 131 132 133 |
# File 'lib/commands.rb', line 126 def cast(spell_book = $player.spells) puts 'what would you like to cast?' spell =gets.chomp puts 'You do not know that spell' unless spell_book.include? spell if spell_book.include? spell send(spell) end end |
#equip(player = $player) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 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 |
# File 'lib/commands.rb', line 70 def equip (player = $player) invtry = [] player.inventory.each do |item| invtry << item.name if (item.class == Weapon) || (item.class == Armour) end puts '' puts '' puts 'what would you like to equip?' puts "('done' to return)" puts '' puts invtry response = '' while true puts 'Current Equipment:'.center(10) puts "="*10 puts "Weapon: #{player.weapon[0].name.capitalize}" unless player.weapon.length == 0 puts "Weapon: empty" if player.weapon.length == 0 player.armour.each do |article| puts "#{(article.type).capitalize}: #{article.name.capitalize}" end puts "="*10 puts '' response = gets.chomp break if response == 'done' if invtry.include? response if Weapon_id.has_key? response player.weapon.delete_at 0 unless player.weapon.length == 0 player.weapon << Weapon_id[response] elsif Armour_id.has_key? response player.armour.each do |armour| player.armour.delete_at (player.armour.index(armour)) if armour.type == Armour_id[response].type end player.armour << Armour_id[response] end else puts 'You do not have that item' end puts '' puts 'what else would you like to equip?' end end |
#experience(player, exp) ⇒ Object
45 46 47 |
# File 'lib/player.rb', line 45 def experience(player, exp) player.exp += exp end |
#fight(monster = rand_monster, player = $player) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 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 |
# File 'lib/rand_fight.rb', line 17 def fight(monster = rand_monster, player = $player) @monster = monster action = '' puts'' puts @monster.name.to_s + ' Approaches' puts '' puts @monster.name.to_s + "'s life is " + @monster.life.to_s puts 'Your life is ' + player.life.to_s puts 'You have ' + player.magic.to_s + ' magic' puts'' until @monster.life <= 0 break if player.life <= 0 puts'' timer action = '' while true puts 'What would you like to do?' action = gets.chomp if Commands_fight.include? action send(action) break unless action == 'inventory' else puts 'please enter a recognized command' end end break if @monster.life <= 0 timer if player.party.length > 0 player.party.each do |char| if (char.life != 0) && (char.life < (char.endurance*2)) && (char.magic >= char.intelligence) puts "#{char.name} casts heal." heal(char) puts '' elsif char.life == 0 break else hit(char, @monster) end end end break if @monster.life <= 0 puts'' timer hit_chance = rand(player.party.length + 1) if hit_chance == 0 puts @monster.name.to_s + ' lunges at you!' if player.agility * (rand(6) + 1) <= player.agility * 4 damage = (@monster.strength * (rand(6)+1) - player.) unless damage < 0 puts 'and hits you!' player.life -= damage end puts 'Your armour absorbs the blow' if damage <= 0 else puts 'but the swing misses' end else defender = player.party[hit_chance - 1] puts @monster.name.to_s + " lunges at #{defender.name}!" if defender.agility * (rand(6) + 1) <= defender.agility * 4 damage = (@monster.strength * (rand(6)+1) - defender.) unless damage < 0 puts "and hits #{defender.name}!" defender.life -= damage end puts "#{defender.name}'s armour absorbs the blow" if damage <= 0 else puts 'but the swing misses' end end timer puts'' puts @monster.name.to_s.capitalize + "'s life is " + @monster.life.to_s puts '' player.party.each do |char| puts "#{char.name}'s life is #{char.life}" end puts 'Your life is ' + player.life.to_s puts "You have #{player.magic} magic left" break if player.life <=0 end timer if @monster.life <= 0 puts '' puts @monster.name.to_s + "'s lifeless body hits the ground with a thud" unless @monster.class == Spector puts 'The Spectral form disipates' if @monster.class == Spector player.experience += @monster.experience puts 'total experience is ' + player.experience.to_s puts 'current level is ' + player.level.to_s loot gold = (rand(4) * (@monster.experience / 3)) player.gold += gold puts 'gained ' + gold.to_s + ' gold' puts 'total gold is ' + player.gold.to_s level_up?(player) player.party.each do |char| char.experience += @monster.experience if char.life > 0 level_up?(char) end timer end puts '' puts '' end |
#fire(offense = $player, defense = @monster) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/spells.rb', line 2 def fire(offense = $player, defense = @monster) puts 'not enough magic' if offense.magic < 3 damage = offense.intelligence * (rand(6)+ 1) if offense.magic >= 3 && (defense.class != Ghoul && defense.class != Undead) defense.life -= damage offense.magic -= 3 end if offense.magic >= 3 && (defense.class == Ghoul || defense.class == Undead) defense.life -= damage * 2 offense.magic -= 3 end end |
#flame(offense = $player, defense = @monster) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/spells.rb', line 38 def flame(offense = $player, defense = @monster) puts 'not enough magic' if offense.magic < 20 damage = offense.intelligence * (rand(6)+1) * 3 if offense.magic >= 3 && (defense.class != Ghoul && defense.class != Undead) defense.life -= damage offense.magic -= 3 end if offense.magic >= 3 && (defense.class == Ghoul || defense.class == Undead) defense.life -= damage * 2 offense.magic -= 3 end end |
#heal(user = $player) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/spells.rb', line 15 def heal(user = $player) puts 'not enough magic' if user.magic < user.intelligence if user.magic >= user.intelligence user.life += user.intelligence*user.intelligence*2 user.magic -= user.intelligence end if user.life > user.endurance * 10 user.life = user.endurance * 10 end end |
#hit(offense = $player, defense = @monster) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/commands.rb', line 135 def hit(offense = $player, defense = @monster) if offense.weapon.length == 0 bonus = 0 else bonus = offense.weapon[0].damage end roll = offense.agility * (rand (6) + 1) defense.life -= (offense.strength * (rand(6) + 1)) + bonus if roll >= 10 && defense.class != Spector puts '' if roll < 10 puts 'Your clumsy swing misses!' if offense == $player puts "#{offense.name}'s swing misses!" unless offense == $player elsif defense.class == Spector puts 'The attack has no effect' if offense == $player puts "#{offense.name}'s attack has no effect" unless offense == $player else puts 'You land a blow square on the monsters head' if offense == $player puts "#{offense.name}'s lands a blow square on the monsters head" unless offense == $player end puts '' end |
#holy(offense = $player, defense = @monster) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/spells.rb', line 26 def holy(offense = $player, defense = @monster) puts 'not enough magic' if offense.magic < 15 if defense.class == Undead && offense.magic >= 20 defense.life = (defense.life/3) offense.magic -= 20 elsif defense.class == Bal && offense.magic >= 20 defense. life -= offense.intelligence * (rand(6)+1) * 3 else puts 'The spell has no effect' end end |
#inventory(player = $player) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/commands.rb', line 8 def inventory(player = $player) invtry = [] maplist = [] player.maps.each do |map| maplist << map.name end player.inventory.each do |item| invtry << item unless (item.class == Weapon) || (item.class == Armour) || (item.class == Keyitem) || (item.class == Spellbook) invtry << item.name if (item.class == Weapon) || (item.class == Armour) || (item.class == Keyitem) || (item.class == Spellbook) end puts '='*10 puts "Your maps".center(10) puts "="*10 puts maplist puts '='*10 puts 'your inventory'.center(10) puts '='*10 puts invtry.sort! puts '='*10 puts '' end |
#level_up?(player) ⇒ Boolean
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/player.rb', line 49 def level_up?(player) if player.experience >= 50 *player.level * player.level player.level += 1 player.strength += 1 player.endurance += 1 player.agility += 1 player.intelligence += 1 puts '' puts "#{player.name} LEVEL UP!" puts'' if player == $player player.attribute player.life = player.endurance * 10 player.magic = player.intelligence * 3 end end end |
#look ⇒ Object
302 303 304 305 306 |
# File 'lib/commands.rb', line 302 def look if $player.position.length == 0 puts $player.area[0].look end end |
#loot ⇒ Object
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
# File 'lib/commands.rb', line 308 def loot roll_1 =(1 + rand(6)) roll_2 =(1 + rand(6)) if roll_1 + roll_2 >= 8 roll_3 = rand(3) if roll_3 == 0 item = Items[rand(4)] $player.inventory << item puts 'recieved ' + item.to_s elsif roll_3 == 1 item = Items[rand(4)] $player.inventory << item puts 'recieved ' + item.to_s elsif roll_3 == 2 item = Items[rand(4)] $player.inventory << item puts 'recieved ' + item.to_s end end end |
#mana(user = $player) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/items.rb', line 29 def mana(user = $player) user.magic += 15 if user.magic > user.intelligence * 3 user.magic = user.intelligence * 3 end end |
#move ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/commands.rb', line 157 def move puts 'move where?' puts "('done' to return)" response = '' while true response = gets.chomp break if response == 'done' if $player.area[0].locations.has_key? response $player.position << $player.area[0].locations[response] roll = (rand(10) + 1) if (roll >= $player.area[0].fightchance) && ($player.area[0].monsters == 0) fight elsif (roll >= $player.area[0].fightchance) && ($player.area[0].monsters != 0) fight($player.area[0].monster) end break end puts 'please enter a valid location' unless $player.area[0].locations.has_key? response end puts "You are in #{$player.position[0].name}" unless $player.position.length == 0 puts 'You are standing outside' if $player.position.length == 0 puts '' puts $player.position[0].introduction unless $player.position.length == 0 end |
#party ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/commands.rb', line 30 def party puts '='*10 puts 'party'.center(10) puts '='*10 puts 'Your party is empty' if $player.party.length == 0 $player.party.each do |char| puts char.name puts char.stats end puts '='*10 end |
#potion(user = $player) ⇒ Object
4 5 6 7 8 9 |
# File 'lib/items.rb', line 4 def potion(user = $player) user.life += 25 if user.life > user.endurance * 10 user.life = user.endurance * 10 end end |
#rand_monster ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/rand_fight.rb', line 5 def rand_monster roll = (rand($player.level * 2) + 1) return Ghoul.new if roll <= 2 return Spector.new if roll > 2 && roll <= 4 return Imp.new if roll > 4 && roll <= 6 return Orc.new if roll > 6 && roll <= 8 return Troll.new if roll > 8 && roll <= 10 return Siren.new if roll > 10 && roll <= 12 return Undead.new if roll > 12 end |
#rejuvinate(user = $player) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/items.rb', line 18 def rejuvinate(user = $player) user.life = user.endurance * 10 user.magic = user.intelligence * 3 if user.life > user.endurance * 10 user.life = user.endurance * 10 end if user.magic > user.intelligence * 3 user.magic = user.intelligence * 3 end end |
#sell ⇒ Object
72 73 74 75 76 77 78 79 80 81 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 |
# File 'lib/shop.rb', line 72 def sell sell = '' while true puts 'what would you like to sell?' invtry = [] Player1.inventory.each do |item| unless (item.class == Weapon) || (item.class == Armour) invtry << item puts item.to_s + ' - ' + (@items[item]/2).to_s else (item.class == Weapon) || (item.class == Armour) invtry << item.name puts item.name.to_s + ' - ' + (@weapons[item.name]/2).to_s if item.class == Weapon puts item.name.to_s + ' - ' + (@armour[item.name]/2).to_s if item.class == Armour end end puts '' sell = gets.chomp puts '' break if sell == 'back' if (invtry.include? sell) && (@items.has_key? sell) Player1.inventory.delete_at(Player1.inventory.index(sell)) Player1.gold += (@items[sell] / 2) elsif (invtry.include? sell) && (@weapons.has_key? sell) Player1.inventory.delete_at(Player1.inventory.index(Weapon_id[sell])) temp = [] Player1.inventory.each do |item| (temp << item) if (item == Weapon_id[sell]) end Player1.weapon.delete_at 0 if temp.length == 0 Player1.gold += (@weapons[sell] / 2) elsif (invtry.include? sell) && (@armour.has_key? sell) Player1.inventory.delete_at(Player1.inventory.index(Armour_id[sell])) temp = [] Player1.inventory.each do |item| (temp << item) if (item == Armour_id[sell]) end Player1.armour.delete_at(Player1.armour.index(sell).to_i) if temp.length == 0 Player1.gold += (@armour[sell] / 2) else puts 'No such item in your inventory' puts '' end puts '' puts 'You now have ' + Player1.gold.to_s + ' gold.' end end |
#shop ⇒ Object
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 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 |
# File 'lib/shop.rb', line 1 def shop puts '' puts '=' * 50 puts 'SHOP'.center(50) puts '='*50 puts 'Welcome Adventurer!' timer @items = {'potion' => 50, 'mana' => 70, 'rejuvinate' => 350, 'xpotion' => 150} @weapons = {'club' => 50, 'sword' => 150, 'axe' => 400, 'claymore' => 800} @spells = {'heal' => 100 , 'holy' => 200, 'flame' => 500} @armour = {Hat.name => 200, Leather.name => 500, Gloves.name => 175, Shield.name => 375, Shoes.name => 225} def buy inventory = [self.weapons, self.items, self.spells, self.armour] puts 'What would you like to purchase?' puts '' puts '-'*10 puts 'items'.center(10) puts '-'*10 @items.each_key do |key| puts key.to_s + ' - ' + @items[key].to_s + ' gold' end puts '-'*10 puts 'spells'.center(10) puts '-'*10 @spells.each_key do |key| puts key.to_s + ' - ' + @spells[key].to_s + ' gold' end puts '-'*10 puts 'weapons'.center(10) puts '-'*10 @weapons.each_key do |key| puts "#{key.to_s.upcase} - #{@weapons[key].to_s} gold" puts "Damage rating: #{Weapon_id[key].damage.to_s}" end puts '-'*10 puts 'armour' puts '-'*10 @armour.each_key do |key| puts "#{key.to_s.upcase} - #{@armour[key].to_s} gold" puts "Defense rating: #{Armour_id[key]..to_s}" puts "Armour type: #{Armour_id[key].type.to_s}" end puts '' purchase = '' while true purchase = gets.chomp break if purchase == 'back' if(@items.include? purchase) || (@weapons.include? purchase) || (@spells.include? purchase) || (@armour.include? purchase) inventory.each do |invtry| if (invtry.each_key.include? purchase) && (Player1.gold >= invtry[purchase]) Player1.inventory << purchase if @items.include? purchase Player1.inventory << Weapon_id[purchase] if @weapons.include? purchase Player1.inventory << Armour_id[purchase] if @armour.include? purchase Player1.spells << purchase if @spells.include? purchase Player1.gold -= invtry[purchase] elsif (invtry.each_key.include? purchase) && (Player1.gold < invtry[purchase]) puts 'You do not have enough gold' end end puts '' puts 'you have ' + Player1.gold.to_s + ' left.' puts '' puts 'Would you like anything else?' puts '' else puts 'No such item in inventory' end end end def sell sell = '' while true puts 'what would you like to sell?' invtry = [] Player1.inventory.each do |item| unless (item.class == Weapon) || (item.class == Armour) invtry << item puts item.to_s + ' - ' + (@items[item]/2).to_s else (item.class == Weapon) || (item.class == Armour) invtry << item.name puts item.name.to_s + ' - ' + (@weapons[item.name]/2).to_s if item.class == Weapon puts item.name.to_s + ' - ' + (@armour[item.name]/2).to_s if item.class == Armour end end puts '' sell = gets.chomp puts '' break if sell == 'back' if (invtry.include? sell) && (@items.has_key? sell) Player1.inventory.delete_at(Player1.inventory.index(sell)) Player1.gold += (@items[sell] / 2) elsif (invtry.include? sell) && (@weapons.has_key? sell) Player1.inventory.delete_at(Player1.inventory.index(Weapon_id[sell])) temp = [] Player1.inventory.each do |item| (temp << item) if (item == Weapon_id[sell]) end Player1.weapon.delete_at 0 if temp.length == 0 Player1.gold += (@weapons[sell] / 2) elsif (invtry.include? sell) && (@armour.has_key? sell) Player1.inventory.delete_at(Player1.inventory.index(Armour_id[sell])) temp = [] Player1.inventory.each do |item| (temp << item) if (item == Armour_id[sell]) end Player1.armour.delete_at(Player1.armour.index(sell).to_i) if temp.length == 0 Player1.gold += (@armour[sell] / 2) else puts 'No such item in your inventory' puts '' end puts '' puts 'You now have ' + Player1.gold.to_s + ' gold.' end end = ['buy', 'sell'] response = '' while true puts 'What would you like to do? (buy or sell)' puts '' inventory puts 'your spells: ' +Player1.spells.to_s puts 'your weapon: ' + Player1.weapon[0].name.to_s unless Player1.weapon.length == 0 puts 'your weapon: ' + Player1.weapon.to_s if Player1.weapon.length == 0 puts '' puts 'Your gold: ' + Player1.gold.to_s puts '' response = gets.chomp puts '' break if response == 'leave' if .include? response send(response) else puts 'Please enter a valid option' end end puts '='*50 puts '' puts '='*50 end |
#sleep ⇒ Object
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/commands.rb', line 212 def sleep puts 'rest well' puts '' timer puts 'zZz' timer puts 'ZzZ' timer puts 'zZz' timer puts '' $player.life = ($player.endurance * 10) $player.magic = ($player.intelligence * 3) $player.party.each do |char| char.life = (char.endurance * 10) char.magic = (char.intelligence * 3) end puts 'You are well rested!' File.open("games/#{$player.name}/#{$player.name}", "w+") do |file| Marshal.dump($player, file) end $player.party.each do |char| File.open("games/#{$player.name}/#{char.name}", "w+") do |file| Marshal.dump(char, file) end end $player.maps.each do |area| File.open("games/#{$player.name}/#{area.name}", "w+") do |file| Marshal.dump(area.location, file) end end $player.visited.each do |location| location.each do |place| File.open("games/#{$player.name}/#{place.name}", "w+") do |file| Marshal.dump(place, file) end end end end |
#stats ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/commands.rb', line 43 def stats puts '' puts '='*10 puts '='*10 puts '' puts 'Attributes'.center(10) puts '='*10 $player.attribute puts '' puts "Level: #{$player.level.to_s}" puts "Health: #{$player.life.to_s} / #{($player.endurance*10).to_s}" puts "Magic: #{$player.magic.to_s} / #{($player.intelligence*3).to_s}" puts "Current experience: #{$player.experience.to_s}" puts "Exp. until next level: #{((50 *$player.level * $player.level) - ($player.experience)).to_s}" puts "Gold: #{$player.gold.to_s}" puts '' puts 'Spells'.center(10) puts '='*10 puts $player.spells puts '' puts '='*10 puts '='*10 puts '' end |
#take ⇒ Object
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
# File 'lib/commands.rb', line 256 def take puts 'what would you like to take?' response = '' while true response = gets.chomp break if (response == 'done' || response == 'nothing') if $player.position[0].inventory.include? response $player.inventory << response if Items.include? response $player.inventory << Weapon_id[response] if Weapon_id.has_key? response $player.inventory << Armour_id[response] if Armour_id.has_key? response $player.inventory << Key_Items[response] if Key_Items.has_key? response $player.inventory << response if Spellbook_id.has_key? response $player.gold += response.amount if response == 'coin purse' $player.position[0].inventory.delete_at($player.position[0].inventory.index(response)) puts "taken #{response}" break elsif response == 'map' map = 0 $player.position[0].inventory.each do |item| if item.class == Maps map += 1 $player.maps << item $player.position[0].inventory.delete_at($player.position[0].inventory.index(item)) puts "taken #{response}" end end puts 'There are no maps here' if map == 0 break elsif response == 'purse' purse = 0 $player.position[0].inventory.each do |item| if item.class == Purse purse += 1 $player.gold += item.amount $player.position[0].inventory.delete_at($player.position[0].inventory.index(item)) puts "taken #{item.amount} gold" end end puts 'There is no coin purse here' if purse == 0 break else puts 'there is not an item here by that name' end end end |
#timer(num = 1) ⇒ Object
1 2 3 4 5 6 7 8 9 10 11 12 |
# File 'lib/timer.rb', line 1 def timer(num=1) i = 0 until i >= num g = 0 h = [] while g <= 1000 h << ' ' * (h.length * g) g += 1 end i+= 1 end end |
#travel ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/commands.rb', line 182 def travel puts 'Travel where?' puts "('done' to return)" response = '' while true response = gets.chomp break if response == 'done' $player.maps.each do |map| if map.name == response roll1 = (rand(10) + 1) roll2 = (rand(10) + 1) roll3 = (rand(10) + 1) fight if roll1 > 4 break if $player.life <= 0 fight if roll2 > 4 break if $player.life <= 0 fight if roll3 > 4 break if $player.life <= 0 puts map.location.introduction map.location.visit += 1 if map.location.visit == 0 $player.area.delete_at(0) $player.area << map.location end end break end puts "You are in #{$player.area[0].name}" unless $player.life <= 0 puts '' end |
#use(inventory = $player.inventory) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/commands.rb', line 114 def use(inventory = $player.inventory) puts 'what would you like to use' g =gets.chomp puts 'no such item in inventory' unless (inventory.include? g) if inventory.include? g send(g) unless Spellbook_id.has_key? g $player.spells << Spellbook_id[g].spell if Spellbook_id.has_key? g puts "Learned #{Spellbook_id[g].spell.to_s}" if Spellbook_id.has_key? g inventory.delete_at(inventory.index(g)) end end |
#xpotion(user = $player) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/items.rb', line 11 def xpotion(user = $player) user.life += 75 if user.life > user.endurance * 10 user.life = user.endurance * 10 end end |