Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikwilkowski committed Oct 16, 2016
2 parents 830f307 + 3bd7655 commit 0522f38
Show file tree
Hide file tree
Showing 12 changed files with 3,007 additions and 9 deletions.
50 changes: 46 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,65 @@
╚═╝ ╚═╝ ╩ ╩ ╚═╝ ╩
```

[![NPM](https://nodei.co/npm/beast.js.png?downloads=true)](https://nodei.co/npm/beast.js/)
![The beast game](https://raw.githubusercontent.com/dominikwilkowski/beast.js/master/assets/play.gif)

> BEAST.js is an homage to the 1984 ASCII game "[BEAST](https://en.wikipedia.org/wiki/Beast_(video_game))" from Dan Baker, Alan Brown, Mark Hamilton and
> Derrick Shadel written in node.
> TODO
# Beast.js

- [How to install](#how-to-install)
- [How to play](#how-to-play)
- [Contributing](#contributing)
- [Test](#test)
- [Release History](#release-history)
- [License](#license)


## How to install

Download the game from this repo and install it's dependencies via:

```shell
npm i
```

or

```
yarn
```

Then run:

```shell
npm start
```


## How to play

The goal is to squash all beasts in each level. To squash a beast between two or more blocks. Press `q` to quit.


## Contributing

Please look at the coding style and work with it, not against it ;)
Run grunt to build and watch the project. _(gulp coming)_

```shell
grunt
```


## Test

TODO


## Release History
* 0.1.0 - alpha test
* 0.1.0 - alpha release


## License
Copyright (c) 2016 Dominik Wilkowski. Licensed under the [GNU GPLv3](https://github.com/dominikwilkowski/beast.js/blob/master/LICENSE).
Copyright (c) Dominik Wilkowski. Licensed under the [GNU GPLv3](https://github.com/dominikwilkowski/beast.js/blob/master/LICENSE).
Binary file added assets/play.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
157 changes: 157 additions & 0 deletions dev/010-constructor.js
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 removed dev/010-init.js
Empty file.
129 changes: 129 additions & 0 deletions dev/020-scaffolding.js
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 ++;
}
}
},
}
})();
Loading

0 comments on commit 0522f38

Please sign in to comment.