console-game-engine
v1.1.0
Published
A basic console game engine for Node.js.
Downloads
6
Readme
Node.js Console Game Engine
A basic console game engine for Node.js.
Installation
You can use npm to install Engine: npm install console-game-engine
Quick start
const ConsoleGame = require("console-game-engine");
//New game object
const game = new ConsoleGame();
//First render.
game.render();
/*Result of this render:
████████████████
████████████████
████████████████
████████████████
████████████████
████████████████
████████████████
████████████████
*/
const write = [[1, 2], [2, 3], [3, 4], [4, 5]];
for (const [x, y] of write) {
game.set(x, y);
}
/*Result of this:
████████████████
████████████████
█ ██████████████
██ █████████████
███ ████████████
████ ███████████
████████████████
████████████████
*/
for (const [x, y] of write){
game.set(x + 6, y);
}
/*Result of this:
████████████████
████████████████
█ █████ ████████
██ █████ ███████
███ █████ ██████
████ █████ █████
████████████████
████████████████
*/
Result:
Usage:
New Game:
For creating new game map.
//Default values for Class:
const width=16, height=8, backgroundChracter = "█";
const game = new ConsoleGame(width,height, BackgroundChracter);
Render:
For write map to console.
game.render();
Clear:
For clearing console. No effect to map.
game.clear();
Reset:
For resetting, backing first version of map (Defined in new ConsoleGame()
):
game.reset();
Set:
Setting a Chracter in map:
//Default values for this:
const x=1,y=1, chracter = " ";
game.set(x,y,chracter );
WARNING: No need to use the render function, it has render in itself.
Get:
Getting a Chracter from map:
const chracter= game.get(1,1);
console.log(chracter)
WARNING: It has not default parameters.