lib/game-state-renderer.js
/**
     * Prints the current game state to standard output.
     */
Prints the current game state to standard output.
Prints the current game state to standard output .
render() {
        let output = ''
        this.game.doorStates.forEach((isDoorOpen, index) => {
            output += this.doorsRepo.getDoorNameFromIndex(index) + '\t'
        })
        output += '\n'
        this.game.doorStates.forEach((isDoorOpen, index) => {
            if (!isDoorOpen) {
                output += this.symbols.door + '\t'
                return
            }
            const symbol = index === this.game.carPos
                ? this.symbols.car
                : this.symbols.goat
            output += (symbol) + '\t'
        })
        output += '\n'
        this.game.doorStates.forEach((isDoorOpen, index) => {
            const playerSymbol = index === this.game.playerPos
                ? this.symbols.player
                : ' '
            output += playerSymbol + '\t'
        })
        console.log(output + '\n')
        if (this.game.state === Game.State.STATE_END_WON) {
            const message = TextIo.padToFullWidth(this.texts.wonMessage, 6)
            console.log(chalk.bold.black.bgGreen(message))
            TextIo.dnl()
        } else if (this.game.state === Game.State.STATE_END_LOST) {
            const message = TextIo.padToFullWidth(this.texts.lostMessage, 1)
            console.log(chalk.bold.white.bgBlack(message))
            TextIo.dnl()
        }
    }
render ( ) { let output = '' this . game . doorStates . forEach ( ( isDoorOpen , index ) => { output += this . doorsRepo . getDoorNameFromIndex ( index ) + '\t' } ) output += '\n' this . game . doorStates . forEach ( ( isDoorOpen , index ) => { if ( ! isDoorOpen ) { output += this . symbols . door + '\t' return } const symbol = index === this . game . carPos ? this . symbols . car : this . symbols . goat output += ( symbol ) + '\t' } ) output += '\n' this . game . doorStates . forEach ( ( isDoorOpen , index ) => { const playerSymbol = index === this . game . playerPos ? this . symbols . player : ' ' output += playerSymbol + '\t' } ) console . log ( output + '\n' ) if ( this . game . state === Game . State . STATE_END_WON ) { const message = TextIo . padToFullWidth ( this . texts . wonMessage , 6 ) console . log ( chalk . bold . black . bgGreen ( message ) ) TextIo . dnl ( ) } else if ( this . game . state === Game . State . STATE_END_LOST ) { const message = TextIo . padToFullWidth ( this . texts . lostMessage , 1 ) console . log ( chalk . bold . white . bgBlack ( message ) ) TextIo . dnl ( ) } }
Prints the current game state to standard output.
Prints the current game state to standard output .
//	process.stdout.write('\033c');