diff options
Diffstat (limited to 'src/main.lisp')
| -rw-r--r-- | src/main.lisp | 59 |
1 files changed, 42 insertions, 17 deletions
diff --git a/src/main.lisp b/src/main.lisp index 330abe4..8baf355 100644 --- a/src/main.lisp +++ b/src/main.lisp @@ -14,8 +14,13 @@ (title :title-pane :display-time :command-loop :display-function 'display-title) + (zone-price :application + :display-time :command-loop + :scroll-bar nil + :display-function 'display-zone-price) (panel :application - :label-alignment :top + :display-time :command-loop + :scroll-bar nil :display-function 'display-panel) (int :interactor)) @@ -24,23 +29,34 @@ (:layouts (default (clim:vertically () (1/8 title) - (5/8 panel) - (2/8 int))))) + (4/8 (clim:horizontally () + (2/3 zone-price) + (1/3 panel))) + (3/8 int))))) + +(defmethod frame-standard-output ((frame superapp)) + (clim:get-frame-pane frame 'int)) -(defun format-panel (panel stream) +(defun format-zone-price (panel stream) (loop for it in panel do (format stream "~a :~T ~$$ [~@$$] owned: ~a~%" (getf it :name) (getf it :price) (getf it :profit) (getf it :qty)))) +(defun format-stats (player-stats stream) + (format stream "CASH: ~$$~%DEBT: ~$$~%INVENTORY: ~a/~a~%" + (getf player-stats :cash) + (getf player-stats :debt) + (car (getf player-stats :inv)) + (cdr (getf player-stats :inv)))) (defun main () (let* ((p (player:init-player "Joze")) - (c (list (commodities:new-commodity "apple" 5) - (commodities:new-commodity "pear" 7))) - (c2 (list (commodities:new-commodity "apple" 6) - (commodities:new-commodity "pear" 2))) + (c (list (commodities:new-commodity "apple" 50) + (commodities:new-commodity "pear" 70))) + (c2 (list (commodities:new-commodity "apple" 60) + (commodities:new-commodity "pear" 20))) (z (zone:new-zone "Bronx" c)) (z2 (zone:new-zone "Manhattan" c2)) (g (game:new-game p z2 (list z z2)))) @@ -51,16 +67,24 @@ 300 2 :align-x :center :align-y :top)) + (defmethod display-zone-price ((frame superapp) stream) + (format-zone-price (game:commodities-panel g) stream)) (defmethod display-panel ((frame superapp) stream) - (format-panel (game:commodities-panel g) stream)) + (format-stats (game:player-stats g) stream)) ;; Panel command (define-superapp-command (com-panel :name t) () - (format-panel (game:commodities-panel g) t)) + (format-zone-price (game:commodities-panel g) t)) + ;; Buy command (define-superapp-command (com-buy :name t) ((item 'string) (quantity 'integer)) - (game:buy-item g item quantity)) + (clim:with-application-frame (frame) + (let ((out (frame-standard-output frame))) + (if (game:buy-item g item quantity) + (format out "Bought ~a ~a~%" quantity item) + (format out "Could not buy ~a ~a~%" quantity item))))) + ;; Sell command (define-superapp-command (com-sell :name t) ((item 'string) (quantity 'integer)) @@ -69,12 +93,13 @@ (define-superapp-command (com-goto :name t) ((dest 'string)) (clim:with-application-frame (frame) - (if (game:change-zone g dest) - (progn - (setf (cur-zone frame) (zone:name (game:get-cur-zone g))) - (format t "~a~%" (cur-zone frame)) - (format t "Arrived in ~a" (zone:name (game:get-cur-zone g)))) - (format t "Zone ~a does not exist!" dest)))) + (let ((out (frame-standard-output frame))) + (if (game:change-zone g dest) + (progn + (setf (cur-zone frame) (zone:name (game:get-cur-zone g))) + (format out "~a~%" (cur-zone frame)) + (format out "Arrived in ~a" (zone:name (game:get-cur-zone g)))) + (format out "Zone ~a does not exist!" dest))))) (clim:run-frame-top-level (clim:make-application-frame 'superapp |
