Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defwidget choice-list ()
- ((choices :accessor choices
- :initarg :choices)
- (prompt :accessor prompt
- :initarg :prompt
- :initform "Choose an action:")
- (choice :accessor choice
- :initform nil)))
- (defclass web-player ()
- ((choice-widget :accessor choice-widget
- :initarg :choice-widget)
- (difficulty :accessor difficulty
- :initarg :difficulty)))
- (defmethod render-widget-body ((widget choice-list) &rest args)
- (declare (ignore args))
- (with-html
- (:p (esc (format nil "The current choice is ~A." (choice widget))))
- (:pre :class "choices"
- (loop for choice in (choices widget)
- do (let ((x choice))
- (render-link (lambda (&rest args)
- (declare (ignore args))
- (setf (choice widget) x)
- ; (mark-dirty widget)
- (answer widget x))
- choice))
- (htm :br)))))
- (defmethod offer-choice ((it web-player) actions &key prompt &allow-other-keys)
- (let ((new-widget (make-instance 'choice-list :choices actions :prompt prompt))
- (old-widget (choice-widget it)))
- ; (do-widget old-widget new-widget)))
- (with-flow old-widget
- (yield new-widget))))
- ; (answer old-widget)))
- ; (setf (choice-widget it) new-widget))))
- (defun web-choice (pc actions &key prompt)
- (let ((new-widget (make-instance 'choice-list :choices actions :prompt prompt)))
- new-widget))
- ; (with-flow old-widget
- ; (yield new-widget))
- ; (answer k)))
- (defun run-game (pc)
- (with-flow (choice-widget pc)
- (setf (difficulty pc) (yield (web-choice pc (list "easy" "medium" "hard") :prompt "Select difficulty:")))
- (setf (difficulty pc) (yield (offer-choice pc (list "easy2" "medium2" "hard2") :prompt "Select difficulty:")))
- (yield (offer-choice pc (list "G3" "H3" "I3")))))
- (defun make-main-page ()
- (let* ((choice-widget (make-instance 'choice-list
- :choices (list "A1" "B1" "C1")))
- (pc (make-instance 'web-player
- :choice-widget choice-widget))
- (comp (make-instance 'composite :widgets
- (list
- "Some text."
- choice-widget
- (lambda (&rest args)
- (declare (ignore args))
- (with-html (render-link (lambda (&rest args)
- (declare (ignore args))
- (run-game pc))
- "Play")))))))
- comp))
- (defun init-user-session (root)
- (with-flow root
- (yield (make-main-page))))
Advertisement
Add Comment
Please, Sign In to add comment