From 3a9bb4886317e82aee1a45e4b643b5973c5215f9 Mon Sep 17 00:00:00 2001 From: El-BG-1970 Date: Sun, 7 Aug 2022 13:45:02 +0200 Subject: implemented game;commodities-panel --- src/game.lisp | 17 +++++++++++++++++ src/player.lisp | 14 ++++---------- src/zone.lisp | 6 ++++-- 3 files changed, 25 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/game.lisp b/src/game.lisp index 979e4e2..b55224a 100644 --- a/src/game.lisp +++ b/src/game.lisp @@ -55,3 +55,20 @@ (defmethod get-profit ((g game) name) (with-slots (cur-zone) g (get-profit-in-zone g name cur-zone))) + + +(defmethod commodities-panel ((g game)) + (with-slots (player cur-zone) g + (mapcar (lambda (c) + (let* ((name (commodities:name c)) + (price (commodities:price c)) + (player-item (player:find-item player name)) + (quantity (if player-item (cdr player-item) 0)) + (profit (if player-item + (- price + (commodities:price (car player-item)))))) + (list name + price + quantity + profit))) + (zone:get-commodities cur-zone)))) diff --git a/src/player.lisp b/src/player.lisp index 32757d0..b5c8651 100644 --- a/src/player.lisp +++ b/src/player.lisp @@ -16,9 +16,11 @@ ((name :initarg :name :reader name) (cash :initarg :cash - :accessor cash) + :accessor cash + :reader get-cash) (debt :initarg :debt - :accessor debt) + :accessor debt + :reader get-debt) (hp :initform 100 :accessor hp) (clout :initform 0 @@ -34,14 +36,6 @@ :cash cash :debt debt)) -(defmethod get-debt ((p player)) - (with-slots (debt) p - debt)) - -(defmethod get-cash ((p player)) - (with-slots (cash) p - cash)) - (defmethod buy-item ((p player) item quantity) (with-slots (stock cash) p (let ((cost (* quantity diff --git a/src/zone.lisp b/src/zone.lisp index ee2fad5..8e733b1 100644 --- a/src/zone.lisp +++ b/src/zone.lisp @@ -2,7 +2,8 @@ (:use :cl) (:export :new-zone :name - :get-commodity)) + :get-commodity + :get-commodities)) (in-package :zone) @@ -10,7 +11,8 @@ ((name :initarg :name :reader name) (commodities :initarg :commodities - :accessor commodities))) + :accessor commodities + :reader get-commodities))) (defun new-zone (name commodities) (make-instance 'zone -- cgit v1.2.3