Skip to content

Commit

Permalink
Added weapon shop, general cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
willluongo committed Feb 18, 2013
1 parent 1942d43 commit 888b6a9
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
31 changes: 29 additions & 2 deletions LotRD.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class LotRD
def initialize()
@forest_monsters = JSON.load(File.open('./forest_monsters.json').read)
@armor_store = JSON.load(File.open('./armor.json').read)
@weapon_store = JSON.load(File.open('./weapon.json').read)
@log = Logger.new("lotrd.log")
@log.level = Logger::DEBUG
@play = true
Expand Down Expand Up @@ -40,7 +41,7 @@ def start

# Prompt is the workhorse of user interactions
#
# * no arguments defaults to "Hit enter to continue"
# * No arguments defaults to "Hit enter to continue"
# * One argument is basically a pause with a custom prompt
# * Automatically handles invalid choices, only returns a valid selection

Expand Down Expand Up @@ -85,6 +86,8 @@ def main_menu
visit_inn
when "a"
visit_armory
when "w"
visit_weaponry
else
prompt "Sorry, that isn't implemented yet. Press enter to continue."
end
Expand Down Expand Up @@ -168,7 +171,6 @@ def visit_armory
item_string = item_string + "\n[#{item_no}] A #{item["name"]}. Armor value #{item["armor_value"]}. Cost: #{item["cost"]} gold."
item_list.push(item_no)
end
# TODO: Add option to sell armor
select = prompt(item_string + "\n[L]eave the store", *item_list, :l)
if select == "l"
# drop out to main menu
Expand All @@ -182,6 +184,31 @@ def visit_armory
end
end

def visit_weaponry
@log.debug(@weapon_store)
clear
puts "Welcome to the Weapon Shop!"
item_string = ""
item_no = 0
item_list = []
@weapon_store.each do |item|
item_no = item_no + 1
item_string = item_string + "\n[#{item_no}] A #{item["name"]}. Attack value #{item["attack_value"]}. Cost: #{item["cost"]} gold."
item_list.push(item_no)
end
select = prompt(item_string + "\n[L]eave the store", *item_list, :l)
if select == "l"
# drop out to main menu
else
if @player.purchase_weapon(select, @weapon_store)
prompt
else
prompt
visit_weaponry
end
end
end

def visit_inn
clear
puts "Welcome to the Ruby Dragon Inn!"
Expand Down
14 changes: 14 additions & 0 deletions player.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ def purchase_armor(select, store)
end
end

def purchase_weapon(select, store)
old_weapon = @weapon
weapon = store[select.to_i-1]
if @gold >= weapon["cost"]
@weapon = Weapon.new(weapon["name"], weapon["use"], weapon["attack_value"], weapon["cost"])
@gold = @gold - weapon["cost"] + old_weapon.cost
puts "Sold! You are now the proud owner of #{@weapon.name}! I even gave you #{old_weapon.cost / 2} gold for that old #{old_weapon.name}!"
return true
else
puts "I am sorry, you don't have enough gold, and I don't do charity!"
return false
end
end

def inn(cost)
if @gold >= cost
@gold = @gold - cost
Expand Down
26 changes: 26 additions & 0 deletions weapon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[
{
"name":"brass knuckles",
"use":"punch",
"cost":10,
"attack_value":5
},
{
"name":"rubber dagger",
"use":"annoy",
"cost":30,
"attack_value":7
},
{
"name":"broken keyboard",
"use":"smack",
"cost":50,
"attack_value":9
},
{
"name":"hatchet",
"use":"smash, smash, smayush",
"cost":150,
"attack_value":12
}
]

0 comments on commit 888b6a9

Please sign in to comment.