Example #1
0
		board: () => {
			BEAST.debugging.report(`draw: board`, 1);

			customStdout.muted = false; //allow output so we can draw

			let spaceTop = Math.floor( getSpaceTop() );
			let spaceLeft = getSpaceLeft();

			Readline.cursorTo( BEAST.RL, 0, (spaceTop + 4) ); //go to top of board

			for(let boardRow of BEAST.BOARD) { //iterate over each row
				let line = ''; //translate BEAST.BOARD to ASCII

				for(let x = 0; x < ( BEAST.MINWIDTH - 2 ); x++) { //iterate over each column in this row
					let element = BEAST.SYMBOLS[ boardRow[ x ] ]; //get the symbol for the element we found

					if( element ) { //if there was an element found
						line += element;
					}
					else { //add space
						line += ' ';
					}
				}

				Readline.moveCursor(BEAST.RL, spaceLeft, 0); //move cursor into board
				BEAST.RL.write(`${line}\n`); //print line inside the frame
			}

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

			customStdout.muted = true; //no more user output now!
		},
Example #2
0
		message: ( message, color = 'black' ) => {
			customStdout.muted = false; //allow output so we can draw

			let spaceTop = Math.floor( getSpaceTop() );
			let spaceLeft = getSpaceLeft(); //space left from frame

			Readline.cursorTo( BEAST.RL, spaceLeft, (spaceTop + 4 + Math.floor( ( BEAST.MINHEIGHT - 7 ) / 2 ) - 2) ); //go to middle of board

			let space = ( (BEAST.MINWIDTH - 2) / 2 ) - ( (message.length + 2) / 2 ); //rest space minus the message length
			let spaceMiddleLeft = Math.floor( space );
			let spaceMiddleRight = Math.ceil( space );

			BEAST.RL.write(`${' '.repeat( BEAST.MINWIDTH - 2 )}\n`); //clear line
			Readline.moveCursor(BEAST.RL, spaceLeft, 0);             //move cursor into board
			BEAST.RL.write(`${' '.repeat( BEAST.MINWIDTH - 2 )}\n`); //clear line
			Readline.moveCursor(BEAST.RL, spaceLeft, 0);             //move cursor into board
			BEAST.RL.write(`${' '.repeat( spaceMiddleLeft )}${Chalk[ color ].bgWhite.bold(` ${message} `)}${' '.repeat( spaceMiddleRight )}\n`);
			Readline.moveCursor(BEAST.RL, spaceLeft, 0);             //move cursor into board
			BEAST.RL.write(`${' '.repeat( BEAST.MINWIDTH - 2 )}\n`); //clear line
			Readline.moveCursor(BEAST.RL, spaceLeft, 0);             //move cursor into board
			BEAST.RL.write(`${' '.repeat( BEAST.MINWIDTH - 2 )}\n`); //clear line

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

			customStdout.muted = true; //no more user output now!
		},
Example #3
0
		score: () => {
			BEAST.debugging.report(`draw: score`, 1);

			customStdout.muted = false; //allow output so we can draw

			//testing screen size
			let error = BEAST.checkSize();
			if( error === '' ) {
				let spaceTop = Math.floor( getSpaceTop() );
				let spaceLeft = getSpaceLeft();

				Readline.cursorTo( BEAST.RL, spaceLeft, (spaceTop + 4 + ( BEAST.MINHEIGHT - 6 )) ); //go to bottom of board

				//calculate the space between lives and beast count
				let spaceMiddle = ( BEAST.MINWIDTH - 2 ) - ( 3 * BEAST.LIVES ) - 3 - ( Object.keys( BEAST.BEASTS ).length.toString().length );

				BEAST.RL.write(
					`${Chalk.cyan(` ${BEAST.SYMBOLS.lives}`).repeat( BEAST.LIVES - BEAST.DEATHS )}` +
					`${Chalk.gray(` ${BEAST.SYMBOLS.lives}`).repeat( BEAST.DEATHS )}` +
					`${' '.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
			}

			customStdout.muted = true; //no more user output now!
		},
Example #4
0
	const getSpaceTop = ( item ) => {
		BEAST.debugging.report(`draw: getSpaceTop`, 1);

		let spacetop = ( CliSize().rows - BEAST.MINHEIGHT ) / 2; //vertically alignment

		return spacetop
	}
Example #5
0
	const getSpaceLeft = ( item ) => {
		BEAST.debugging.report(`draw: getSpaceLeft`, 1);

		let spaceLeft = Math.floor( ( CliSize().columns - BEAST.MINWIDTH ) / 2 ) + 1; //horizontal alignment

		return spaceLeft
	}
Example #6
0
BEAST.checkSize = () => {
	BEAST.debugging.report(`Running checkSize`, 1);

	let error = ''; //undefined is overrated

	if( CliSize().columns < ( BEAST.MINWIDTH + 4 ) || CliSize().rows < ( BEAST.MINHEIGHT + 1 ) ) {

		if( CliSize().columns < ( BEAST.MINWIDTH + 4 ) ) {
			error = `\n  Your console window is not wide enough for this game\n` +
				`  Please resize your window to at least ${( BEAST.MINWIDTH + 4 )} x ${( BEAST.MINHEIGHT + 1 )}\n` +
				`  (It is ${CliSize().columns} x ${CliSize().rows})\n`;
		}

		if( CliSize().rows < ( BEAST.MINHEIGHT + 1 ) ) {
			error = `\n  Your console window is not tall enough for this game\n` +
				`  Please resize your window to at least ${( BEAST.MINWIDTH + 4 )} x ${( BEAST.MINHEIGHT + 1 )}\n` +
				`  (It is ${CliSize().columns} x ${CliSize().rows})\n`;
		}
	}

	return error;
}
Example #7
0
		level: () => {
			BEAST.debugging.report(`draw: level`, 1);

			customStdout.muted = false; //allow output so we can draw

			//testing screen size
			let error = BEAST.checkSize();
			if( error === '' ) {
				let spaceTop = Math.floor( getSpaceTop() );
				let spaceLeft = getSpaceLeft(); //horizontal alignment
				let spaceMiddle = ( BEAST.MINWIDTH - 2 ) - 10 - ( Object.keys( BEAST.LEVEL ).length.toString().length ); //calculate the space so we can right align

				Readline.cursorTo( BEAST.RL, (spaceLeft + spaceMiddle), (spaceTop + 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; //no more user output now!
		},
Example #8
0
let setSize = size => {
    size = size || cliSize();
    CliUpdate.columns = size.columns;
    CliUpdate.rows = size.rows;
};