(in-package :cl-user) (defpackage transacc (:use :cl) (:export :main)) (in-package :transacc) (clim:define-application-frame superapp () ((cur-zone :initarg :start-zone :accessor cur-zone)) ;; :panes section describes different parts of the ;; application-frame. This application has only one pane. (:panes (title :title-pane :display-time :command-loop :display-function 'display-title) (panel :application :label-alignment :top :display-function 'display-panel) (int :interactor)) ;; :layouts section describes how the panes are layed out. ;; This application has one layout named "default" which has a single pane. (:layouts (default (clim:vertically () (1/8 title) (5/8 panel) (2/8 int))))) (defun format-panel (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 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))) (z (zone:new-zone "Bronx" c)) (z2 (zone:new-zone "Manhattan" c2)) (g (game:new-game p z2 (list z z2)))) (defmethod display-title ((frame superapp) stream) (clim:draw-text* stream (format nil "Joze~%~a" (zone:name (game:get-cur-zone g))) 300 2 :align-x :center :align-y :top)) (defmethod display-panel ((frame superapp) stream) (format-panel (game:commodities-panel g) stream)) ;; Panel command (define-superapp-command (com-panel :name t) () (format-panel (game:commodities-panel g) t)) ;; Buy command (define-superapp-command (com-buy :name t) ((item 'string) (quantity 'integer)) (game:buy-item g item quantity)) ;; Sell command (define-superapp-command (com-sell :name t) ((item 'string) (quantity 'integer)) (game:sell-item g item quantity)) ;; Goto command (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)))) (clim:run-frame-top-level (clim:make-application-frame 'superapp :height 400 :width 600 :start-zone (game:get-cur-zone g)))))