-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
3,007 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
/*************************************************************************************************************************************************************** | ||
* | ||
* Beast, and ANSI node game | ||
* | ||
* Beast is a node adaptation from the original written by Dan Baker, Alan Brown, Mark Hamilton and Derrick Shadel in 1984 | ||
* https://en.wikipedia.org/wiki/Beast_(video_game) | ||
* | ||
* @license https://github.com/dominikwilkowski/beast.js/blob/master/LICENSE GNU-GPLv3 | ||
* @author Dominik Wilkowski [email protected] | ||
* @repository https://github.com/dominikwilkowski/beast.js | ||
* | ||
**************************************************************************************************************************************************************/ | ||
|
||
'use strict'; | ||
|
||
|
||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
// Dependencies | ||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
const CFonts = require(`cfonts`); | ||
const Chalk = require(`chalk`); | ||
const Fs = require(`fs`); | ||
|
||
|
||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
// Constructor | ||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
const BEAST = (() => { //constructor factory | ||
return { | ||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
// settings | ||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
DEBUG: [Debug], //debug settings | ||
DEBUGLEVEL: 2, //debug level setting | ||
MINWIDTH: 100, //width of the game canvas | ||
MINHEIGHT: 40, //height of the game canvas (reuse in BEAST.HERO.y) | ||
BOARD: [], //the board representation in integers | ||
START: { //the start position of the player, the beasts start on the right top corner | ||
x: 1, //left aligned | ||
y: (40 - 8), //we take MINHEIGHT - 8 to get to the bottom | ||
}, | ||
HERO: {}, //position tracking for our hero | ||
DEAD: false, //when the hero dies he/she can't move no more | ||
BEASTS: {}, //position tracking for all beasts | ||
LIVES: 4, //how many lives do we have? | ||
DEATHS: 0, //how many times have we died so far? | ||
LEVEL: 1, //the current level (we start with 1 duh) | ||
LEVELS: { //the amount of elements per level | ||
1: { //start easy | ||
beast: 1, | ||
block: 600, | ||
solid: 50, | ||
speed: 1000, | ||
}, | ||
2: { //increase beasts and solids, decrease blocks | ||
beast: 3, | ||
block: 350, | ||
solid: 200, | ||
speed: 1000, | ||
}, | ||
3: { //increase beasts and solids, decrease blocks and speed | ||
beast: 10, | ||
block: 100, | ||
solid: 500, | ||
speed: 500, | ||
}, | ||
}, | ||
SYMBOLS: { //symbols for element | ||
hero: Chalk.cyan('¶'), | ||
beast: Chalk.green('Φ'), | ||
block: Chalk.gray('▓'), | ||
solid: Chalk.white('▓'), | ||
}, | ||
RL: {}, //the readline object for reuse in all modules | ||
INTERVAL: {}, //the interval object to clear or set the beast walking interval on | ||
|
||
|
||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
// Debugging prettiness | ||
// | ||
// debugging, Print debug message that will be logged to console. | ||
// | ||
// @method headline Return a headline preferably at the beginning of your app | ||
// @param [text] {string} The sting you want to log | ||
// @param [level] {integer} (optional) The debug level. Show equal and greater levels. Default: 99 | ||
// @return [ansi] {output} | ||
// | ||
// @method report Return a message to report starting a process | ||
// @param [text] {string} The sting you want to log | ||
// @param [level] {integer} (optional) The debug level. Show equal and greater levels. Default: 99 | ||
// @return [ansi] {output} | ||
// | ||
// @method error Return a message to report an error | ||
// @param [text] {string} The sting you want to log | ||
// @param [level] {integer} (optional) The debug level. Show equal and greater levels. Default: 99 | ||
// @return [ansi] {output} | ||
// | ||
// @method interaction Return a message to report an interaction | ||
// @param [text] {string} The sting you want to log | ||
// @param [level] {integer} (optional) The debug level. Show equal and greater levels. Default: 99 | ||
// @return [ansi] {output} | ||
// | ||
// @method send Return a message to report data has been sent | ||
// @param [text] {string} The sting you want to log | ||
// @param [level] {integer} (optional) The debug level. Show equal and greater levels. Default: 99 | ||
// @return [ansi] {output} | ||
// | ||
// @method received Return a message to report data has been received | ||
// @param [text] {string} The sting you want to log | ||
// @param [level] {integer} (optional) The debug level. Show equal and greater levels. Default: 99 | ||
// @return [ansi] {output} | ||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
debugging: { | ||
|
||
headline: ( text ) => { | ||
if( BEAST.DEBUG ) { | ||
CFonts.say(text, { | ||
'font': 'chrome', | ||
'align': 'center', | ||
'colors': ['green', 'cyan', 'white'], | ||
}); | ||
} | ||
}, | ||
|
||
report: ( text, level = 99 ) => { | ||
if( BEAST.DEBUG && level >= BEAST.DEBUGLEVEL ) { | ||
console.log(Chalk.bgWhite(`\n${Chalk.bold.green(' \u2611 ')} ${Chalk.black(`${text} `)}`)); | ||
} | ||
}, | ||
|
||
error: ( text, level = 99 ) => { | ||
if( BEAST.DEBUG && level >= BEAST.DEBUGLEVEL ) { | ||
console.log(Chalk.bgWhite(`\n${Chalk.red(' \u2612 ')} ${Chalk.black(`${text} `)}`)); | ||
} | ||
}, | ||
|
||
interaction: ( text, level = 99 ) => { | ||
if( BEAST.DEBUG && level >= BEAST.DEBUGLEVEL ) { | ||
console.log(Chalk.bgWhite(`\n${Chalk.blue(' \u261C ')} ${Chalk.black(`${text} `)}`)); | ||
} | ||
}, | ||
|
||
send: ( text, level = 99 ) => { | ||
if( BEAST.DEBUG && level >= BEAST.DEBUGLEVEL ) { | ||
console.log(Chalk.bgWhite(`\n${Chalk.bold.cyan(' \u219D ')} ${Chalk.black(`${text} `)}`)); | ||
} | ||
}, | ||
|
||
received: ( text, level = 99 ) => { | ||
if( BEAST.DEBUG && level >= BEAST.DEBUGLEVEL ) { | ||
console.log(Chalk.bgWhite(`\n${Chalk.bold.cyan(' \u219C ')} ${Chalk.black(`${text} `)}`)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
})(); |
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/*************************************************************************************************************************************************************** | ||
* | ||
* Scaffolding | ||
* | ||
* Scaffold the game canvas | ||
* | ||
**************************************************************************************************************************************************************/ | ||
|
||
|
||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
// Dependencies | ||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
|
||
|
||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
// Module | ||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
BEAST.scaffolding = (() => { | ||
|
||
return { | ||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
// Public function | ||
// init, Scaffold the canvas | ||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
init: () => { | ||
BEAST.debugging.report(`scaffolding: init`, 1); | ||
|
||
BEAST.HERO = { | ||
x: BEAST.START.x, | ||
y: BEAST.START.y, | ||
}; | ||
|
||
BEAST.scaffolding.cords(); //we need to fill the BEAST.BOARD with empty arrays | ||
BEAST.scaffolding.beasts(); //add beasts | ||
BEAST.scaffolding.element( 'block' ); //add blocks to BEAST.BOARD | ||
BEAST.scaffolding.element( 'solid' ); //add solids to BEAST.BOARD | ||
BEAST.scaffolding.hero(); //last but not least we need the hero | ||
}, | ||
|
||
|
||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
// Public function | ||
// cords, Scaffold the coordinates for the board | ||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
cords: () => { | ||
BEAST.debugging.report(`scaffolding: cords`, 1); | ||
|
||
for(let i = 0; i < ( BEAST.MINHEIGHT - 7 ); i++) { | ||
BEAST.BOARD[ i ] = []; //add array per row | ||
}; | ||
}, | ||
|
||
|
||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
// Public function | ||
// hero, Scaffold the hero onto the board | ||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
hero: () => { | ||
BEAST.debugging.report(`scaffolding: hero`, 1); | ||
|
||
BEAST.BOARD[ BEAST.HERO.y ][ BEAST.HERO.x ] = 'hero' //add the hero his/her starting position | ||
}, | ||
|
||
|
||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
// Public function | ||
// beasts, Scaffold beasts onto the board | ||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
beasts: () => { | ||
BEAST.debugging.report(`scaffolding: beasts`, 1); | ||
|
||
let beasts = 0; //keep track of the beasts we distribute | ||
BEAST.BEASTS = []; | ||
|
||
while( beasts < BEAST.LEVELS[ BEAST.LEVEL ]['beast'] ) { | ||
let randomX = Math.floor( Math.random() * ((BEAST.MINWIDTH - 2) - ( BEAST.MINWIDTH / 2 )) + ( BEAST.MINWIDTH / 2 ) ); | ||
let randomY = Math.floor( Math.random() * (((BEAST.MINHEIGHT - 7) / 2) - 0) + 0 ); | ||
|
||
if( BEAST.BOARD[ randomY ][ randomX ] === undefined ) { //no other elements on the spot | ||
BEAST.BOARD[ randomY ][ randomX ] = 'beast'; //adding beast onto board | ||
|
||
BEAST.BEASTS[`${randomX}-${randomY}`] = { //adding beast to beast registry | ||
x: randomX, | ||
y: randomY, | ||
} | ||
|
||
beasts ++; | ||
} | ||
} | ||
}, | ||
|
||
|
||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
// Public function | ||
// element, Randomly create and distribute elements on the board | ||
// | ||
// @param element {keyword} We can only scaffold 'beast', 'block', 'solid' | ||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
element: ( element ) => { | ||
BEAST.debugging.report(`scaffolding: blocks`, 1); | ||
|
||
let count = 0; //keep track of elements we distribute | ||
|
||
while( count < BEAST.LEVELS[ BEAST.LEVEL ][ element ] ) { | ||
let randomX = Math.floor( Math.random() * ((BEAST.MINWIDTH - 2) - 0 ) + 0 ); | ||
let randomY = Math.floor( Math.random() * ((BEAST.MINHEIGHT - 7) - 0 ) + 0 ); | ||
|
||
if( | ||
randomY + '-' + randomX != ( BEAST.HERO.y + 1 ) + '-' + ( BEAST.HERO.x - 1 ) && //row after one column before | ||
randomY + '-' + randomX != ( BEAST.HERO.y + 1 ) + '-' + ( BEAST.HERO.x ) && //row after | ||
randomY + '-' + randomX != ( BEAST.HERO.y + 1 ) + '-' + ( BEAST.HERO.x + 1 ) && //row after one column after | ||
|
||
randomY + '-' + randomX != BEAST.HERO.y + '-' + ( BEAST.HERO.x - 1 ) && //same row one column before | ||
randomY + '-' + randomX != BEAST.HERO.y + '-' + BEAST.HERO.x && //hero position | ||
randomY + '-' + randomX != BEAST.HERO.y + '-' + ( BEAST.HERO.x + 1 ) && //same row one column after | ||
|
||
randomY + '-' + randomX != ( BEAST.HERO.y - 1 ) + '-' + ( BEAST.HERO.x - 1 ) && //row before one column before | ||
randomY + '-' + randomX != ( BEAST.HERO.y - 1 ) + '-' + ( BEAST.HERO.x ) && //row before | ||
randomY + '-' + randomX != ( BEAST.HERO.y - 1 ) + '-' + ( BEAST.HERO.x + 1 ) && //row before one column after | ||
|
||
BEAST.BOARD[ randomY ][ randomX ] === undefined //no other elements on the spot | ||
) { | ||
BEAST.BOARD[ randomY ][ randomX ] = element; | ||
count ++; | ||
} | ||
} | ||
}, | ||
} | ||
})(); |
Oops, something went wrong.