Commit 7fa07570 authored by Cory Chamblin's avatar Cory Chamblin

removed window as class slot from scenes

parent 5b0f5fbd
......@@ -10,28 +10,23 @@
;;;; scenes ---------------------------------------------------------------------
(defclass <scene> ()
((window
:initarg :window
:initform (error ":window is required")
:reader window)))
(defclass <scene> () ())
(defgeneric display-scene (s))
(defgeneric display-scene (scene window))
(defgeneric handle-input (s key))
(defgeneric handle-input (scene key))
(defclass <start-scene> (<scene>) ())
(defmethod display-scene ((s <start-scene>))
(draw-string (window s) 0 2 " CORYS ROGUELIKE")
(draw-string (window s) 0 4 " Press [Space] to start")
(draw-string (window s) 0 5 " Press [Q] to quit"))
(defmethod display-scene ((s <start-scene>) window)
(draw-string window 0 2 " CORYS ROGUELIKE")
(draw-string window 0 4 " Press [Space] to start")
(draw-string window 0 5 " Press [Q] to quit"))
(defmethod handle-input ((s <start-scene>) key)
(case key
(#\Space (make-instance '<play-scene> :window (window s)))
(#\Space (make-instance '<play-scene>))
(#\Q (progn
(setf *running* nil)
s))
......@@ -40,37 +35,37 @@
(defclass <play-scene> (<scene>) ())
(defmethod display-scene ((s <play-scene>))
(draw-string (window s) 0 0 " You are having fun.")
(draw-string (window s) 0 1 "-- press [Esc] to lose or [Enter] to win --"))
(defmethod display-scene ((s <play-scene>) window)
(draw-string window 0 0 " You are having fun.")
(draw-string window 0 1 "-- press [Esc] to lose or [Enter] to win --"))
(defmethod handle-input ((s <play-scene>) key)
(case key
(#\Escape (make-instance '<lose-scene> :window (window s)))
(#\Newline (make-instance '<win-scene> :window (window s)))
(#\Escape (make-instance '<lose-scene>))
(#\Newline (make-instance '<win-scene>))
(otherwise s)))
(defclass <win-scene> (<scene>) ())
(defmethod display-scene ((s <win-scene>))
(draw-string (window s) 0 0 " !! YOU WIN !!")
(draw-string (window s) 0 1 "-- press [Enter] to restart --"))
(defmethod display-scene ((s <win-scene>) window)
(draw-string window 0 0 " !! YOU WIN !!")
(draw-string window 0 1 "-- press [Enter] to restart --"))
(defmethod handle-input ((s <win-scene>) key)
(case key
(#\Newline (make-instance '<start-scene> :window (window s)))
(#\Newline (make-instance '<start-scene>))
(otherwise s)))
(defclass <lose-scene> (<scene>) ())
(defmethod display-scene ((s <lose-scene>))
(draw-string (window s) 0 0 " You lose.")
(draw-string (window s) 0 1 "-- press [Enter] to restart --"))
(defmethod display-scene ((s <lose-scene>) window)
(draw-string window 0 0 " You lose.")
(draw-string window 0 1 "-- press [Enter] to restart --"))
(defmethod handle-input ((s <lose-scene>) key)
(case key
(#\Newline (make-instance '<start-scene> :window (window s)))
(#\Newline (make-instance '<start-scene>))
(otherwise s)))
......@@ -84,19 +79,18 @@
;;;; main -----------------------------------------------------------------------
(defun initialize (window)
(defun initialize ()
(setf *running* t)
(make-instance '<start-scene>
:window window))
(make-instance '<start-scene>))
(defun gameloop ()
(let* ((window charms:*standard-window*)
(scene (initialize window)))
(scene (initialize)))
(loop named :game-loop
while *running*
do (progn
(charms:clear-window window)
(display-scene scene)
(display-scene scene window)
(setf scene (handle-input scene (charms:get-char window :ignore-error t)))))))
(defun main ()
......@@ -104,4 +98,3 @@
(charms:disable-echoing)
(charms:enable-raw-input :interpret-control-characters t)
(gameloop)))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment