Alec 4 years ago
commit 6dca957391

@ -15,14 +15,14 @@ const template = `
<td class="scoreboard_data">progress</td>
</tr>
<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_progress}}</td>
<td class="scoreboard_data">{{player_one_progress * 100}}%</td>
</tr>
<tr class="scoreboard_lastRow">
<td class="scoreboard_player">player_2</td>
<td class="scoreboard_data">{{player_one_score}}</td>
<td class="scoreboard_data">{{player_two_progress}}</td>
<td class="scoreboard_player">Player 2</td>
<td class="scoreboard_data">{{player_two_score}}</td>
<td class="scoreboard_data">{{player_two_progress * 100}}%</td>
</tr>
</table>
</div>

@ -170,12 +170,14 @@ export default class TopLevelComponent extends Component {
* @param {number} 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
setTimeout(() => {
game_service.advance_game_state()
}, 5000)
// Give the user time to see whether they hit or not
setTimeout(() => {
game_service.advance_game_state()
}, 5000)
}
}
/**

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

Loading…
Cancel
Save