Created
April 14, 2020 18:23
-
-
Save Raagh/fb0aa6865f7015cf470a13243f783b20 to your computer and use it in GitHub Desktop.
Functional Snake Game part 2 - UI module
This file contains hidden or 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
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