-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
29 lines (23 loc) · 806 Bytes
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { SnakeGame } from "lib/SnakeGame";
import { ConsoleRenderer } from "lib/ConsoleRenderer";
import { KeyboardController, Keys } from "lib/Keyboard";
const snakeGame = new SnakeGame(4, 20, 20)
const renderer = new ConsoleRenderer(snakeGame)
const keyboard = new KeyboardController()
if(process.argv.indexOf('-c') !== -1)
renderer.colorize = false
if(process.argv.indexOf('-i') !== -1)
renderer.extended = false
setInterval(() => {
snakeGame.loop()
renderer.render()
}, 200)
renderer.render()
keyboard.on('keypress', ({enum: e}) => {
switch(e) {
case Keys.UP: snakeGame.setDirection('UP'); break
case Keys.LEFT: snakeGame.setDirection('LEFT'); break
case Keys.RIGHT: snakeGame.setDirection('RIGHT'); break
case Keys.BOTTOM: snakeGame.setDirection('BOTTOM'); break
}
})