I'm stuck on figuring out how to implement this.
The concept is that I want:
- to be able to let the game update whether or not the player has entered input, but use the input if it's available
- be able to seamlessly swap out the user's input with a predefined sequence for testing purposes.
This is the broken implementation I currently have:
(defn game
"Runs the simplified version of the main game"
[world user-input-machine]
(let [input [first (deref user-input-machine 10 nil)]]
(if (not= input "QUIT")
(do (println input) ; do game logic stuff
(game world (rest (deref user-input-machine)))) ;repeat
world)))
The idea being to pass in something like
(future (repeatedly(readline)))
or
(future (["hello", "world", "QUIT"]))
As input. The implementation is wrong for a number of reasons. I'm just getting started with clojure, and this is my first attempt at using futures/delays/promises etc. Can anyone help me out?
I've come across a few related questions that haven't quite answered what im looking for (I'm not even sure how to articulate the query):