File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11<template >
22 <div class =" battle-board" >
33 <div class =" boards" >
4+ <Boats :boats =" playerBoats " />
45 <PlayBoard :title =" ' Player' " :board =" playerCellsBoard " :ships-visible =" true " />
56 <PlayBoard :title =" ' IA' " :board =" IACellsBoard " :ships-visible =" false " @play =" play " />
7+ <Boats :boats =" IABoats " />
68 </div >
79 <button class =" start-button" @click =" startGame" >Start Game</button >
810 </div >
911</template >
1012
1113<script >
1214import PlayBoard from " ./PlayBoard.vue" ;
15+ import Boats from " ./Boats.vue" ;
1316import { generateRandomBoard } from " ../services/board-helper.js" ;
1417import { shoot } from " ../services/play-helper.js" ;
1518import { findTargetCellV2 } from " ../services/ia-helper.js" ;
@@ -19,12 +22,15 @@ import Vue from "vue";
1922export default {
2023 name: " BattleBoard" ,
2124 components: {
22- PlayBoard
25+ PlayBoard,
26+ Boats
2327 },
2428 data : function () {
2529 return {
2630 playerCellsBoard: {},
2731 IACellsBoard: {},
32+ IABoats: {},
33+ playerBoats: {},
2834 gameStarted: false ,
2935 humanCanPlay: true
3036 };
Original file line number Diff line number Diff line change 1+ <template >
2+ <div >
3+ <ol class =" boats-liste" >
4+ <li
5+ v-for =" boat in boatsInfos"
6+ :key =" boat.name"
7+ v-bind:class =" {sunk: boat.isSunk}"
8+ >{{boat.name}} ({{boat.nbCells}})</li >
9+ </ol >
10+ </div >
11+ </template >
12+
13+ <script >
14+ export default {
15+ name: " Boats" ,
16+ props: {
17+ boats: {
18+ type: Object ,
19+ required: true
20+ }
21+ },
22+ computed: {
23+ boatsInfos : function () {
24+ const x = Object .keys (this .boats )
25+ .map (name => ({
26+ name,
27+ nbCells: this .boats [name].cells .length ,
28+ isSunk: this .boats [name].nbOfAliveCells === 0
29+ }))
30+ .sort ((boat1 , boat2 ) =>
31+ boat1 .nbCells < boat2 .nbCells ||
32+ (boat1 .nbCells === boat2 .nbCells && boat1 .name < boat2 .name )
33+ ? 1
34+ : - 1
35+ );
36+ return x;
37+ }
38+ }
39+ };
40+ </script >
41+
42+ <style lang="scss" scoped>
43+ .sunk {
44+ text-decoration : line-through ;
45+ color : red ;
46+ }
47+ .boats-liste {
48+ list-style : none ;
49+ padding : 100% 0 ;
50+ margin : 0 ;
51+ font-size : 18px ;
52+ font-weight : 500 ;
53+ }
54+ </style >
You can’t perform that action at this time.
0 commit comments