diff options
| author | El-BG-1970 <elouangros@hotmail.com> | 2022-07-31 18:15:19 +0200 |
|---|---|---|
| committer | El-BG-1970 <elouangros@hotmail.com> | 2022-07-31 18:15:19 +0200 |
| commit | 374cada07cb663cae76d0d1896cfad5172752fc3 (patch) | |
| tree | ce3ccdbd02fb9bdd7ec36a2e93c0a5e9455a9de3 /src/player.lisp | |
| parent | 3dc8dc250a5cd4089f43a4ff2ac9e9593fa93203 (diff) | |
| download | transacc-374cada07cb663cae76d0d1896cfad5172752fc3.tar.gz | |
added repay-debt to player
Diffstat (limited to 'src/player.lisp')
| -rw-r--r-- | src/player.lisp | 21 |
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))) |
