2018-03-07 04:40:40 +02:00
|
|
|
<template>
|
2018-03-07 10:48:32 +02:00
|
|
|
<div class="root">
|
2018-03-08 10:57:57 +02:00
|
|
|
<header><b>{{ blackUser.name }}</b>(黒) vs <b>{{ whiteUser.name }}</b>(白)</header>
|
|
|
|
|
2018-03-10 06:22:20 +02:00
|
|
|
<div style="overflow: hidden">
|
2018-03-29 08:48:47 +03:00
|
|
|
<p class="turn" v-if="!iAmPlayer && !game.isEnded">{{ turnUser.name }}のターンです<mk-ellipsis/></p>
|
2018-03-10 06:22:20 +02:00
|
|
|
<p class="turn" v-if="logPos != logs.length">{{ turnUser.name }}のターン</p>
|
2018-03-29 08:48:47 +03:00
|
|
|
<p class="turn1" v-if="iAmPlayer && !game.isEnded && !isMyTurn">相手のターンです<mk-ellipsis/></p>
|
|
|
|
<p class="turn2" v-if="iAmPlayer && !game.isEnded && isMyTurn" v-animate-css="{ classes: 'tada', iteration: 'infinite' }">あなたのターンです</p>
|
|
|
|
<p class="result" v-if="game.isEnded && logPos == logs.length">
|
|
|
|
<template v-if="game.winner"><b>{{ game.winner.name }}</b>の勝ち{{ game.settings.isLlotheo ? ' (ロセオ)' : '' }}</template>
|
2018-03-10 06:22:20 +02:00
|
|
|
<template v-else>引き分け</template>
|
|
|
|
</p>
|
|
|
|
</div>
|
2018-03-08 10:57:57 +02:00
|
|
|
|
2018-03-09 11:11:10 +02:00
|
|
|
<div class="board" :style="{ 'grid-template-rows': `repeat(${ game.settings.map.length }, 1fr)`, 'grid-template-columns': `repeat(${ game.settings.map[0].length }, 1fr)` }">
|
2018-03-07 10:48:32 +02:00
|
|
|
<div v-for="(stone, i) in o.board"
|
2018-03-29 08:48:47 +03:00
|
|
|
:class="{ empty: stone == null, none: o.map[i] == 'null', isEnded: game.isEnded, myTurn: !game.isEnded && isMyTurn, can: turnUser ? o.canPut(turnUser.id == blackUser.id, i) : null, prev: o.prevPos == i }"
|
2018-03-07 10:48:32 +02:00
|
|
|
@click="set(i)"
|
2018-03-16 16:38:25 +02:00
|
|
|
:title="'[' + (o.transformPosToXy(i)[0] + 1) + ', ' + (o.transformPosToXy(i)[1] + 1) + '] (' + i + ')'"
|
2018-03-07 10:48:32 +02:00
|
|
|
>
|
2018-03-29 08:48:47 +03:00
|
|
|
<img v-if="stone === true" :src="`${blackUser.avatarUrl}?thumbnail&size=128`" alt="">
|
|
|
|
<img v-if="stone === false" :src="`${whiteUser.avatarUrl}?thumbnail&size=128`" alt="">
|
2018-03-07 10:48:32 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2018-03-08 10:57:57 +02:00
|
|
|
|
2018-03-16 16:38:25 +02:00
|
|
|
<p class="status"><b>{{ logPos }}ターン目</b> 黒:{{ o.blackCount }} 白:{{ o.whiteCount }} 合計:{{ o.blackCount + o.whiteCount }}</p>
|
2018-03-08 10:57:57 +02:00
|
|
|
|
2018-03-29 08:48:47 +03:00
|
|
|
<div class="player" v-if="game.isEnded">
|
2018-03-15 08:02:15 +02:00
|
|
|
<el-button-group>
|
|
|
|
<el-button type="primary" @click="logPos = 0" :disabled="logPos == 0">%fa:angle-double-left%</el-button>
|
|
|
|
<el-button type="primary" @click="logPos--" :disabled="logPos == 0">%fa:angle-left%</el-button>
|
|
|
|
</el-button-group>
|
2018-03-07 14:57:06 +02:00
|
|
|
<span>{{ logPos }} / {{ logs.length }}</span>
|
2018-03-15 08:02:15 +02:00
|
|
|
<el-button-group>
|
|
|
|
<el-button type="primary" @click="logPos++" :disabled="logPos == logs.length">%fa:angle-right%</el-button>
|
|
|
|
<el-button type="primary" @click="logPos = logs.length" :disabled="logPos == logs.length">%fa:angle-double-right%</el-button>
|
|
|
|
</el-button-group>
|
2018-03-07 14:57:06 +02:00
|
|
|
</div>
|
2018-03-07 04:40:40 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
2018-03-11 10:23:59 +02:00
|
|
|
import * as CRC32 from 'crc-32';
|
2018-04-02 06:58:53 +03:00
|
|
|
import Othello, { Color } from '../../../../../othello/core';
|
2018-03-10 18:55:46 +02:00
|
|
|
import { url } from '../../../config';
|
2018-03-07 10:48:32 +02:00
|
|
|
|
2018-03-07 04:40:40 +02:00
|
|
|
export default Vue.extend({
|
2018-03-11 10:23:59 +02:00
|
|
|
props: ['initGame', 'connection'],
|
2018-03-07 14:57:06 +02:00
|
|
|
|
2018-03-07 04:40:40 +02:00
|
|
|
data() {
|
|
|
|
return {
|
2018-03-11 10:23:59 +02:00
|
|
|
game: null,
|
2018-03-08 10:57:57 +02:00
|
|
|
o: null as Othello,
|
2018-03-07 14:57:06 +02:00
|
|
|
logs: [],
|
2018-03-11 10:23:59 +02:00
|
|
|
logPos: 0,
|
|
|
|
pollingClock: null
|
2018-03-07 04:40:40 +02:00
|
|
|
};
|
|
|
|
},
|
2018-03-07 14:57:06 +02:00
|
|
|
|
2018-03-07 10:48:32 +02:00
|
|
|
computed: {
|
2018-03-07 11:45:16 +02:00
|
|
|
iAmPlayer(): boolean {
|
2018-05-27 07:49:09 +03:00
|
|
|
if (!this.$store.getters.isSignedIn) return false;
|
|
|
|
return this.game.user1Id == this.$store.state.i.id || this.game.user2Id == this.$store.state.i.id;
|
2018-03-07 11:45:16 +02:00
|
|
|
},
|
2018-03-08 10:57:57 +02:00
|
|
|
myColor(): Color {
|
|
|
|
if (!this.iAmPlayer) return null;
|
2018-05-27 07:49:09 +03:00
|
|
|
if (this.game.user1Id == this.$store.state.i.id && this.game.black == 1) return true;
|
|
|
|
if (this.game.user2Id == this.$store.state.i.id && this.game.black == 2) return true;
|
2018-03-12 18:49:54 +02:00
|
|
|
return false;
|
2018-03-07 10:48:32 +02:00
|
|
|
},
|
2018-03-08 10:57:57 +02:00
|
|
|
opColor(): Color {
|
|
|
|
if (!this.iAmPlayer) return null;
|
2018-03-12 18:49:54 +02:00
|
|
|
return this.myColor === true ? false : true;
|
2018-03-08 10:57:57 +02:00
|
|
|
},
|
|
|
|
blackUser(): any {
|
|
|
|
return this.game.black == 1 ? this.game.user1 : this.game.user2;
|
|
|
|
},
|
|
|
|
whiteUser(): any {
|
|
|
|
return this.game.black == 1 ? this.game.user2 : this.game.user1;
|
|
|
|
},
|
|
|
|
turnUser(): any {
|
2018-03-12 18:49:54 +02:00
|
|
|
if (this.o.turn === true) {
|
2018-03-08 10:57:57 +02:00
|
|
|
return this.game.black == 1 ? this.game.user1 : this.game.user2;
|
2018-03-12 18:49:54 +02:00
|
|
|
} else if (this.o.turn === false) {
|
2018-03-08 10:57:57 +02:00
|
|
|
return this.game.black == 1 ? this.game.user2 : this.game.user1;
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
isMyTurn(): boolean {
|
|
|
|
if (this.turnUser == null) return null;
|
2018-05-27 07:49:09 +03:00
|
|
|
return this.turnUser.id == this.$store.state.i.id;
|
2018-03-07 10:48:32 +02:00
|
|
|
}
|
|
|
|
},
|
2018-03-07 14:57:06 +02:00
|
|
|
|
|
|
|
watch: {
|
|
|
|
logPos(v) {
|
2018-03-29 08:48:47 +03:00
|
|
|
if (!this.game.isEnded) return;
|
2018-03-08 10:57:57 +02:00
|
|
|
this.o = new Othello(this.game.settings.map, {
|
2018-03-29 08:48:47 +03:00
|
|
|
isLlotheo: this.game.settings.isLlotheo,
|
|
|
|
canPutEverywhere: this.game.settings.canPutEverywhere,
|
|
|
|
loopedBoard: this.game.settings.loopedBoard
|
2018-03-08 10:57:57 +02:00
|
|
|
});
|
2018-03-07 14:57:06 +02:00
|
|
|
this.logs.forEach((log, i) => {
|
|
|
|
if (i < v) {
|
2018-03-15 08:02:15 +02:00
|
|
|
this.o.put(log.color, log.pos);
|
2018-03-07 14:57:06 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
this.$forceUpdate();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-03-07 10:48:32 +02:00
|
|
|
created() {
|
2018-03-11 10:23:59 +02:00
|
|
|
this.game = this.initGame;
|
|
|
|
|
2018-03-08 10:57:57 +02:00
|
|
|
this.o = new Othello(this.game.settings.map, {
|
2018-03-29 08:48:47 +03:00
|
|
|
isLlotheo: this.game.settings.isLlotheo,
|
|
|
|
canPutEverywhere: this.game.settings.canPutEverywhere,
|
|
|
|
loopedBoard: this.game.settings.loopedBoard
|
2018-03-08 10:57:57 +02:00
|
|
|
});
|
|
|
|
|
2018-03-07 10:48:32 +02:00
|
|
|
this.game.logs.forEach(log => {
|
2018-03-15 08:02:15 +02:00
|
|
|
this.o.put(log.color, log.pos);
|
2018-03-07 10:48:32 +02:00
|
|
|
});
|
2018-03-07 04:40:40 +02:00
|
|
|
|
2018-03-07 14:57:06 +02:00
|
|
|
this.logs = this.game.logs;
|
|
|
|
this.logPos = this.logs.length;
|
2018-03-11 10:23:59 +02:00
|
|
|
|
|
|
|
// 通信を取りこぼしてもいいように定期的にポーリングさせる
|
2018-03-29 08:48:47 +03:00
|
|
|
if (this.game.isStarted && !this.game.isEnded) {
|
2018-03-11 10:23:59 +02:00
|
|
|
this.pollingClock = setInterval(() => {
|
|
|
|
const crc32 = CRC32.str(this.logs.map(x => x.pos.toString()).join(''));
|
|
|
|
this.connection.send({
|
|
|
|
type: 'check',
|
|
|
|
crc32
|
|
|
|
});
|
2018-03-12 00:53:58 +02:00
|
|
|
}, 3000);
|
2018-03-11 10:23:59 +02:00
|
|
|
}
|
2018-03-07 10:48:32 +02:00
|
|
|
},
|
2018-03-07 14:57:06 +02:00
|
|
|
|
2018-03-07 10:48:32 +02:00
|
|
|
mounted() {
|
2018-03-07 04:40:40 +02:00
|
|
|
this.connection.on('set', this.onSet);
|
2018-03-11 10:23:59 +02:00
|
|
|
this.connection.on('rescue', this.onRescue);
|
2018-03-07 04:40:40 +02:00
|
|
|
},
|
2018-03-07 14:57:06 +02:00
|
|
|
|
2018-03-07 04:40:40 +02:00
|
|
|
beforeDestroy() {
|
|
|
|
this.connection.off('set', this.onSet);
|
2018-03-11 10:23:59 +02:00
|
|
|
this.connection.off('rescue', this.onRescue);
|
|
|
|
|
|
|
|
clearInterval(this.pollingClock);
|
2018-03-07 04:40:40 +02:00
|
|
|
},
|
2018-03-07 14:57:06 +02:00
|
|
|
|
2018-03-07 10:48:32 +02:00
|
|
|
methods: {
|
|
|
|
set(pos) {
|
2018-03-29 08:48:47 +03:00
|
|
|
if (this.game.isEnded) return;
|
2018-03-08 11:30:28 +02:00
|
|
|
if (!this.iAmPlayer) return;
|
2018-03-07 11:45:16 +02:00
|
|
|
if (!this.isMyTurn) return;
|
2018-03-08 10:57:57 +02:00
|
|
|
if (!this.o.canPut(this.myColor, pos)) return;
|
|
|
|
|
|
|
|
this.o.put(this.myColor, pos);
|
|
|
|
|
2018-03-10 18:55:46 +02:00
|
|
|
// サウンドを再生する
|
2018-05-20 20:13:39 +03:00
|
|
|
if (this.$store.state.device.enableSounds) {
|
2018-03-10 18:55:46 +02:00
|
|
|
const sound = new Audio(`${url}/assets/othello-put-me.mp3`);
|
2018-05-20 20:13:39 +03:00
|
|
|
sound.volume = this.$store.state.device.soundVolume;
|
2018-03-10 18:55:46 +02:00
|
|
|
sound.play();
|
|
|
|
}
|
|
|
|
|
2018-03-07 10:48:32 +02:00
|
|
|
this.connection.send({
|
|
|
|
type: 'set',
|
|
|
|
pos
|
|
|
|
});
|
2018-03-08 10:57:57 +02:00
|
|
|
|
|
|
|
this.checkEnd();
|
|
|
|
|
2018-03-07 10:48:32 +02:00
|
|
|
this.$forceUpdate();
|
|
|
|
},
|
2018-03-07 14:57:06 +02:00
|
|
|
|
2018-03-07 10:48:32 +02:00
|
|
|
onSet(x) {
|
2018-03-07 14:57:06 +02:00
|
|
|
this.logs.push(x);
|
|
|
|
this.logPos++;
|
2018-03-08 10:57:57 +02:00
|
|
|
this.o.put(x.color, x.pos);
|
|
|
|
this.checkEnd();
|
|
|
|
this.$forceUpdate();
|
2018-03-10 18:55:46 +02:00
|
|
|
|
|
|
|
// サウンドを再生する
|
2018-05-20 20:13:39 +03:00
|
|
|
if (this.$store.state.device.enableSounds && x.color != this.myColor) {
|
2018-03-10 18:55:46 +02:00
|
|
|
const sound = new Audio(`${url}/assets/othello-put-you.mp3`);
|
2018-05-20 20:13:39 +03:00
|
|
|
sound.volume = this.$store.state.device.soundVolume;
|
2018-03-10 18:55:46 +02:00
|
|
|
sound.play();
|
|
|
|
}
|
2018-03-08 10:57:57 +02:00
|
|
|
},
|
2018-03-07 11:45:16 +02:00
|
|
|
|
2018-03-08 10:57:57 +02:00
|
|
|
checkEnd() {
|
2018-03-29 08:48:47 +03:00
|
|
|
this.game.isEnded = this.o.isEnded;
|
|
|
|
if (this.game.isEnded) {
|
2018-03-12 18:49:54 +02:00
|
|
|
if (this.o.winner === true) {
|
2018-03-29 08:48:47 +03:00
|
|
|
this.game.winnerId = this.game.black == 1 ? this.game.user1Id : this.game.user2Id;
|
2018-03-08 10:57:57 +02:00
|
|
|
this.game.winner = this.game.black == 1 ? this.game.user1 : this.game.user2;
|
2018-03-12 18:49:54 +02:00
|
|
|
} else if (this.o.winner === false) {
|
2018-03-29 08:48:47 +03:00
|
|
|
this.game.winnerId = this.game.black == 1 ? this.game.user2Id : this.game.user1Id;
|
2018-03-08 10:57:57 +02:00
|
|
|
this.game.winner = this.game.black == 1 ? this.game.user2 : this.game.user1;
|
|
|
|
} else {
|
2018-03-29 08:48:47 +03:00
|
|
|
this.game.winnerId = null;
|
2018-03-08 10:57:57 +02:00
|
|
|
this.game.winner = null;
|
2018-03-07 11:45:16 +02:00
|
|
|
}
|
2018-03-07 10:48:32 +02:00
|
|
|
}
|
2018-03-11 10:23:59 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// 正しいゲーム情報が送られてきたとき
|
|
|
|
onRescue(game) {
|
|
|
|
this.game = game;
|
|
|
|
|
|
|
|
this.o = new Othello(this.game.settings.map, {
|
2018-03-29 08:48:47 +03:00
|
|
|
isLlotheo: this.game.settings.isLlotheo,
|
|
|
|
canPutEverywhere: this.game.settings.canPutEverywhere,
|
|
|
|
loopedBoard: this.game.settings.loopedBoard
|
2018-03-11 10:23:59 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
this.game.logs.forEach(log => {
|
2018-03-12 18:49:54 +02:00
|
|
|
this.o.put(log.color, log.pos, true);
|
2018-03-11 10:23:59 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
this.logs = this.game.logs;
|
|
|
|
this.logPos = this.logs.length;
|
|
|
|
|
|
|
|
this.checkEnd();
|
|
|
|
this.$forceUpdate();
|
2018-03-07 10:48:32 +02:00
|
|
|
}
|
|
|
|
}
|
2018-03-07 04:40:40 +02:00
|
|
|
});
|
|
|
|
</script>
|
2018-03-07 10:48:32 +02:00
|
|
|
|
|
|
|
<style lang="stylus" scoped>
|
|
|
|
@import '~const.styl'
|
|
|
|
|
|
|
|
.root
|
|
|
|
text-align center
|
|
|
|
|
|
|
|
> header
|
|
|
|
padding 8px
|
|
|
|
border-bottom dashed 1px #c4cdd4
|
|
|
|
|
2018-03-07 14:57:06 +02:00
|
|
|
> .board
|
2018-03-07 10:48:32 +02:00
|
|
|
display grid
|
|
|
|
grid-gap 4px
|
2018-03-09 18:48:20 +02:00
|
|
|
width 350px
|
|
|
|
height 350px
|
2018-03-07 10:48:32 +02:00
|
|
|
margin 0 auto
|
|
|
|
|
|
|
|
> div
|
|
|
|
background transparent
|
|
|
|
border-radius 6px
|
|
|
|
overflow hidden
|
|
|
|
|
|
|
|
*
|
|
|
|
pointer-events none
|
|
|
|
user-select none
|
|
|
|
|
|
|
|
&.empty
|
2018-03-08 15:11:08 +02:00
|
|
|
border solid 2px #eee
|
2018-03-07 10:48:32 +02:00
|
|
|
|
|
|
|
&.empty.can
|
2018-03-08 15:11:08 +02:00
|
|
|
background #eee
|
2018-03-07 10:48:32 +02:00
|
|
|
|
|
|
|
&.empty.myTurn
|
2018-03-08 15:11:08 +02:00
|
|
|
border-color #ddd
|
2018-03-07 10:48:32 +02:00
|
|
|
|
|
|
|
&.can
|
|
|
|
background #eee
|
|
|
|
cursor pointer
|
|
|
|
|
|
|
|
&:hover
|
|
|
|
border-color darken($theme-color, 10%)
|
|
|
|
background $theme-color
|
|
|
|
|
|
|
|
&:active
|
|
|
|
background darken($theme-color, 10%)
|
|
|
|
|
2018-03-07 15:25:26 +02:00
|
|
|
&.prev
|
|
|
|
box-shadow 0 0 0 4px rgba($theme-color, 0.7)
|
|
|
|
|
2018-03-08 15:11:08 +02:00
|
|
|
&.isEnded
|
|
|
|
border-color #ddd
|
|
|
|
|
2018-03-08 10:57:57 +02:00
|
|
|
&.none
|
|
|
|
border-color transparent !important
|
|
|
|
|
2018-03-07 10:48:32 +02:00
|
|
|
> img
|
|
|
|
display block
|
|
|
|
width 100%
|
|
|
|
height 100%
|
2018-03-07 14:57:06 +02:00
|
|
|
|
|
|
|
> .graph
|
|
|
|
display grid
|
|
|
|
grid-template-columns repeat(61, 1fr)
|
|
|
|
width 300px
|
|
|
|
height 38px
|
|
|
|
margin 0 auto 16px auto
|
|
|
|
|
|
|
|
> div
|
|
|
|
&:not(:empty)
|
|
|
|
background #ccc
|
|
|
|
|
|
|
|
> div:first-child
|
|
|
|
background #333
|
|
|
|
|
|
|
|
> div:last-child
|
|
|
|
background #ccc
|
|
|
|
|
2018-03-16 16:38:25 +02:00
|
|
|
> .status
|
|
|
|
margin 0
|
|
|
|
padding 16px 0
|
|
|
|
|
2018-03-07 14:57:06 +02:00
|
|
|
> .player
|
2018-03-15 08:02:15 +02:00
|
|
|
padding-bottom 32px
|
2018-03-07 14:57:06 +02:00
|
|
|
|
|
|
|
> span
|
|
|
|
display inline-block
|
|
|
|
margin 0 8px
|
|
|
|
min-width 70px
|
2018-03-07 10:48:32 +02:00
|
|
|
</style>
|