Alec 4 years ago
commit 6dca957391

@ -15,14 +15,14 @@ const template = `
<td class="scoreboard_data">progress</td> <td class="scoreboard_data">progress</td>
</tr> </tr>
<tr class="scoreboard_rows_score&progress"> <tr class="scoreboard_rows_score&progress">
<td class="scoreboard_player">player_1</td> <td class="scoreboard_player">Player 1</td>
<td class="scoreboard_data">{{player_one_score}}</td> <td class="scoreboard_data">{{player_one_score}}</td>
<td class="scoreboard_data">{{player_one_progress}}</td> <td class="scoreboard_data">{{player_one_progress * 100}}%</td>
</tr> </tr>
<tr class="scoreboard_lastRow"> <tr class="scoreboard_lastRow">
<td class="scoreboard_player">player_2</td> <td class="scoreboard_player">Player 2</td>
<td class="scoreboard_data">{{player_one_score}}</td> <td class="scoreboard_data">{{player_two_score}}</td>
<td class="scoreboard_data">{{player_two_progress}}</td> <td class="scoreboard_data">{{player_two_progress * 100}}%</td>
</tr> </tr>
</table> </table>
</div> </div>

@ -170,12 +170,14 @@ export default class TopLevelComponent extends Component {
* @param {number} column_index * @param {number} column_index
*/ */
on_missile_fired([row_index, column_index]) { on_missile_fired([row_index, column_index]) {
game_service.attempt_missile_fire([row_index, column_index]) if ( this.player_is_firing_missiles ) {
game_service.attempt_missile_fire([row_index, column_index])
// Give the user time to see whether they hit or not // Give the user time to see whether they hit or not
setTimeout(() => { setTimeout(() => {
game_service.advance_game_state() game_service.advance_game_state()
}, 5000) }, 5000)
}
} }
/** /**

@ -214,21 +214,16 @@ export class GameStateService {
* @private * @private
*/ */
get_player_score(player) { get_player_score(player) {
let i = 1; let score = 0
let j = 1; this.player_x_game_board[player].some(row => {
let score = 0; row.some(cell => {
for(i; i<=8; i++) if ( cell.render === GridCellState.Damaged || cell.render === GridCellState.Sunk ) {
{ score += 1
for(j; j<=8; j++)
{
let cell = this.player_x_game_board[this.get_other_player(player)][i][j];
if(cell.render === GridCellState.Damaged || cell.render === GridCellState.Sunk )
{
score++;
} }
} })
} })
return(score);
return score
} }
/** /**
@ -238,21 +233,16 @@ export class GameStateService {
* @private * @private
*/ */
get_boat_count(player){ get_boat_count(player){
let i = 1; let boat_count = 0
let j = 1; this.player_x_game_board[player].some(row => {
let boat_count = 0; row.some(cell => {
for(i; i<=8; i++) if ( isShipCell(cell.render) ) {
{ boat_count += 1
for(j; j<=8; j++)
{
let cell = this.player_x_game_board[this.get_other_player(player)][i][j];
if(cell.render === GridCellState.Damaged || cell.render === GridCellState.Sunk || cell.render === GridCellState.Ship )
{
boat_count++;
} }
} })
} })
return(boat_count);
return boat_count
} }
/** /**
@ -261,7 +251,12 @@ export class GameStateService {
* @private * @private
*/ */
get_progress(player){ get_progress(player){
return(this.get_player_score(player) / this.get_boat_count(player)) const boat_count = this.get_boat_count(player)
if ( boat_count !== 0 ) {
return (this.get_player_score(player) / boat_count).toFixed(2)
} else {
return 0
}
} }
/** /**
@ -359,6 +354,7 @@ export class GameStateService {
if(winner) { if(winner) {
this.current_state = GameState.PlayerVictory; this.current_state = GameState.PlayerVictory;
this.current_player = winner; this.current_player = winner;
this.current_opponent = this.get_other_player(winner);
} }
this.current_turn_had_missile_attempt = false this.current_turn_had_missile_attempt = false

Loading…
Cancel
Save