Comparing version 1.0.3 to 1.0.4
{ | ||
"name": "snekjs", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "A terminal-based Snake implementation written in JavaScript (Node.js) 🐍", | ||
@@ -5,0 +5,0 @@ "author": { |
@@ -1,8 +0,6 @@ | ||
const blessed = require('blessed') | ||
const { Game } = require('./src/Game') | ||
const { UserInterface } = require('./src/UserInterface') | ||
const { Game } = require('./src/Game') | ||
const ui = new UserInterface(blessed, blessed.screen()) | ||
const game = new Game(ui) | ||
const game = new Game(new UserInterface()) | ||
// Begin game | ||
game.start() |
@@ -18,2 +18,5 @@ # 🐍 Snek.js [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) [![snekjs on NPM](https://img.shields.io/npm/v/snekjs.svg?color=green&label=snekjs)](https://www.npmjs.com/package/snekjs) | ||
cd snek | ||
# install and run via npm or yarn | ||
npm install && npm run play | ||
yarn && yarn play | ||
@@ -34,7 +37,4 @@ ``` | ||
// index.js | ||
const blessed = require('blessed') | ||
const { UserInterface, Game } = require('snekjs') | ||
const ui = new UserInterface(blessed, blessed.screen()) | ||
const game = new Game(ui) | ||
const game = new Game(new UserInterface()) | ||
@@ -41,0 +41,0 @@ // Begin game |
@@ -0,1 +1,3 @@ | ||
const blessed = require('blessed') | ||
/** | ||
@@ -10,7 +12,7 @@ * @class UserInterface | ||
class UserInterface { | ||
constructor(blessed, screen) { | ||
constructor() { | ||
// Blessed is the terminal library API that provides a screen, elements, and | ||
// event handling | ||
this.blessed = blessed | ||
this.screen = screen | ||
this.screen = blessed.screen() | ||
@@ -20,4 +22,13 @@ // Game title | ||
// Create the game container | ||
this.gameBox = { | ||
// Create the boxes | ||
this.gameBox = this.createGameBox() | ||
this.scoreBox = this.createScoreBox() | ||
this.gameOverBox = this.createGameOverBox() | ||
this.gameContainer = this.blessed.box(this.gameBox) | ||
this.scoreContainer = this.blessed.box(this.scoreBox) | ||
} | ||
createGameBox() { | ||
return { | ||
parent: this.screen, | ||
@@ -33,5 +44,6 @@ top: 1, | ||
} | ||
} | ||
// Create the score container | ||
this.scoreBox = { | ||
createScoreBox() { | ||
return { | ||
parent: this.screen, | ||
@@ -48,4 +60,6 @@ top: 0, | ||
} | ||
} | ||
this.gameOverBox = { | ||
createGameOverBox() { | ||
return { | ||
parent: this.screen, | ||
@@ -70,5 +84,2 @@ top: 'center', | ||
} | ||
this.gameContainer = this.blessed.box(this.gameBox) | ||
this.scoreContainer = this.blessed.box(this.scoreBox) | ||
} | ||
@@ -75,0 +86,0 @@ |
55957
307