-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
69 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,55 @@ | ||
(ns ruin.drawing | ||
(:use [ruin.state :only [game]]) | ||
(:require [lanterna.screen :as s])) | ||
|
||
(def SIDEBAR-WIDTH 40) | ||
|
||
(defmulti draw-ui | ||
"Draw the UI to the console. Does not clear or refresh." | ||
(fn [ui game] | ||
(fn [ui] | ||
(:kind ui))) | ||
|
||
|
||
(defmethod draw-ui :start [this {:keys [screen]}] | ||
(defmethod draw-ui :start [ui] | ||
(io! | ||
(s/put-sheet screen 0 0 [" _____ _ _ _____ _ _" | ||
"| __ \\| | | |_ _| \\ | |" | ||
"| |__) | | | | | | | \\| |" | ||
"| _ /| | | | | | | . ` |" | ||
"| | \\ \\| |__| |_| |_| |\\ |" | ||
"|_| \\_\\\\____/|_____|_| \\_|" | ||
"" | ||
"press any key to begin..."]))) | ||
|
||
(defmethod draw-ui :win [this {:keys [screen]}] | ||
(s/put-sheet (:screen @game) 0 0 | ||
[" _____ _ _ _____ _ _" | ||
"| __ \\| | | |_ _| \\ | |" | ||
"| |__) | | | | | | | \\| |" | ||
"| _ /| | | | | | | . ` |" | ||
"| | \\ \\| |__| |_| |_| |\\ |" | ||
"|_| \\_\\\\____/|_____|_| \\_|" | ||
"" | ||
"press any key to begin..."]))) | ||
|
||
(defmethod draw-ui :win [ui] | ||
(io! | ||
(s/put-sheet screen 0 0 ["Congratulations, you've won!" | ||
"" | ||
"press any key to continue..."]))) | ||
(s/put-sheet (:screen @game) 0 0 | ||
["Congratulations, you've won!" | ||
"" | ||
"press any key to continue..."]))) | ||
|
||
(defmethod draw-ui :lose [this {:keys [screen]}] | ||
(defmethod draw-ui :lose [ui] | ||
(io! | ||
(s/put-sheet screen 0 0 ["Sorry, you lost." | ||
"" | ||
"press any key to continue..."]))) | ||
(s/put-sheet (:screen @game) 0 0 | ||
["Sorry, you lost." | ||
"" | ||
"press any key to continue..."]))) | ||
|
||
|
||
(defmethod draw-ui :play [this {:keys [screen]}] | ||
(defn draw-map [] | ||
(let [screen (:screen @game) | ||
[cols rows] (s/get-size screen) | ||
map-height rows | ||
map-width (- cols (inc SIDEBAR-WIDTH))] | ||
(s/put-sheet screen 0 0 | ||
(repeat map-height (repeat map-width \.))))) | ||
|
||
(defmethod draw-ui :play [ui] | ||
(io! | ||
(s/put-sheet screen 0 0 ["You are playing." | ||
"" | ||
"press enter to win, anything else to lose"]))) | ||
(draw-map) | ||
(s/put-sheet (:screen @game) 0 0 | ||
["You are playing." | ||
"" | ||
"press enter to win, anything else to lose"]))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,41 @@ | ||
(ns ruin.input | ||
(:use [ruin.ui :only [push-ui pop-ui ->UI]]) | ||
(:use [ruin.state :only [game]] | ||
[ruin.ui :only [push-ui pop-ui ->UI]]) | ||
(:require [lanterna.screen :as s])) | ||
|
||
|
||
(defmulti process-input | ||
"Handle input from the console." | ||
(fn [ui game input] | ||
(fn [ui input] | ||
(:kind ui))) | ||
|
||
|
||
(defmethod process-input :start [ui game input] | ||
(defmethod process-input :start [ui input] | ||
(cond | ||
(#{:escape \q} input) (do | ||
(dosync (alter game dissoc :state)) | ||
(s/stop (:screen @game))) | ||
:else (dosync | ||
(pop-ui game) | ||
(push-ui game (->UI :play))))) | ||
(pop-ui) | ||
(push-ui (->UI :play))))) | ||
|
||
(defmethod process-input :win [ui game input] | ||
(defmethod process-input :win [ui input] | ||
(dosync | ||
(pop-ui game) | ||
(push-ui game (->UI :start)))) | ||
(pop-ui) | ||
(push-ui (->UI :start)))) | ||
|
||
(defmethod process-input :lose [ui game input] | ||
(defmethod process-input :lose [ui input] | ||
(dosync | ||
(pop-ui game) | ||
(push-ui game (->UI :start)))) | ||
(pop-ui) | ||
(push-ui (->UI :start)))) | ||
|
||
|
||
(defmethod process-input :play [ui game input] | ||
(defmethod process-input :play [ui input] | ||
(case input | ||
:enter (dosync | ||
(pop-ui game) | ||
(push-ui game (->UI :win))) | ||
(pop-ui) | ||
(push-ui (->UI :win))) | ||
(dosync | ||
(pop-ui game) | ||
(push-ui game (->UI :lose))))) | ||
(pop-ui) | ||
(push-ui (->UI :lose))))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
(ns ruin.state) | ||
|
||
|
||
(defonce game (ref nil)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters