Created
October 5, 2015 00:18
-
-
Save anonymous/e211188a556c94c50573 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Shop < Event | |
def initialize(hero) | |
@shop = {"hammer" => [-8, 0, 6, 6, 0, 0, "The Magic Hammer"], "sword" => [-9, 0, 3, 3, 2, 20, "The Magic Sword"], | |
"shield" => [-7, 5, 0, 0, 0, 0, "The Magic Shield"], "boots" => [-5, 0, 0, 0, 6, 0, "The Magic Boots"], | |
"ring" => [-5, 0, 0, 0, 0, 30, "The Magic Ring"], "potion" => [-1, 0, 0, 0, 0, 0, "a health potion"]} | |
@offer = "Whatchu want?: HAMMER, SWORD, SHIELD, BOOTS, RING, POTION.\n Or type EXIT to finish shopping." | |
@stats = [hero.gold, hero.ac, hero.attack_range.min, hero.attack_range.max, hero.hit_chance, hero.crit_chance] | |
end | |
def upgrade(item) | |
@stats.map.with_index{|x, i| x + @shop[item][i]} | |
end | |
def not_enough_gold(item) | |
puts "I am sorry, you can't afford that! You have #{@stats[0]} gold left." | |
puts "The #{@shop[item][6]} costs #{@shop[item][0].abs}!" | |
end | |
def enter(hero) | |
puts "Shoppkeeper flavor text" # will describe what is for sale, and what it does. | |
puts @offer | |
input = prompt | |
while input != "exit" | |
if input == "potion" | |
if @stats[0] + @shop[input][0] >= 0 | |
@stats[0] -= 1 | |
hero.spells[:heal] += 1 | |
puts "You purchased #{@shop[input][6]}! You have #{@stats[0]} gold left!" | |
else | |
not_enough_gold(input) | |
end | |
elsif @shop[input] != nil | |
if @stats[0] + @shop[input][0] >= 0 | |
puts "test: stats before purchase are: #{@stats}" | |
@stats = upgrade(input) | |
puts "test: stats after purchase are: #{@stats}" | |
puts "You purchased #{@shop[input][6]}! You have #{@stats[0]} gold left!" | |
else | |
not_enough_gold(input) | |
end | |
else | |
puts "Sorry, I don't have '%s' for sale!" % input | |
puts @offer | |
end | |
if @stats[0] == 0 | |
puts "Looks like you spent all your gold! Come back when you have more, okay?" | |
break | |
end | |
input = prompt | |
end | |
hero.gold, hero.ac, min_att, max_att, hero.hit_chance, hero.crit_chance = @stats | |
hero.attack_range = min_att..max_att | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment