jayunit100
jayunit100

Reputation: 17640

Main class in clojure, leiningan (Conway's game of life)

Hi guys! I'm running Conway's game of life - but I think I had to modify the original version here: https://github.com/sebastianbenz/clojure-game-of-life to reference field.clj (rather than run.clj) in the project.clj file. After doing so, I can start the game by running

repl> (run-game)

However, it crashes on this method, which has no comments regarding input arguments.

Thus, my question is: what does this form (appear to do) from a Clojure syntax perspective?

(defn run-game
  ([engine seed]
    (run-game engine seed
      {:columns 50 :rows 50 :speed 500 :cellsize 10}))
  ([engine seed options]
    (let [panel (field-panel engine seed options)
          frame (field-frame panel)
          timer (Timer. (options :speed) panel)]
      (.start timer))))

UPDATE _

Upvotes: 1

Views: 248

Answers (1)

Adrian Mouat
Adrian Mouat

Reputation: 46538

I'm not 100% sure what you're asking, but it basically defines a function that either takes engine and seed arguments or engine, seed and options arguments.

If the option argument isn't specified, the function creates a default map {:columns 50 :rows 50 :speed 500 :cellsize 10} and calls the second form.

You'll have to look at the code to determine what engine and seed should be set to.

Then you can call it as:

(run-game engine seed)

or

(run-game engine seed {:columns 75 :rows 75 :speed 750 :cellsize 15})

Does that help?

Upvotes: 4

Related Questions