Skip to content

Instantly share code, notes, and snippets.

@Raagh
Created April 14, 2020 18:23
Show Gist options
  • Save Raagh/fb0aa6865f7015cf470a13243f783b20 to your computer and use it in GitHub Desktop.
Save Raagh/fb0aa6865f7015cf470a13243f783b20 to your computer and use it in GitHub Desktop.
Functional Snake Game part 2 - UI module
const r = require("ramda")
const { intercalate, update } = require("./helper")
const createWorld = (rows, columns, state) => {
const repeatDot = r.repeat(".")
const map = r.map(r.thunkify(repeatDot)(rows), repeatDot(columns))
return r.pipe(addSnake(state), addApple(state))(map)
}
const addSnake = state => r.pipe(...r.map(update("X"), state.snake))
const addApple = state => update("O")(state.apple)
const displayWorld = matrix => {
console.clear()
console.log(intercalate("\r\n", r.map(intercalate(" "), matrix)))
}
const display = r.curry((rows, columns, state) => {
return r.pipe(createWorld, displayWorld)(rows, columns, state)
})
module.exports = {
display,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment