Skip to content

Commit

Permalink
Use inventory weight to limit buying
Browse files Browse the repository at this point in the history
  • Loading branch information
ragesoss committed Mar 28, 2019
1 parent 6ad751e commit a8237b0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
10 changes: 7 additions & 3 deletions actions/market_actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
class MarketActions < Action
def self.buy good, market
price = market.price good
if $adventurer.can_afford?(price) && market.available?(good)
if !$adventurer.can_afford?(price)
return failure("Sorry, you don't have enough #{MONEY}.")
elsif !market.available?(good)
return failure("Sorry, there's nothing left to buy.")
elsif $adventurer.encumbered?
return failure("You're carrying too much already!")
else
$adventurer.inventory.add good, 1
$adventurer.pay price
market.remove good, 1
return success
else
return failure
end
end

Expand Down
3 changes: 1 addition & 2 deletions concepts/adventurer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def initialize name
end

def status
"You have #@life life. You have #@money #{MONEY}."
"You have #@life life. You have #@money #{MONEY}. Your pack weighs #{inventory.weight}."
end

def heal!
Expand All @@ -40,7 +40,6 @@ def damage_range

MAX_WEIGHT = 100
def encumbered?
pp inventory.weight
inventory.weight > MAX_WEIGHT
end
end
2 changes: 1 addition & 1 deletion interfaces/in_town.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def buy good
if result.success?
@result = Gosu::Image.from_text("You have #{$adventurer.money} #{MONEY} left.", 30)
else
@result = Gosu::Image.from_text("Sorry, you don't have enough #{MONEY}.", 30)
@result = Gosu::Image.from_text(result.text, 30)
end
update_greeting
buy_goods @selected_option # regenerates the options
Expand Down

0 comments on commit a8237b0

Please sign in to comment.