2018-03-06 10:54:56 -06:00
|
|
|
|
<template>
|
2018-06-16 18:10:54 -05:00
|
|
|
|
<div class="mk-reversi">
|
2018-03-06 20:40:40 -06:00
|
|
|
|
<div v-if="game">
|
2018-03-08 02:57:57 -06:00
|
|
|
|
<x-gameroom :game="game"/>
|
2018-03-06 20:40:40 -06:00
|
|
|
|
</div>
|
2018-03-07 02:48:32 -06:00
|
|
|
|
<div class="matching" v-else-if="matching">
|
2018-03-06 20:40:40 -06:00
|
|
|
|
<h1><b>{{ matching.name }}</b>を待っています<mk-ellipsis/></h1>
|
2018-03-07 02:48:32 -06:00
|
|
|
|
<div class="cancel">
|
|
|
|
|
<el-button round @click="cancel">キャンセル</el-button>
|
|
|
|
|
</div>
|
2018-03-06 10:54:56 -06:00
|
|
|
|
</div>
|
2018-03-07 02:48:32 -06:00
|
|
|
|
<div class="index" v-else>
|
|
|
|
|
<h1>Misskey %fa:circle%thell%fa:circle R%</h1>
|
2018-06-16 18:10:54 -05:00
|
|
|
|
<p>他のMisskeyユーザーとリバーシで対戦しよう</p>
|
2018-03-07 02:48:32 -06:00
|
|
|
|
<div class="play">
|
|
|
|
|
<el-button round>フリーマッチ(準備中)</el-button>
|
|
|
|
|
<el-button type="primary" round @click="match">指名</el-button>
|
|
|
|
|
<details>
|
|
|
|
|
<summary>遊び方</summary>
|
|
|
|
|
<div>
|
2018-06-16 18:10:54 -05:00
|
|
|
|
<p>リバーシは、相手と交互に石をボードに置いてゆき、相手の石を挟んでひっくり返しながら、最終的に残った石が多い方が勝ちというボードゲームです。</p>
|
2018-03-07 02:48:32 -06:00
|
|
|
|
<dl>
|
|
|
|
|
<dt><b>フリーマッチ</b></dt>
|
|
|
|
|
<dd>ランダムなユーザーと対戦するモードです。</dd>
|
|
|
|
|
<dt><b>指名</b></dt>
|
|
|
|
|
<dd>指定したユーザーと対戦するモードです。</dd>
|
|
|
|
|
</dl>
|
|
|
|
|
</div>
|
|
|
|
|
</details>
|
|
|
|
|
</div>
|
|
|
|
|
<section v-if="invitations.length > 0">
|
|
|
|
|
<h2>対局の招待があります!:</h2>
|
|
|
|
|
<div class="invitation" v-for="i in invitations" tabindex="-1" @click="accept(i)">
|
2018-05-04 02:27:03 -05:00
|
|
|
|
<mk-avatar class="avatar" :user="i.parent"/>
|
2018-03-07 02:48:32 -06:00
|
|
|
|
<span class="name"><b>{{ i.parent.name }}</b></span>
|
|
|
|
|
<span class="username">@{{ i.parent.username }}</span>
|
2018-03-29 00:48:47 -05:00
|
|
|
|
<mk-time :time="i.createdAt"/>
|
2018-03-07 02:48:32 -06:00
|
|
|
|
</div>
|
|
|
|
|
</section>
|
|
|
|
|
<section v-if="myGames.length > 0">
|
|
|
|
|
<h2>自分の対局</h2>
|
2018-06-16 18:10:54 -05:00
|
|
|
|
<a class="game" v-for="g in myGames" tabindex="-1" @click.prevent="go(g)" :href="`/reversi/${g.id}`">
|
2018-05-04 02:56:23 -05:00
|
|
|
|
<mk-avatar class="avatar" :user="g.user1"/>
|
|
|
|
|
<mk-avatar class="avatar" :user="g.user2"/>
|
2018-03-08 02:57:57 -06:00
|
|
|
|
<span><b>{{ g.user1.name }}</b> vs <b>{{ g.user2.name }}</b></span>
|
2018-03-29 00:48:47 -05:00
|
|
|
|
<span class="state">{{ g.isEnded ? '終了' : '進行中' }}</span>
|
2018-03-09 22:22:20 -06:00
|
|
|
|
</a>
|
2018-03-06 20:40:40 -06:00
|
|
|
|
</section>
|
2018-03-07 03:45:16 -06:00
|
|
|
|
<section v-if="games.length > 0">
|
2018-03-07 02:48:32 -06:00
|
|
|
|
<h2>みんなの対局</h2>
|
2018-06-16 18:10:54 -05:00
|
|
|
|
<a class="game" v-for="g in games" tabindex="-1" @click.prevent="go(g)" :href="`/reversi/${g.id}`">
|
2018-05-04 02:56:23 -05:00
|
|
|
|
<mk-avatar class="avatar" :user="g.user1"/>
|
|
|
|
|
<mk-avatar class="avatar" :user="g.user2"/>
|
2018-03-08 02:57:57 -06:00
|
|
|
|
<span><b>{{ g.user1.name }}</b> vs <b>{{ g.user2.name }}</b></span>
|
2018-03-29 00:48:47 -05:00
|
|
|
|
<span class="state">{{ g.isEnded ? '終了' : '進行中' }}</span>
|
2018-03-09 22:22:20 -06:00
|
|
|
|
</a>
|
2018-03-06 10:54:56 -06:00
|
|
|
|
</section>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
|
import Vue from 'vue';
|
2018-06-16 18:10:54 -05:00
|
|
|
|
import XGameroom from './reversi.gameroom.vue';
|
2018-03-06 20:40:40 -06:00
|
|
|
|
|
2018-03-06 10:54:56 -06:00
|
|
|
|
export default Vue.extend({
|
2018-03-06 20:40:40 -06:00
|
|
|
|
components: {
|
2018-03-08 02:57:57 -06:00
|
|
|
|
XGameroom
|
2018-03-06 20:40:40 -06:00
|
|
|
|
},
|
2018-03-09 10:48:16 -06:00
|
|
|
|
props: ['initGame'],
|
2018-03-06 20:40:40 -06:00
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
game: null,
|
|
|
|
|
games: [],
|
|
|
|
|
gamesFetching: true,
|
|
|
|
|
gamesMoreFetching: false,
|
2018-03-07 02:48:32 -06:00
|
|
|
|
myGames: [],
|
|
|
|
|
matching: null,
|
2018-03-06 20:40:40 -06:00
|
|
|
|
invitations: [],
|
|
|
|
|
connection: null,
|
2018-03-11 04:08:26 -05:00
|
|
|
|
connectionId: null,
|
|
|
|
|
pingClock: null
|
2018-03-06 20:40:40 -06:00
|
|
|
|
};
|
|
|
|
|
},
|
2018-03-09 10:48:16 -06:00
|
|
|
|
watch: {
|
|
|
|
|
game(g) {
|
|
|
|
|
this.$emit('gamed', g);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
created() {
|
|
|
|
|
if (this.initGame) {
|
|
|
|
|
this.game = this.initGame;
|
|
|
|
|
}
|
|
|
|
|
},
|
2018-03-06 20:40:40 -06:00
|
|
|
|
mounted() {
|
2018-06-16 18:10:54 -05:00
|
|
|
|
this.connection = (this as any).os.streams.reversiStream.getConnection();
|
|
|
|
|
this.connectionId = (this as any).os.streams.reversiStream.use();
|
2018-03-06 20:40:40 -06:00
|
|
|
|
|
2018-03-07 02:48:32 -06:00
|
|
|
|
this.connection.on('matched', this.onMatched);
|
2018-03-06 20:40:40 -06:00
|
|
|
|
this.connection.on('invited', this.onInvited);
|
2018-03-06 10:54:56 -06:00
|
|
|
|
|
2018-06-16 18:10:54 -05:00
|
|
|
|
(this as any).api('reversi/games', {
|
2018-03-07 02:48:32 -06:00
|
|
|
|
my: true
|
|
|
|
|
}).then(games => {
|
|
|
|
|
this.myGames = games;
|
|
|
|
|
});
|
|
|
|
|
|
2018-06-16 18:10:54 -05:00
|
|
|
|
(this as any).api('reversi/games').then(games => {
|
2018-03-06 20:40:40 -06:00
|
|
|
|
this.games = games;
|
|
|
|
|
this.gamesFetching = false;
|
|
|
|
|
});
|
|
|
|
|
|
2018-06-16 18:10:54 -05:00
|
|
|
|
(this as any).api('reversi/invitations').then(invitations => {
|
2018-03-06 20:40:40 -06:00
|
|
|
|
this.invitations = this.invitations.concat(invitations);
|
|
|
|
|
});
|
2018-03-11 04:08:26 -05:00
|
|
|
|
|
|
|
|
|
this.pingClock = setInterval(() => {
|
|
|
|
|
if (this.matching) {
|
|
|
|
|
this.connection.send({
|
|
|
|
|
type: 'ping',
|
|
|
|
|
id: this.matching.id
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}, 3000);
|
2018-03-06 20:40:40 -06:00
|
|
|
|
},
|
|
|
|
|
beforeDestroy() {
|
2018-03-07 02:48:32 -06:00
|
|
|
|
this.connection.off('matched', this.onMatched);
|
2018-03-06 20:40:40 -06:00
|
|
|
|
this.connection.off('invited', this.onInvited);
|
2018-06-16 18:10:54 -05:00
|
|
|
|
(this as any).os.streams.reversiStream.dispose(this.connectionId);
|
2018-03-11 04:08:26 -05:00
|
|
|
|
|
|
|
|
|
clearInterval(this.pingClock);
|
2018-03-06 20:40:40 -06:00
|
|
|
|
},
|
|
|
|
|
methods: {
|
2018-03-09 03:29:27 -06:00
|
|
|
|
go(game) {
|
2018-06-16 18:10:54 -05:00
|
|
|
|
(this as any).api('reversi/games/show', {
|
2018-03-29 00:48:47 -05:00
|
|
|
|
gameId: game.id
|
2018-03-09 03:29:27 -06:00
|
|
|
|
}).then(game => {
|
2018-03-11 04:08:26 -05:00
|
|
|
|
this.matching = null;
|
2018-03-09 03:29:27 -06:00
|
|
|
|
this.game = game;
|
|
|
|
|
});
|
|
|
|
|
},
|
2018-03-06 20:40:40 -06:00
|
|
|
|
match() {
|
|
|
|
|
(this as any).apis.input({
|
|
|
|
|
title: 'ユーザー名を入力してください'
|
|
|
|
|
}).then(username => {
|
|
|
|
|
(this as any).api('users/show', {
|
|
|
|
|
username
|
|
|
|
|
}).then(user => {
|
2018-06-16 18:10:54 -05:00
|
|
|
|
(this as any).api('reversi/match', {
|
2018-03-29 00:48:47 -05:00
|
|
|
|
userId: user.id
|
2018-03-06 20:40:40 -06:00
|
|
|
|
}).then(res => {
|
|
|
|
|
if (res == null) {
|
|
|
|
|
this.matching = user;
|
|
|
|
|
} else {
|
|
|
|
|
this.game = res;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
},
|
2018-03-07 02:48:32 -06:00
|
|
|
|
cancel() {
|
|
|
|
|
this.matching = null;
|
2018-06-16 18:10:54 -05:00
|
|
|
|
(this as any).api('reversi/match/cancel');
|
2018-03-07 02:48:32 -06:00
|
|
|
|
},
|
|
|
|
|
accept(invitation) {
|
2018-06-16 18:10:54 -05:00
|
|
|
|
(this as any).api('reversi/match', {
|
2018-03-29 00:48:47 -05:00
|
|
|
|
userId: invitation.parent.id
|
2018-03-07 02:48:32 -06:00
|
|
|
|
}).then(game => {
|
|
|
|
|
if (game) {
|
2018-03-11 04:08:26 -05:00
|
|
|
|
this.matching = null;
|
2018-03-07 02:48:32 -06:00
|
|
|
|
this.game = game;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
2018-03-06 20:40:40 -06:00
|
|
|
|
onMatched(game) {
|
2018-03-11 04:08:26 -05:00
|
|
|
|
this.matching = null;
|
2018-03-06 20:40:40 -06:00
|
|
|
|
this.game = game;
|
|
|
|
|
},
|
|
|
|
|
onInvited(invite) {
|
|
|
|
|
this.invitations.unshift(invite);
|
2018-03-06 10:54:56 -06:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
|
2018-03-07 02:48:32 -06:00
|
|
|
|
<style lang="stylus" scoped>
|
|
|
|
|
@import '~const.styl'
|
|
|
|
|
|
2018-06-16 18:10:54 -05:00
|
|
|
|
.mk-reversi
|
2018-03-07 02:48:32 -06:00
|
|
|
|
color #677f84
|
2018-03-09 10:48:16 -06:00
|
|
|
|
background #fff
|
2018-03-07 02:48:32 -06:00
|
|
|
|
|
|
|
|
|
> .matching
|
|
|
|
|
> h1
|
|
|
|
|
margin 0
|
|
|
|
|
padding 24px
|
|
|
|
|
font-size 20px
|
|
|
|
|
text-align center
|
|
|
|
|
font-weight normal
|
|
|
|
|
|
|
|
|
|
> .cancel
|
|
|
|
|
margin 0 auto
|
|
|
|
|
padding 24px 0 0 0
|
|
|
|
|
max-width 200px
|
|
|
|
|
text-align center
|
|
|
|
|
border-top dashed 1px #c4cdd4
|
|
|
|
|
|
|
|
|
|
> .index
|
|
|
|
|
> h1
|
|
|
|
|
margin 0
|
|
|
|
|
padding 24px
|
|
|
|
|
font-size 24px
|
|
|
|
|
text-align center
|
|
|
|
|
font-weight normal
|
|
|
|
|
color #fff
|
|
|
|
|
background linear-gradient(to bottom, #8bca3e, #d6cf31)
|
|
|
|
|
|
|
|
|
|
& + p
|
|
|
|
|
margin 0
|
|
|
|
|
padding 12px
|
|
|
|
|
margin-bottom 12px
|
|
|
|
|
text-align center
|
|
|
|
|
font-size 14px
|
|
|
|
|
border-bottom solid 1px #d3d9dc
|
|
|
|
|
|
|
|
|
|
> .play
|
|
|
|
|
margin 0 auto
|
|
|
|
|
padding 0 16px
|
|
|
|
|
max-width 500px
|
|
|
|
|
text-align center
|
|
|
|
|
|
|
|
|
|
> details
|
|
|
|
|
margin 8px 0
|
|
|
|
|
|
|
|
|
|
> div
|
|
|
|
|
padding 16px
|
|
|
|
|
font-size 14px
|
|
|
|
|
text-align left
|
|
|
|
|
background #f5f5f5
|
|
|
|
|
border-radius 8px
|
|
|
|
|
|
|
|
|
|
> section
|
|
|
|
|
margin 0 auto
|
|
|
|
|
padding 0 16px 16px 16px
|
|
|
|
|
max-width 500px
|
|
|
|
|
border-top solid 1px #d3d9dc
|
|
|
|
|
|
|
|
|
|
> h2
|
|
|
|
|
margin 0
|
|
|
|
|
padding 16px 0 8px 0
|
|
|
|
|
font-size 16px
|
|
|
|
|
font-weight bold
|
|
|
|
|
|
|
|
|
|
.invitation
|
|
|
|
|
margin 8px 0
|
|
|
|
|
padding 8px
|
|
|
|
|
border solid 1px #e1e5e8
|
|
|
|
|
border-radius 6px
|
|
|
|
|
cursor pointer
|
|
|
|
|
|
|
|
|
|
*
|
|
|
|
|
pointer-events none
|
|
|
|
|
user-select none
|
|
|
|
|
|
|
|
|
|
&:focus
|
|
|
|
|
border-color $theme-color
|
|
|
|
|
|
|
|
|
|
&:hover
|
|
|
|
|
background #f5f5f5
|
|
|
|
|
|
|
|
|
|
&:active
|
|
|
|
|
background #eee
|
|
|
|
|
|
2018-05-04 02:27:03 -05:00
|
|
|
|
> .avatar
|
2018-05-04 03:08:41 -05:00
|
|
|
|
width 32px
|
|
|
|
|
height 32px
|
2018-03-07 02:48:32 -06:00
|
|
|
|
border-radius 100%
|
|
|
|
|
|
|
|
|
|
> span
|
|
|
|
|
margin 0 8px
|
|
|
|
|
line-height 32px
|
|
|
|
|
|
|
|
|
|
.game
|
2018-03-09 22:22:20 -06:00
|
|
|
|
display block
|
2018-03-07 02:48:32 -06:00
|
|
|
|
margin 8px 0
|
|
|
|
|
padding 8px
|
2018-03-09 22:22:20 -06:00
|
|
|
|
color #677f84
|
2018-03-07 02:48:32 -06:00
|
|
|
|
border solid 1px #e1e5e8
|
|
|
|
|
border-radius 6px
|
|
|
|
|
cursor pointer
|
|
|
|
|
|
|
|
|
|
*
|
|
|
|
|
pointer-events none
|
|
|
|
|
user-select none
|
|
|
|
|
|
|
|
|
|
&:focus
|
|
|
|
|
border-color $theme-color
|
|
|
|
|
|
|
|
|
|
&:hover
|
|
|
|
|
background #f5f5f5
|
|
|
|
|
|
|
|
|
|
&:active
|
|
|
|
|
background #eee
|
|
|
|
|
|
2018-05-04 02:27:03 -05:00
|
|
|
|
> .avatar
|
2018-05-04 03:08:41 -05:00
|
|
|
|
width 32px
|
|
|
|
|
height 32px
|
2018-03-07 02:48:32 -06:00
|
|
|
|
border-radius 100%
|
|
|
|
|
|
|
|
|
|
> span
|
|
|
|
|
margin 0 8px
|
|
|
|
|
line-height 32px
|
|
|
|
|
</style>
|