game.js
// Track score for each player by increasing increment in the ships.hits property until that value equals the lenght of the ship which then adds to the player's score property
Track score for each player by increasing increment in the ships.hits property until that value equals the lenght of the ship which then adds to the player's score property
Track score for each player by increasing increment in the ships . hits property until that value equals the lenght of the ship which then adds to the player ' s score property
trackScore(ships, destroyedShips, internalBoard, rowIndex, columnIndex, currentPlayer, opposingPlayer) {
		for (let i = 0; i < ships.length; i++) {
			if (internalBoard[rowIndex][columnIndex] === this.addColor(Color.BgCyan + Color.FgBlack, ships[i].initials, Color.Reset)) {
				ships[i].hits++;
				if (ships[i].hits === ships[i].size) {
					if (destroyedShips.length === 0) {
						destroyedShips.push(ships[i].name);
					}
					else if (destroyedShips.length > 0) {
						destroyedShips.push(" " + ships[i].name);
					}
					currentPlayer.score++;
					console.log(this.addColor(Color.Bright, "You sunk ", Color.Reset) + this.addColor(Color.Bright + opposingPlayer.color, opposingPlayer.name, Color.Reset) + this.addColor(Color.Bright, "'s " + ships[i].name, Color.Reset + "!"));
				}
			}
		}
		if (destroyedShips.length > 0) {
			console.log("Ships you have destroyed: " + destroyedShips);
		}
		else {
			console.log("Ships you have destroyed: none");
		}
	}
trackScore ( ships , destroyedShips , internalBoard , rowIndex , columnIndex , currentPlayer , opposingPlayer ) { for ( let i = 0 ; i < ships . length ; i ++ ) { if ( internalBoard [ rowIndex ] [ columnIndex ] === this . addColor ( Color . BgCyan + Color . FgBlack , ships [ i ] . initials , Color . Reset ) ) { ships [ i ] . hits ++ ; if ( ships [ i ] . hits === ships [ i ] . size ) { if ( destroyedShips . length === 0 ) { destroyedShips . push ( ships [ i ] . name ) ; } else if ( destroyedShips . length > 0 ) { destroyedShips . push ( " " + ships [ i ] . name ) ; } currentPlayer . score ++ ; console . log ( this . addColor ( Color . Bright , "You sunk " , Color . Reset ) + this . addColor ( Color . Bright + opposingPlayer . color , opposingPlayer . name , Color . Reset ) + this . addColor ( Color . Bright , "'s " + ships [ i ] . name , Color . Reset + "!" ) ) ; } } } if ( destroyedShips . length > 0 ) { console . log ( "Ships you have destroyed: " + destroyedShips ) ; } else { console . log ( "Ships you have destroyed: none" ) ; } }
Track score for each player by increasing increment in the ships.hits property until that value equals the lenght of the ship which then adds to the player's score property
Track score for each player by increasing increment in the ships . hits property until that value equals the lenght of the ship which then adds to the player ' s score property