diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/game.lisp | 11 | ||||
| -rw-r--r-- | src/main.lisp | 37 |
2 files changed, 37 insertions, 11 deletions
diff --git a/src/game.lisp b/src/game.lisp index 40e201c..f0efd14 100644 --- a/src/game.lisp +++ b/src/game.lisp @@ -7,6 +7,7 @@ :get-profit :get-profit-in-zone :get-cur-zone + :get-zone :commodities-panel :player-stats)) @@ -60,9 +61,13 @@ (with-slots (cur-zone) g (get-profit-in-zone g name cur-zone))) +(defmethod get-zone ((g game) zone) + (with-slots (zones) g + (find-if (lambda (x) (string= (zone:name x) zone)) + zones))) -(defmethod commodities-panel ((g game)) - (with-slots (player cur-zone) g +(defmethod commodities-panel ((g game) zone) + (with-slots (player) g (mapcar (lambda (c) (let* ((name (commodities:name c)) (price (commodities:price c)) @@ -75,7 +80,7 @@ :price price :qty quantity :profit profit))) - (zone:get-commodities cur-zone)))) + (zone:get-commodities zone)))) (defmethod player-stats ((g game)) (with-slots (player) g diff --git a/src/main.lisp b/src/main.lisp index 8baf355..12c1483 100644 --- a/src/main.lisp +++ b/src/main.lisp @@ -7,7 +7,9 @@ (clim:define-application-frame superapp () ((cur-zone :initarg :start-zone - :accessor cur-zone)) + :accessor cur-zone) + (cur-panel :initform '(stats) + :accessor cur-panel)) ;; :panes section describes different parts of the ;; application-frame. This application has only one pane. (:panes @@ -30,8 +32,8 @@ (default (clim:vertically () (1/8 title) (4/8 (clim:horizontally () - (2/3 zone-price) - (1/3 panel))) + (1/2 zone-price) + (1/2 panel))) (3/8 int))))) (defmethod frame-standard-output ((frame superapp)) @@ -68,14 +70,33 @@ :align-x :center :align-y :top)) (defmethod display-zone-price ((frame superapp) stream) - (format-zone-price (game:commodities-panel g) stream)) + (format stream "Prices for ~a~%" (zone:name (game:get-cur-zone g))) + (format-zone-price + (game:commodities-panel g (game:get-cur-zone g)) stream)) (defmethod display-panel ((frame superapp) stream) - (format-stats (game:player-stats g) stream)) + (case (car (cur-panel frame)) + ('stats (format-stats (game:player-stats g) stream)) + ('prices (progn + (format stream "Prices for ~a~%" (cdr (cur-panel frame))) + (format-zone-price + (game:commodities-panel g + (game:get-zone g + (cdr (cur-panel frame)))) + stream))))) ;; Panel command - (define-superapp-command (com-panel :name t) () - (format-zone-price (game:commodities-panel g) t)) - + (define-superapp-command (com-prices :name t) ((zone 'string)) + (clim:with-application-frame (frame) + (if (game:get-zone g zone) + (setf (cur-panel frame) (cons 'prices zone)) + (format (frame-standard-output frame) + "Zone ~A does not exist~%" + zone)))) + ;; Stats command + (define-superapp-command (com-stats :name t) () + (clim:with-application-frame (frame) + (setf (cur-panel frame) '(stats)))) + ;; Buy command (define-superapp-command (com-buy :name t) ((item 'string) (quantity 'integer)) |
