Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 8 additions & 15 deletions src/components/BattleBoard.vue
Original file line number Diff line number Diff line change
@@ -1,35 +1,28 @@
<template>
<div class="battle-board">
<div v-if="winner" class="end-game-message" :class="this.winner">
{{ this.winner }} wins !!!
</div>
<div v-if="winner" class="end-game-message" :class="this.winner">{{ this.winner }} wins !!!</div>
<div v-else class="boards">
<PlayBoard
title="Player"
:board="playerCellsBoard"
:ships-visible="true"
/>
<PlayBoard
title="IA"
:board="IACellsBoard"
:ships-visible="false"
@play="play"
/>
<Boats :boats="playerBoats" />
<PlayBoard title="Player" :board="playerCellsBoard" :ships-visible="true" />
<PlayBoard title="IA" :board="IACellsBoard" :ships-visible="false" @play="play" />
<Boats :boats="IABoats" />
</div>
<button class="start-button" @click="startGame">Start Game</button>
</div>
</template>

<script>
import PlayBoard from "./PlayBoard.vue";
import Boats from "./Boats.vue";
import { generateRandomBoard } from "../services/board-helper.js";
import { shoot } from "../services/play-helper.js";
import { findTargetCellV2 } from "../services/ia-helper.js";

export default {
name: "BattleBoard",
components: {
PlayBoard
PlayBoard,
Boats
},
data: function() {
return {
Expand Down
55 changes: 55 additions & 0 deletions src/components/Boats.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<template>
<div>
<ol class="boats-liste">
<li
v-for="boat in boatsInfos"
:key="boat.name"
v-bind:class="{sunk: boat.isSunk}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tu peux écrire ça :class= si tu veux 🙂
https://v1.vuejs.org/guide/syntax.html#Shorthands

>{{boat.name}} ({{boat.nbCells}})</li>
</ol>
</div>
</template>

<script>
export default {
name: "Boats",
props: {
boats: {
type: Object,
required: true
}
},
computed: {
boatsInfos: function() {
const x = Object.keys(this.boats)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

x => boatsInformation

ca me semble hyper compliqué quand l'objet passé en props a déjà quasiment toutes les infos, on veut forcément l'ordonner?

.filter(name => !!this.boats[name].cells)
.map(name => ({
name,
nbCells: this.boats[name].cells.length,
isSunk: this.boats[name].nbOfAliveCells === 0
}))
.sort((boat1, boat2) =>
boat1.nbCells < boat2.nbCells ||
(boat1.nbCells === boat2.nbCells && boat1.name < boat2.name)
? 1
: -1
);
return x;
}
}
};
</script>

<style lang="scss" scoped>
.sunk {
text-decoration: line-through;
color: red;
}
.boats-liste {
list-style: none;
padding: 100% 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pourquoi 100% ?

margin: 0;
font-size: 18px;
font-weight: 500;
}
</style>