You need a check in the loop to see if the player wants to end the game. Clojure doesn't have a break statement like Java so you created a infinite loop that will never end. To make sure the game ends you need to have a base case. Example of a main game loop in clojure:
(loop [game-state initial-state] (if (game-ends? game-state) (close-game game-state) (recur (render (logic game-state))))) You should also look into records to store the game's state. Records are faster than hash maps and you have polymorphism with protocols. Be careful of the lazy functions in clojure like map. It will only execute when you ask a value for it. Matt Hoyt ________________________________ From: Dennis Haupt <d.haup...@googlemail.com> To: clojure@googlegroups.com Sent: Saturday, September 24, 2011 2:36 PM Subject: beginner question -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 in java, i would start coding a game with a loop like this: while (true) { logic(); render(); } i would store the current state of the world in an object containing the complete data of the whole game and update its values in each iteration. how would i do this in clojure? the outer loop could look like (def next [oldstate] (....)) <- input = current game, return value = next iteration (loop [world initalState] (recur (next world))) // <- the loop but how would be world look like? the "best" (most trivial) thing that i could think of is for it to be a map which is passed along several transform functions, for example (def playerHealthRegen [world] (...)) <- input = world (a map), output = a new map with a new entry at key "playerhealth" each function would then return a slightly modified version of the world, and at the end, i'll have my completely new state. is that about right? or is there a completely different way i overlooked? - -- -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.14 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQIcBAEBAgAGBQJOfjE+AAoJENRtux+h35aGo0MQAMipkc8e0YTPxsWsLzaVoQuz MtXerKHHqqbuyxy+mzlc4xFfFUfs//wQGdk/ExZhby7eNVBc9AGYKarCyG/DVxfM HwN7RVHIKDtWoHQk71dthSAzkHgbZvFxjO2W3EkI10rTsCYNFx1WV4o/PMt/KYJj phmtO9LcHmb/ySsLveTmSdJTYjSDb7ENudLbM2z/4SP9AqN21sU1HRNF/Y4gLnq3 tnnGmbpRU8Xs6xv8O8oluRrhjgpGF58okG+JnnW+aqF95OaDMp2dQ2mPKxcWLzmt zkMj41jC28By05oVPIIOstB50rOzU0VAQvEJRDohz2E2sxbhFfUci7G/75hvBkYz vUXeQi4TCYM/gQlOOiAqUuutWpYWBbgL7OOHck3VkGn7UEKBguhkMTO/xGJjFxbY 6/pxIy7i7+DbSXfq+tu5sw2XAS96tctD1dWVdFjfpKukckvcDff3/L0ObKwIxTQu BN9tqoUOs1Tp2OBJhkEJfaBMgUKqX5+IW/mKARVywNFLRWTAYs74OTO86ei/jTPo kqwu2NGE9p/iHpLAxin8sz6I34kOlHJ2X7Xi4PBC19mmVgErt+A8MIvELuxhKBYw BxoWZ11bccphKHFUdEDaj43pd1DqFhLqqpDvFWumUIO48pnDRpYcYcRLZ/6raCXv apIq/CL5V7UHCJ+d/ANo =Ckx2 -----END PGP SIGNATURE----- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en