-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add resting at the inn, and some refactoring
- Loading branch information
Showing
6 changed files
with
76 additions
and
24 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class Action | ||
def self.success | ||
Success.new | ||
end | ||
|
||
def self.failure | ||
Failure.new | ||
end | ||
|
||
class Success | ||
def success? | ||
true | ||
end | ||
end | ||
|
||
class Failure | ||
def success? | ||
false | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require_relative './action' | ||
|
||
class InnActions < Action | ||
def self.rest cost | ||
if $adventurer.money >= cost | ||
$adventurer.money -= cost | ||
$adventurer.heal! | ||
return success | ||
else | ||
return failure | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,27 @@ | ||
class MarketActions | ||
require_relative './action' | ||
|
||
class MarketActions < Action | ||
def self.buy good, market | ||
price = market.send(good)[:price] | ||
if $adventurer.money >= price | ||
$adventurer.inventory.add(good, 1) | ||
$adventurer.money -= price | ||
market.remove(good, 1) | ||
return Success.new | ||
if $adventurer.can_afford? price | ||
$adventurer.inventory.add good, 1 | ||
$adventurer.pay price | ||
market.remove good, 1 | ||
return success | ||
else | ||
return Failure.new | ||
return failure | ||
end | ||
end | ||
|
||
def self.sell good, market | ||
price = market.send(good)[:price] | ||
if $adventurer.inventory.goods[good] > 0 | ||
$adventurer.inventory.remove(good, 1) | ||
$adventurer.money += price | ||
market.add(good, 1) | ||
return Success.new | ||
$adventurer.inventory.remove good, 1 | ||
$adventurer.get_paid price | ||
market.add good, 1 | ||
return success | ||
else | ||
return Failure.new | ||
end | ||
end | ||
|
||
class Success | ||
def success? | ||
true | ||
end | ||
end | ||
class Failure | ||
def success? | ||
false | ||
return failure | ||
end | ||
end | ||
end |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,8 @@ def describe | |
def market | ||
@market ||= Market.new(self) | ||
end | ||
|
||
def inn_cost | ||
@inn_cost ||= rand(5..15) | ||
end | ||
end |
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