SHOW:
|
|
- or go back to the newest paste.
| 1 | - | ; Prompt is not currently in use, and I don't /think/ actually need a slot (choice) for the result...? |
| 1 | + | |
| 2 | ((choices :accessor choices | |
| 3 | :initarg :choices) | |
| 4 | (prompt :accessor prompt | |
| 5 | :initarg :prompt | |
| 6 | :initform "Choose an action:") | |
| 7 | (choice :accessor choice | |
| 8 | :initform nil))) | |
| 9 | ||
| 10 | (defclass web-player () | |
| 11 | ((choice-widget :accessor choice-widget | |
| 12 | :initarg :choice-widget) | |
| 13 | (difficulty :accessor difficulty | |
| 14 | :initarg :difficulty))) | |
| 15 | ||
| 16 | (defmethod render-widget-body ((widget choice-list) &rest args) | |
| 17 | (declare (ignore args)) | |
| 18 | (with-html | |
| 19 | (:p (esc (format nil "The current choice is ~A." (choice widget)))) | |
| 20 | (:pre :class "choices" | |
| 21 | (loop for choice in (choices widget) | |
| 22 | do (let ((x choice)) | |
| 23 | (render-link (lambda (&rest args) | |
| 24 | (declare (ignore args)) | |
| 25 | (setf (choice widget) x) | |
| 26 | - | ; (setf (choice widget) x) |
| 26 | + | |
| 27 | (answer widget x)) | |
| 28 | choice)) | |
| 29 | (htm :br))))) | |
| 30 | ||
| 31 | (defmethod offer-choice ((it web-player) actions &key prompt &allow-other-keys) | |
| 32 | (let ((new-widget (make-instance 'choice-list :choices actions :prompt prompt)) | |
| 33 | (old-widget (choice-widget it))) | |
| 34 | ; (do-widget old-widget new-widget))) | |
| 35 | (with-flow old-widget | |
| 36 | - | (setf (choice new-widget) (yield new-widget)) |
| 36 | + | (yield new-widget)))) |
| 37 | - | (setf (choice-widget it) new-widget)))) |
| 37 | + | ; (answer old-widget))) |
| 38 | ; (setf (choice-widget it) new-widget)))) | |
| 39 | ||
| 40 | - | (setf (difficulty pc) (offer-choice pc (list "easy" "medium" "hard") :prompt "Select difficulty:")) |
| 40 | + | (defun web-choice (pc actions &key prompt) |
| 41 | - | (offer-choice pc (list "G3" "H3" "I3"))) |
| 41 | + | (let ((new-widget (make-instance 'choice-list :choices actions :prompt prompt))) |
| 42 | new-widget)) | |
| 43 | ; (with-flow old-widget | |
| 44 | ; (yield new-widget)) | |
| 45 | ; (answer k))) | |
| 46 | ||
| 47 | (defun run-game (pc) | |
| 48 | (with-flow (choice-widget pc) | |
| 49 | (setf (difficulty pc) (yield (web-choice pc (list "easy" "medium" "hard") :prompt "Select difficulty:"))) | |
| 50 | (setf (difficulty pc) (yield (offer-choice pc (list "easy2" "medium2" "hard2") :prompt "Select difficulty:"))) | |
| 51 | - | choice-widget)))) |
| 51 | + | (yield (offer-choice pc (list "G3" "H3" "I3"))))) |
| 52 | - | (prog1 comp |
| 52 | + | |
| 53 | - | (run-game pc)))) |
| 53 | + | |
| 54 | (let* ((choice-widget (make-instance 'choice-list | |
| 55 | :choices (list "A1" "B1" "C1"))) | |
| 56 | (pc (make-instance 'web-player | |
| 57 | :choice-widget choice-widget)) | |
| 58 | (comp (make-instance 'composite :widgets | |
| 59 | (list | |
| 60 | "Some text." | |
| 61 | choice-widget | |
| 62 | (lambda (&rest args) | |
| 63 | (declare (ignore args)) | |
| 64 | (with-html (render-link (lambda (&rest args) | |
| 65 | (declare (ignore args)) | |
| 66 | (run-game pc)) | |
| 67 | "Play"))))))) | |
| 68 | comp)) | |
| 69 | ||
| 70 | (defun init-user-session (root) | |
| 71 | (with-flow root | |
| 72 | (yield (make-main-page)))) |