added a get player score helper method(#2)

issue-2
Evan Powell 4 years ago
parent ed5eaf0d55
commit 4463e804f4

@ -138,6 +138,30 @@ export class GameStateService {
})
})
}
/**
* get the "score" (the number of hits) that the
* current player has (counting sunk ships)
* @return {number}
* @private
*/
get_player_score () {
let i = 1;
let j = 1;
let score = 0;
for(i; i<=9; i++)
{
for(j; j<=9; j++)
{
let cell = this.player_x_game_board[this.current_opponent][i][j];
if(cell.render === GridCellState.Damaged || cell.render === GridCellState.Sunk )
{
score++;
}
}
}
return(score);
}
}
// Export a single instance, so it can be shared by all files

Loading…
Cancel
Save