summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/player.lisp21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/player.lisp b/src/player.lisp
index d91c32a..d497fed 100644
--- a/src/player.lisp
+++ b/src/player.lisp
@@ -2,8 +2,9 @@
(:use :cl)
(:export :init-player
:name
- :cash
- :debt
+ :get-cash
+ :get-debt
+ :repay-debt
:buy-item))
(in-package :player)
@@ -31,6 +32,14 @@
:cash cash
:debt debt))
+(defmethod get-debt ((p player))
+ (with-slots (debt) player
+ debt))
+
+(defmethod get-cash ((p player))
+ (with-slots (cash) player
+ cash))
+
(defmethod buy-item ((p player) item quantity)
(with-slots (stock cash) p
(let ((cost (* quantity
@@ -41,4 +50,10 @@
(setq cash (- cash cost))
t)))))
-
+(defmethod repay-debt ((p player) amount)
+ (with-slots (debt cash) p
+ (when (and (<= amount debt)
+ (<= amount cash))
+ (setq cash (- cash amount)
+ debt (- debt amount))
+ t)))