Get possible boats to add #1}

master
Alec 4 years ago
parent 8ee2a8252b
commit 7f460b2324

@ -55,12 +55,20 @@ export default class GameBoardComponent extends Component {
*/ */
// rows = [] // rows = []
column_labels = ["A", "B", "C", "D", "E", "F", "G", "H", "I"] column_labels = ["A", "B", "C", "D", "E", "F", "G", "H", "I"]
<<<<<<< Updated upstream
=======
>>>>>>> Stashed changes
async vue_on_create() { async vue_on_create() {
this.ready = true this.ready = true
} }
<<<<<<< Updated upstream
on_cell_click(row_i, cell_i) { on_cell_click(row_i, cell_i) {
alert(`${row_i} : ${cell_i}`) alert(`${row_i} : ${cell_i}`)
} }
=======
>>>>>>> Stashed changes
} }

@ -3,6 +3,7 @@ import {GameState} from '../module/util.js'
import game_service from '../services/GameState.service.js' import game_service from '../services/GameState.service.js'
const template = ` const template = `
<<<<<<< Updated upstream
<div class="top-level-container"> <div class="top-level-container">
<div class="top-level-component"> <div class="top-level-component">
<div v-if="current_state === GameState.ChoosingNumberOfShips"> <div v-if="current_state === GameState.ChoosingNumberOfShips">
@ -12,6 +13,24 @@ const template = `
<button @click="ship(3)" class="shipBtn">3 ships</button> <button @click="ship(3)" class="shipBtn">3 ships</button>
<button @click="ship(4)" class="shipBtn">4 ships</button> <button @click="ship(4)" class="shipBtn">4 ships</button>
<button @click="ship(5)" class="shipBtn">5 ships</button> <button @click="ship(5)" class="shipBtn">5 ships</button>
=======
<div class="top-level-component">
<div v-if="current_state === GameState.ChoosingNumberOfShips">
Choose number of ships:
<button @click="ship1" class="shipBtn">1 ship</button>
<button @click="ship2" class="shipBtn">2 ships</button>
<button @click="ship3" class="shipBtn">3 ships</button>
<button @click="ship4" class="shipBtn">4 ships</button>
<button @click="ship5" class="shipBtn">5 ships</button>
</div>
<<<<<<< HEAD
=======
>>>>>>> 19aa3733d0604f37e6875b825eb51ccd4092d4c4
<div v-if="current_state !== GameState.ChoosingNumberOfShips" class="game-boards-container">
<!-- Opponent's board -->
<div class="game-board">
<app-game-board v-bind:rows="opponent_rows"></app-game-board>
>>>>>>> Stashed changes
</div> </div>
<div v-if="current_state !== GameState.ChoosingNumberOfShips" class="game-boards-container"> <div v-if="current_state !== GameState.ChoosingNumberOfShips" class="game-boards-container">
<!-- Opponent's board --> <!-- Opponent's board -->

@ -57,17 +57,34 @@ export class GameStateService {
} }
/** /**
* sets the number of boats to a valid number * sets the number of boats to a valid number
* @private * @private
* @return none * @return none
*/ */
set_n_boats(number){ set_n_boats(number){
if(number >= 1 && number <= 5 ) if(number >= 1 && number <= 5 )
{ {
this.n_boats = number; this.n_boats = number;
} }
} }
get_possible_boats(number){
if (get_n_boats == 1) {
return (ships:x1)
}
if (get_n_boats == 2) {
return (ships:x1, x2)
}
if (get_n_boats == 3) {
return (ships:x1, x2, x3)
}
if (get_n_boats == 4) {
return (ships:x1, x2, x3,x4)
}
if (get_n_boats == 5) {
return (ships:x1, x2, x3, x4, x5)
}
}
/** /**
* The current state of the game. * The current state of the game.
* @private * @private
@ -174,10 +191,10 @@ export class GameStateService {
} }
/** /**
* get the "score" (the number of hits) that the * get the "score" (the number of hits) that the
* current player has (counting sunk ships) * current player has (counting sunk ships)
* @return {number} * @return {number}
* @private * @private
*/ */
get_player_score(player) { get_player_score(player) {
let i = 1; let i = 1;
@ -201,7 +218,7 @@ export class GameStateService {
* gets the number of the boats (sunken, damaged or not) that the opponent has * gets the number of the boats (sunken, damaged or not) that the opponent has
* used to help keep get progress method looking clean * used to help keep get progress method looking clean
* @return {number} * @return {number}
* @private * @private
*/ */
get_boat_count(player){ get_boat_count(player){
let i = 1; let i = 1;
@ -224,7 +241,7 @@ export class GameStateService {
/** /**
* gets the progress (hits/total boats) that the player has * gets the progress (hits/total boats) that the player has
* @return {number} * @return {number}
* @private * @private
*/ */
get_progress(player){ get_progress(player){
return(this.get_player_score(player) / this.get_boat_count(player)) return(this.get_player_score(player) / this.get_boat_count(player))
@ -239,10 +256,10 @@ export class GameStateService {
} }
/** /**
* responsible for advancing the game state * responsible for advancing the game state
* will be consisting of * will be consisting of
* @return * @return
* @private * @private
*/ */
advance_game_state() { advance_game_state() {
/** functions to be made that validate: /** functions to be made that validate:
@ -271,7 +288,7 @@ export class GameStateService {
// all you need to do is make sure they have placed all the appropriate ships // all you need to do is make sure they have placed all the appropriate ships
if ( this.get_ship_entities(this.current_player).length === this.n_boats ) { if ( this.get_ship_entities(this.current_player).length === this.n_boats ) {
this.current_player = Player.Two; this.current_player = Player.Two;
this.current_opponent = Player.One; this.current_opponent = Player.One;
} }
else{ else{
throw new InvalidAdvanceStateError("Player One has a problem with the number of boats selected"); throw new InvalidAdvanceStateError("Player One has a problem with the number of boats selected");
@ -309,7 +326,7 @@ export class GameStateService {
let winner = this.get_winner(); let winner = this.get_winner();
if(winner) { if(winner) {
this.current_state = GameState.PlayerVictory; this.current_state = GameState.PlayerVictory;
this.current_player = winner; this.current_player = winner;
} }

@ -29,6 +29,7 @@
/* Styles for the various grid cell states. */ /* Styles for the various grid cell states. */
.game-board-cell-component { .game-board-cell-component {
width: 40px; width: 40px;
height: 40px; height: 40px;
border: 1px solid grey; border: 1px solid grey;

Loading…
Cancel
Save