Skip to content

Commit

Permalink
fixed #1, Added level indicator
Browse files Browse the repository at this point in the history
Signed-off-by: Dominik Wilkowski <[email protected]>
  • Loading branch information
dominikwilkowski committed Oct 17, 2016
1 parent 3bd7655 commit 0872c9b
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ temp
.sass-cache
.idea
validation-report.json
validation-status.json
validation-status.json
yarn.lock
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ yarn
Then run:

```shell
npm start
node prod/index.js
```


Expand All @@ -61,6 +61,7 @@ TODO


## Release History
* 0.1.1 - Added level indicator, fixed lives display
* 0.1.0 - alpha release


Expand Down
8 changes: 7 additions & 1 deletion dev/010-constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,17 @@ const BEAST = (() => { //constructor factory
},
2: { //increase beasts and solids, decrease blocks
beast: 3,
block: 400,
solid: 100,
speed: 1000,
},
3: { //increase beasts and solids, decrease blocks
beast: 5,
block: 350,
solid: 200,
speed: 1000,
},
3: { //increase beasts and solids, decrease blocks and speed
4: { //increase beasts and solids, decrease blocks and speed
beast: 10,
block: 100,
solid: 500,
Expand Down
38 changes: 36 additions & 2 deletions dev/030-draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,11 @@ BEAST.draw = (() => {
// score, Draw the score at the bottom of the frame
//--------------------------------------------------------------------------------------------------------------------------------------------------------------
score: () => {
BEAST.debugging.report(`draw: score`, 1);

customStdout.muted = false;

//testing screen size and just printing on error
//testing screen size
let error = BEAST.checkSize();
if( error === '' ) {
let top = Math.floor( ( CliSize().rows - BEAST.MINHEIGHT ) / 2 );
Expand All @@ -101,7 +103,11 @@ BEAST.draw = (() => {
//calculate the space between lives and beast count
let spaceMiddle = ( BEAST.MINWIDTH - 2 ) - ( 3 * BEAST.LIVES ) - 6 - ( Object.keys( BEAST.BEASTS ).length.toString().length );

BEAST.RL.write(`${spaceLeft}${Chalk.red(' ❤').repeat( BEAST.LIVES - BEAST.DEATHS )}${Chalk.gray(' ❤').repeat( BEAST.DEATHS )}`);
BEAST.RL.write(
`${spaceLeft}${Chalk.red(` ${BEAST.SYMBOLS.hero}`).repeat( BEAST.LIVES - BEAST.DEATHS )}` +
`${Chalk.gray(` ${BEAST.SYMBOLS.hero}`).repeat( BEAST.DEATHS )}`
);

BEAST.RL.write(`${' '.repeat( spaceMiddle )} ${ Object.keys( BEAST.BEASTS ).length } x ${BEAST.SYMBOLS.beast}`);

Readline.cursorTo( BEAST.RL, 0, (CliSize().rows - 1) ); //go to bottom of board and rest cursor there
Expand All @@ -111,6 +117,33 @@ BEAST.draw = (() => {
},


//--------------------------------------------------------------------------------------------------------------------------------------------------------------
// Public function
// level, Draw the score at the bottom of the frame
//--------------------------------------------------------------------------------------------------------------------------------------------------------------
level: () => {
BEAST.debugging.report(`draw: level`, 1);

customStdout.muted = false;

//testing screen size
let error = BEAST.checkSize();
if( error === '' ) {
let top = Math.floor( ( CliSize().rows - BEAST.MINHEIGHT ) / 2 );
let spaceLeft = Math.floor( ( CliSize().columns - BEAST.MINWIDTH ) / 2 ); //horizontal alignment
let spaceMiddle = ( BEAST.MINWIDTH - 2 ) - 9 - ( Object.keys( BEAST.LEVEL ).length.toString().length ); //calculate the space so we can right align

Readline.cursorTo( BEAST.RL, (spaceLeft + spaceMiddle), (top + 2) ); //go to top above the board and right align

BEAST.RL.write(` Level: ${BEAST.LEVEL}`);

Readline.cursorTo( BEAST.RL, 0, (CliSize().rows - 1) ); //go to bottom of board and rest cursor there
}

customStdout.muted = true;
},


//--------------------------------------------------------------------------------------------------------------------------------------------------------------
// Public function
// board, Drawing the board
Expand Down Expand Up @@ -186,6 +219,7 @@ BEAST.draw = (() => {

BEAST.draw.frame(); //draw frame,
BEAST.draw.score(); //draw score,
BEAST.draw.level(); //draw level,
BEAST.draw.board(); //draw board, I mean the function names are kinda obvious so this comment really doesn't help much.
},
}
Expand Down
46 changes: 43 additions & 3 deletions dev/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,17 @@ const BEAST = (() => { //constructor factory
},
2: { //increase beasts and solids, decrease blocks
beast: 3,
block: 400,
solid: 100,
speed: 1000,
},
3: { //increase beasts and solids, decrease blocks
beast: 5,
block: 350,
solid: 200,
speed: 1000,
},
3: { //increase beasts and solids, decrease blocks and speed
4: { //increase beasts and solids, decrease blocks and speed
beast: 10,
block: 100,
solid: 500,
Expand Down Expand Up @@ -373,9 +379,11 @@ BEAST.draw = (() => {
// score, Draw the score at the bottom of the frame
//--------------------------------------------------------------------------------------------------------------------------------------------------------------
score: () => {
BEAST.debugging.report(`draw: score`, 1);

customStdout.muted = false;

//testing screen size and just printing on error
//testing screen size
let error = BEAST.checkSize();
if( error === '' ) {
let top = Math.floor( ( CliSize().rows - BEAST.MINHEIGHT ) / 2 );
Expand All @@ -387,7 +395,11 @@ BEAST.draw = (() => {
//calculate the space between lives and beast count
let spaceMiddle = ( BEAST.MINWIDTH - 2 ) - ( 3 * BEAST.LIVES ) - 6 - ( Object.keys( BEAST.BEASTS ).length.toString().length );

BEAST.RL.write(`${spaceLeft}${Chalk.red(' ❤').repeat( BEAST.LIVES - BEAST.DEATHS )}${Chalk.gray(' ❤').repeat( BEAST.DEATHS )}`);
BEAST.RL.write(
`${spaceLeft}${Chalk.red(` ${BEAST.SYMBOLS.hero}`).repeat( BEAST.LIVES - BEAST.DEATHS )}` +
`${Chalk.gray(` ${BEAST.SYMBOLS.hero}`).repeat( BEAST.DEATHS )}`
);

BEAST.RL.write(`${' '.repeat( spaceMiddle )} ${ Object.keys( BEAST.BEASTS ).length } x ${BEAST.SYMBOLS.beast}`);

Readline.cursorTo( BEAST.RL, 0, (CliSize().rows - 1) ); //go to bottom of board and rest cursor there
Expand All @@ -397,6 +409,33 @@ BEAST.draw = (() => {
},


//--------------------------------------------------------------------------------------------------------------------------------------------------------------
// Public function
// level, Draw the score at the bottom of the frame
//--------------------------------------------------------------------------------------------------------------------------------------------------------------
level: () => {
BEAST.debugging.report(`draw: level`, 1);

customStdout.muted = false;

//testing screen size
let error = BEAST.checkSize();
if( error === '' ) {
let top = Math.floor( ( CliSize().rows - BEAST.MINHEIGHT ) / 2 );
let spaceLeft = Math.floor( ( CliSize().columns - BEAST.MINWIDTH ) / 2 ); //horizontal alignment
let spaceMiddle = ( BEAST.MINWIDTH - 2 ) - 9 - ( Object.keys( BEAST.LEVEL ).length.toString().length ); //calculate the space so we can right align

Readline.cursorTo( BEAST.RL, (spaceLeft + spaceMiddle), (top + 2) ); //go to top above the board and right align

BEAST.RL.write(` Level: ${BEAST.LEVEL}`);

Readline.cursorTo( BEAST.RL, 0, (CliSize().rows - 1) ); //go to bottom of board and rest cursor there
}

customStdout.muted = true;
},


//--------------------------------------------------------------------------------------------------------------------------------------------------------------
// Public function
// board, Drawing the board
Expand Down Expand Up @@ -472,6 +511,7 @@ BEAST.draw = (() => {

BEAST.draw.frame(); //draw frame,
BEAST.draw.score(); //draw score,
BEAST.draw.level(); //draw level,
BEAST.draw.board(); //draw board, I mean the function names are kinda obvious so this comment really doesn't help much.
},
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "beast.js",
"description": "ANSI Beast for node",
"version": "0.1.0",
"version": "0.1.1",
"homepage": "https://github.com/dominikwilkowski/beast.js",
"author": {
"name": "Dominik Wilkowski",
Expand Down
46 changes: 43 additions & 3 deletions prod/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,17 @@ const BEAST = (() => { //constructor factory
},
2: { //increase beasts and solids, decrease blocks
beast: 3,
block: 400,
solid: 100,
speed: 1000,
},
3: { //increase beasts and solids, decrease blocks
beast: 5,
block: 350,
solid: 200,
speed: 1000,
},
3: { //increase beasts and solids, decrease blocks and speed
4: { //increase beasts and solids, decrease blocks and speed
beast: 10,
block: 100,
solid: 500,
Expand Down Expand Up @@ -373,9 +379,11 @@ BEAST.draw = (() => {
// score, Draw the score at the bottom of the frame
//--------------------------------------------------------------------------------------------------------------------------------------------------------------
score: () => {
BEAST.debugging.report(`draw: score`, 1);

customStdout.muted = false;

//testing screen size and just printing on error
//testing screen size
let error = BEAST.checkSize();
if( error === '' ) {
let top = Math.floor( ( CliSize().rows - BEAST.MINHEIGHT ) / 2 );
Expand All @@ -387,7 +395,11 @@ BEAST.draw = (() => {
//calculate the space between lives and beast count
let spaceMiddle = ( BEAST.MINWIDTH - 2 ) - ( 3 * BEAST.LIVES ) - 6 - ( Object.keys( BEAST.BEASTS ).length.toString().length );

BEAST.RL.write(`${spaceLeft}${Chalk.red(' ❤').repeat( BEAST.LIVES - BEAST.DEATHS )}${Chalk.gray(' ❤').repeat( BEAST.DEATHS )}`);
BEAST.RL.write(
`${spaceLeft}${Chalk.red(` ${BEAST.SYMBOLS.hero}`).repeat( BEAST.LIVES - BEAST.DEATHS )}` +
`${Chalk.gray(` ${BEAST.SYMBOLS.hero}`).repeat( BEAST.DEATHS )}`
);

BEAST.RL.write(`${' '.repeat( spaceMiddle )} ${ Object.keys( BEAST.BEASTS ).length } x ${BEAST.SYMBOLS.beast}`);

Readline.cursorTo( BEAST.RL, 0, (CliSize().rows - 1) ); //go to bottom of board and rest cursor there
Expand All @@ -397,6 +409,33 @@ BEAST.draw = (() => {
},


//--------------------------------------------------------------------------------------------------------------------------------------------------------------
// Public function
// level, Draw the score at the bottom of the frame
//--------------------------------------------------------------------------------------------------------------------------------------------------------------
level: () => {
BEAST.debugging.report(`draw: level`, 1);

customStdout.muted = false;

//testing screen size
let error = BEAST.checkSize();
if( error === '' ) {
let top = Math.floor( ( CliSize().rows - BEAST.MINHEIGHT ) / 2 );
let spaceLeft = Math.floor( ( CliSize().columns - BEAST.MINWIDTH ) / 2 ); //horizontal alignment
let spaceMiddle = ( BEAST.MINWIDTH - 2 ) - 9 - ( Object.keys( BEAST.LEVEL ).length.toString().length ); //calculate the space so we can right align

Readline.cursorTo( BEAST.RL, (spaceLeft + spaceMiddle), (top + 2) ); //go to top above the board and right align

BEAST.RL.write(` Level: ${BEAST.LEVEL}`);

Readline.cursorTo( BEAST.RL, 0, (CliSize().rows - 1) ); //go to bottom of board and rest cursor there
}

customStdout.muted = true;
},


//--------------------------------------------------------------------------------------------------------------------------------------------------------------
// Public function
// board, Drawing the board
Expand Down Expand Up @@ -472,6 +511,7 @@ BEAST.draw = (() => {

BEAST.draw.frame(); //draw frame,
BEAST.draw.score(); //draw score,
BEAST.draw.level(); //draw level,
BEAST.draw.board(); //draw board, I mean the function names are kinda obvious so this comment really doesn't help much.
},
}
Expand Down

0 comments on commit 0872c9b

Please sign in to comment.