programing rebuy in

This commit is contained in:
wzdwc
2020-04-29 08:20:10 +08:00
parent 2481f5f2d3
commit 4d85239fbb
16 changed files with 972 additions and 133 deletions
+37 -37
View File
@@ -1,37 +1,37 @@
import Vue from 'vue';
import VueRouter, { RouteConfig } from 'vue-router';
import Home from '../views/Home.vue';
import Login from '../views/login.vue';
import Register from '../views/register.vue';
import Game from '../views/game.vue';
Vue.use(VueRouter);
const routes: RouteConfig[] = [
{
path: '/',
name: 'home',
component: Home,
},
{
path: '/login',
name: 'login',
component: Login,
},
{
path: '/register',
name: 'register',
component: Register,
},
{
path: '/game/:roomNumber/:isOwner?',
name: 'game',
component: Game,
},
];
const router = new VueRouter({
routes,
});
export default router;
import Vue from 'vue';
import VueRouter, { RouteConfig } from 'vue-router';
import Home from '../views/Home.vue';
import Login from '../views/login.vue';
import Register from '../views/register.vue';
import Game from '../views/game.vue';
Vue.use(VueRouter);
const routes: RouteConfig[] = [
{
path: '/',
name: 'home',
component: Home,
},
{
path: '/login',
name: 'login',
component: Login,
},
{
path: '/register',
name: 'register',
component: Register,
},
{
path: '/game/:roomNumber/:isOwner?',
name: 'game',
component: Game,
},
];
const router = new VueRouter({
routes,
});
export default router;
+1 -1
View File
@@ -2,7 +2,7 @@ import axios, {AxiosRequestConfig, Method} from 'axios';
import cookie from 'js-cookie';
const request = async ({method = 'post' as Method, url = '', body = {}, timeout = 8000}) => {
const origin = 'http://192.168.0.103:7001/node';
const origin = 'http://192.168.0.101:7001/node';
// const origin = 'http://172.22.72.70:7001/node';
if (!url) {
return Promise.reject('Request url is null!');
+62 -62
View File
@@ -1,62 +1,62 @@
<template>
<div class="home-container container">
<div class="room-btn" v-show="showBtn">
<div class="create-room btn"
@click="createRoom"><span>create room</span>
</div>
<div class="btn"
@click="joinRoom"> <span>join room</span>
</div>
</div>
<div class="room number" v-show="isJoin">
<div class="input-bd">
<div class="input-name">room number:</div>
<div class="input-text">
<input type="tel" maxlength="6"
v-model="roomNumber"/>
</div>
</div>
<div class="btn">
<span @click="go">go</span>
</div>
</div>
</div>
</template>
<script lang="ts">
import { Vue } from 'vue-property-decorator';
import Component from 'vue-class-component';
import service from '../service';
@Component
export default class Home extends Vue {
public roomNumber: string = '';
private isJoin = false;
private showBtn = true;
private async createRoom() {
try {
const result = await service.createRoom();
const { roomNumber } = result.data;
console.log(result);
this.$router.replace({ name: 'game', params: { roomNumber, isOwner: '1' } });
} catch (e) {
console.log(e);
}
}
private joinRoom() {
this.isJoin = true;
this.showBtn = false;
}
private go() {
this.$router.replace({ name: 'game', params: { roomNumber: this.roomNumber } });
}
}
</script>
<style lang="less">
.home-container {
}
</style>
<template>
<div class="home-container container">
<div class="room-btn" v-show="showBtn">
<div class="create-room btn"
@click="createRoom"><span>create room</span>
</div>
<div class="btn"
@click="joinRoom"> <span>join room</span>
</div>
</div>
<div class="room number" v-show="isJoin">
<div class="input-bd">
<div class="input-name">room number:</div>
<div class="input-text">
<input type="tel" maxlength="6"
v-model="roomNumber"/>
</div>
</div>
<div class="btn">
<span @click="go">go</span>
</div>
</div>
</div>
</template>
<script lang="ts">
import { Vue } from 'vue-property-decorator';
import Component from 'vue-class-component';
import service from '../service';
@Component
export default class Home extends Vue {
public roomNumber: string = '';
private isJoin = false;
private showBtn = true;
private async createRoom() {
try {
const result = await service.createRoom();
const { roomNumber } = result.data;
console.log(result);
this.$router.replace({ name: 'game', params: { roomNumber, isOwner: '1' } });
} catch (e) {
console.log(e);
}
}
private joinRoom() {
this.isJoin = true;
this.showBtn = false;
}
private go() {
this.$router.replace({ name: 'game', params: { roomNumber: this.roomNumber } });
}
}
</script>
<style lang="less">
.home-container {
}
</style>
+21 -10
View File
@@ -5,8 +5,9 @@
<div class="users"
v-for="user in users">
<span> {{user.nickName}}: {{user.counter}}</span>
<span>buyIn: {{user.buyIn}}</span>
<span v-show="user.actionSize > 0"> actionSize:{{user.actionSize}} </span>
<span> type:{{user.type}} </span>
<span v-show="user.type"> type:{{user.type}} </span>
<span v-show="gameOver && user.handCard">handCard: {{mapCard(user.handCard)}}</span>
</div>
<div class="join">
@@ -43,7 +44,7 @@
<div class="btn play"
v-show="isOwner && !isPlay"><span @click="play">play game</span></div>
</div>
<div class="buy-in" v-show="showBuyIn">
<div class="buy-in">
<div class="input-bd">
<div class="input-name">buy in:</div>
<div class="input-text">
@@ -61,7 +62,6 @@
import Component from 'vue-class-component';
import io from 'socket.io-client';
import cookie from 'js-cookie';
import service from '../service';
interface IUser {
counter: number;
@@ -71,6 +71,7 @@
type: string;
userId?: number;
handCard?: string[];
buyIn: number;
}
export enum ECommand {
@@ -105,11 +106,11 @@
private showBuyIn = true;
get isPlay() {
return this.pot !== 0 && this.currPlayer?.counter !== 0;
return this.pot !== 0 && this.currPlayer?.buyIn !== 0;
}
get hasBuyIn() {
return this.currPlayer?.counter !== 0;
return this.currPlayer?.buyIn !== 0;
}
get roomId() {
@@ -169,6 +170,10 @@
// check
if ('check' === type) {
return this.prevSize <= 0
|| (this.commonCard.length === 0
&& this.users.length === 2
&& this.currPlayer?.type === 'dealer'
&& this.prevSize === 2)
|| (this.currPlayer?.type === 'big_blind' && this.prevSize === 2 &&
this.commonCard.length === 0);
}
@@ -200,7 +205,7 @@
const token = cookie.get('token');
const log = console.log;
// const origin = 'http://172.22.72.70:7001';
const origin = 'http://192.168.0.103:7001';
const origin = 'http://192.168.0.101:7001';
this.socket = io(`${origin}/socket`, {
// 实际使用中可以在这里传递参数
query: {
@@ -260,13 +265,19 @@
if (msg.action === 'gameOver') {
console.log('gameOver', msg.data);
this.winner = msg.data.winner;
this.winner.forEach((w: IUser[]) => {
this.users = this.users.map((p) => {
const winner = w.find(wPlayer => wPlayer.userId === p.userId);
return Object.assign({}, p, { handCard: winner?.handCard });
const allPlayers = msg.data.allPlayers;
allPlayers.forEach((w: IUser) => {
this.users.forEach((p) => {
if (w.userId === p.userId) {
p.handCard = w.handCard;
}
});
});
}
if (msg.action === 'newGame') {
this.init();
}
});
// 系统事件