|
| 1 | +<template> |
| 2 | + <div class="game-dsl"> |
| 3 | + <GameHead :gameInfo="gameInfo"></GameHead> |
| 4 | + <Map2D :width="3" :height="3" :grid="view.board" :clickHandler="onClick"> |
| 5 | + <template v-slot:default="slotProps"> |
| 6 | + <UrPiece |
| 7 | + :key="slotProps.key" |
| 8 | + :mouseover="doNothing" :mouseleave="doNothing" |
| 9 | + class="piece" |
| 10 | + :class="'piece-' + slotProps.tile.tile.owner" |
| 11 | + :onclick="pieceClick" |
| 12 | + :piece="slotProps.tile"> |
| 13 | + </UrPiece> |
| 14 | + </template> |
| 15 | + </Map2D> |
| 16 | + <GameResult :gameInfo="gameInfo"></GameResult> |
| 17 | + </div> |
| 18 | +</template> |
| 19 | +<script> |
| 20 | +import Map2D from "../common/Map2D"; |
| 21 | +import Socket from "../../socket"; |
| 22 | +import UrPiece from "../ur/UrPiece"; |
| 23 | +import GameHead from "./common/GameHead"; |
| 24 | +import GameResult from "./common/GameResult"; |
| 25 | +import { mapState } from "vuex"; |
| 26 | +
|
| 27 | +export default { |
| 28 | + name: "DSLTTT", |
| 29 | + props: ["gameInfo", "showRules"], |
| 30 | + created() { |
| 31 | + Socket.$on("type:IllegalMove", this.messageIllegal); // TODO: Is this used? |
| 32 | + }, |
| 33 | + beforeDestroy() { |
| 34 | + Socket.$off("type:IllegalMove", this.messageIllegal); |
| 35 | + }, |
| 36 | + mounted() { |
| 37 | + Socket.send( |
| 38 | + `{ "type": "ViewRequest", "gameType": "${ |
| 39 | + this.gameInfo.gameType |
| 40 | + }", "gameId": "${this.gameInfo.gameId}" }` |
| 41 | + ); |
| 42 | + }, |
| 43 | + components: { |
| 44 | + Map2D, |
| 45 | + GameHead, |
| 46 | + GameResult, |
| 47 | + UrPiece |
| 48 | + }, |
| 49 | + methods: { |
| 50 | + doNothing: function() {}, |
| 51 | + action: function(name, data) { |
| 52 | + if (Socket.isConnected()) { |
| 53 | + let json = `{ "gameType": "${this.gameInfo.gameType}", "gameId": "${ |
| 54 | + this.gameInfo.gameId |
| 55 | + }", "type": "move", "moveType": "${name}", "move": ${JSON.stringify( |
| 56 | + data |
| 57 | + )} }`; |
| 58 | + Socket.send(json); |
| 59 | + } |
| 60 | + }, |
| 61 | + pieceClick(data) { |
| 62 | + console.log(`onClick on DSLTTT pieceClick invoked: ${data.x}, ${data.y}`) |
| 63 | + this.action("play", { x: data.x, y: data.y }); |
| 64 | + }, |
| 65 | + onClick: function(x, y) { |
| 66 | + console.log(`onClick on DSLTTT invoked: ${x}, ${y}`) |
| 67 | + this.action("play", { x: x, y: y }); |
| 68 | + }, |
| 69 | + messageIllegal(e) { |
| 70 | + console.log("IllegalMove: " + JSON.stringify(e)); |
| 71 | + } |
| 72 | + }, |
| 73 | + computed: { |
| 74 | + ...mapState("DslGameState", { |
| 75 | + view(state) { |
| 76 | + return state.games[this.gameInfo.gameId].gameData.view; |
| 77 | + } |
| 78 | + }) |
| 79 | + } |
| 80 | +}; |
| 81 | +</script> |
| 82 | +<style> |
| 83 | +@import "../../assets/games-style.css"; |
| 84 | +
|
| 85 | +.connect4-board { |
| 86 | + width: 448px; |
| 87 | + height: 384px; |
| 88 | +} |
| 89 | +
|
| 90 | +.game-connect4 .pieces { |
| 91 | + grid-template-columns: repeat(7, 1fr); |
| 92 | + grid-template-rows: repeat(6, 1fr); |
| 93 | +} |
| 94 | +</style> |
0 commit comments