fixed bug
This commit is contained in:
Generated
+24
-20
@@ -2,37 +2,36 @@
|
||||
<project version="4">
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="f9039135-aa11-4abd-ad74-f40c84e4fdb2" name="Default Changelist" comment="">
|
||||
<change afterPath="$PROJECT_DIR$/client/src/interface/IRoom.ts" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/client/src/assets/less/base.less" beforeDir="false" afterPath="$PROJECT_DIR$/client/src/assets/less/base.less" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/client/src/components/Action.vue" beforeDir="false" afterPath="$PROJECT_DIR$/client/src/components/Action.vue" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/client/src/components/BuyIn.vue" beforeDir="false" afterPath="$PROJECT_DIR$/client/src/components/BuyIn.vue" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/client/src/components/CommonCard.vue" beforeDir="false" afterPath="$PROJECT_DIR$/client/src/components/CommonCard.vue" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/client/src/components/SitList.vue" beforeDir="false" afterPath="$PROJECT_DIR$/client/src/components/SitList.vue" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/client/src/components/cardList.vue" beforeDir="false" afterPath="$PROJECT_DIR$/client/src/components/cardList.vue" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/client/src/components/notice.vue" beforeDir="false" afterPath="$PROJECT_DIR$/client/src/components/notice.vue" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/client/src/components/range.vue" beforeDir="false" afterPath="$PROJECT_DIR$/client/src/components/range.vue" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/client/src/components/record.vue" beforeDir="false" afterPath="$PROJECT_DIR$/client/src/components/record.vue" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/client/src/components/sendMsg.vue" beforeDir="false" afterPath="$PROJECT_DIR$/client/src/components/sendMsg.vue" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/client/src/components/toast.vue" beforeDir="false" afterPath="$PROJECT_DIR$/client/src/components/toast.vue" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/client/src/components/x-input.vue" beforeDir="false" afterPath="$PROJECT_DIR$/client/src/components/x-input.vue" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/client/src/main.ts" beforeDir="false" afterPath="$PROJECT_DIR$/client/src/main.ts" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/client/src/plugins/toast.ts" beforeDir="false" afterPath="$PROJECT_DIR$/client/src/plugins/toast.ts" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/client/src/router/index.ts" beforeDir="false" afterPath="$PROJECT_DIR$/client/src/router/index.ts" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/client/src/service/index.ts" beforeDir="false" afterPath="$PROJECT_DIR$/client/src/service/index.ts" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/client/src/utils/PokerStyle.ts" beforeDir="false" afterPath="$PROJECT_DIR$/client/src/utils/PokerStyle.ts" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/client/src/utils/origin.ts" beforeDir="false" afterPath="$PROJECT_DIR$/client/src/utils/origin.ts" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/client/src/views/Home.vue" beforeDir="false" afterPath="$PROJECT_DIR$/client/src/views/Home.vue" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/client/src/views/game.vue" beforeDir="false" afterPath="$PROJECT_DIR$/client/src/views/game.vue" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/client/src/views/login.vue" beforeDir="false" afterPath="$PROJECT_DIR$/client/src/views/login.vue" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/client/src/views/register.vue" beforeDir="false" afterPath="$PROJECT_DIR$/client/src/views/register.vue" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/server/src.zip" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/server/src/app/controller/room.ts" beforeDir="false" afterPath="$PROJECT_DIR$/server/src/app/controller/room.ts" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/server/src/app/core/Poker.ts" beforeDir="false" afterPath="$PROJECT_DIR$/server/src/app/core/Poker.ts" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/server/src/app/core/PokerGame.ts" beforeDir="false" afterPath="$PROJECT_DIR$/server/src/app/core/PokerGame.ts" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/server/src/app/core/PokerStyle.ts" beforeDir="false" afterPath="$PROJECT_DIR$/server/src/app/core/PokerStyle.ts" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/server/src/app/io/controller/game.ts" beforeDir="false" afterPath="$PROJECT_DIR$/server/src/app/io/controller/game.ts" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/server/src/app/io/middleware/join.ts" beforeDir="false" afterPath="$PROJECT_DIR$/server/src/app/io/middleware/join.ts" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/server/src/interface/ICommandRecord.ts" beforeDir="false" afterPath="$PROJECT_DIR$/server/src/interface/ICommandRecord.ts" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/server/src/interface/IGame.ts" beforeDir="false" afterPath="$PROJECT_DIR$/server/src/interface/IGame.ts" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/server/src/interface/IGameRecord.ts" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/server/src/interface/IGameRoom.ts" beforeDir="false" afterPath="$PROJECT_DIR$/server/src/interface/IGameRoom.ts" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/server/src/lib/baseSocketController.ts" beforeDir="false" afterPath="$PROJECT_DIR$/server/src/lib/baseSocketController.ts" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/server/src/interface/IRoom.ts" beforeDir="false" afterPath="$PROJECT_DIR$/server/src/interface/IRoom.ts" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/server/src/interface/IUser.ts" beforeDir="false" afterPath="$PROJECT_DIR$/server/src/interface/IUser.ts" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/server/src/service/account.ts" beforeDir="false" afterPath="$PROJECT_DIR$/server/src/service/account.ts" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/server/src/service/commandRecord.ts" beforeDir="false" afterPath="$PROJECT_DIR$/server/src/service/commandRecord.ts" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/server/src/service/game.ts" beforeDir="false" afterPath="$PROJECT_DIR$/server/src/service/game.ts" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/server/src/service/gameRecord.ts" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/server/src/service/room.ts" beforeDir="false" afterPath="$PROJECT_DIR$/server/src/service/room.ts" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/server/src/service/user.ts" beforeDir="false" afterPath="$PROJECT_DIR$/server/src/service/user.ts" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/server/test/app/core/pokerGame.test.ts" beforeDir="false" afterPath="$PROJECT_DIR$/server/test/app/core/pokerGame.test.ts" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/server/test/app/core/pokerStyle.test.ts" beforeDir="false" afterPath="$PROJECT_DIR$/server/test/app/core/pokerStyle.test.ts" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
@@ -42,9 +41,9 @@
|
||||
<component name="FileTemplateManagerImpl">
|
||||
<option name="RECENT_TEMPLATES">
|
||||
<list>
|
||||
<option value="TypeScript File" />
|
||||
<option value="Vue" />
|
||||
<option value="Less File" />
|
||||
<option value="TypeScript File" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
@@ -108,7 +107,8 @@
|
||||
<workItem from="1588168659920" duration="21070000" />
|
||||
<workItem from="1589475961634" duration="559000" />
|
||||
<workItem from="1589732800789" duration="13203000" />
|
||||
<workItem from="1590767628109" duration="35321000" />
|
||||
<workItem from="1590767628109" duration="39193000" />
|
||||
<workItem from="1593066389745" duration="5258000" />
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
@@ -128,6 +128,10 @@
|
||||
<screen x="0" y="0" width="1440" height="900" />
|
||||
</state>
|
||||
<state x="533" y="173" key="#com.intellij.ide.util.MemberChooser/0.0.1440.900@0.0.1440.900" timestamp="1587206645912" />
|
||||
<state x="100" y="100" width="1240" height="700" key="DiffContextDialog" timestamp="1593070402308">
|
||||
<screen x="0" y="0" width="1440" height="900" />
|
||||
</state>
|
||||
<state x="100" y="100" width="1240" height="700" key="DiffContextDialog/0.0.1440.900@0.0.1440.900" timestamp="1593070402308" />
|
||||
<state x="221" y="89" key="SettingsEditor" timestamp="1588864041632">
|
||||
<screen x="0" y="0" width="1440" height="900" />
|
||||
</state>
|
||||
@@ -141,10 +145,10 @@
|
||||
<screen x="0" y="0" width="1440" height="900" />
|
||||
</state>
|
||||
<state x="513" y="145" key="com.intellij.openapi.editor.actions.MultiplePasteAction$ClipboardContentChooser/0.0.1440.900@0.0.1440.900" timestamp="1590828749947" />
|
||||
<state x="378" y="207" width="683" height="490" key="find.popup" timestamp="1591498154515">
|
||||
<state x="378" y="207" width="683" height="490" key="find.popup" timestamp="1593070201850">
|
||||
<screen x="0" y="0" width="1440" height="900" />
|
||||
</state>
|
||||
<state x="378" y="207" width="683" height="490" key="find.popup/0.0.1440.900@0.0.1440.900" timestamp="1591498154515" />
|
||||
<state x="378" y="207" width="683" height="490" key="find.popup/0.0.1440.900@0.0.1440.900" timestamp="1593070201850" />
|
||||
<state x="563" y="230" key="refactoring.ChangeSignatureDialog" timestamp="1589900590051">
|
||||
<screen x="0" y="0" width="1440" height="900" />
|
||||
</state>
|
||||
|
||||
@@ -110,11 +110,13 @@ import { IPlayer } from '@/interface/IPlayer';
|
||||
}
|
||||
|
||||
private action(command: string) {
|
||||
this.actioned = true;
|
||||
console.log('command:', command)
|
||||
this.$emit('action', command);
|
||||
// this.isAction = false;
|
||||
this.isRaise = false;
|
||||
if (!this.actioned) {
|
||||
this.actioned = true;
|
||||
this.$emit('action', command);
|
||||
// this.isAction = false;
|
||||
this.isRaise = false;
|
||||
this.actioned = false;
|
||||
}
|
||||
}
|
||||
|
||||
private showActionSize(multiple: number) {
|
||||
|
||||
+106
-106
@@ -1,106 +1,106 @@
|
||||
<template>
|
||||
<div class="buy-in"
|
||||
v-show="showBuyIn">
|
||||
<div class="shadow"
|
||||
@click="closeBuyIn"></div>
|
||||
<div class="buy-in-body">
|
||||
<div class="input-bd">
|
||||
<div class="input-name"><span>buy in: </span><input type="number" v-model="buyInSize"></div>
|
||||
<range :max="max"
|
||||
:min="min"
|
||||
v-model="buyInSize"
|
||||
@change="getBuyInSize"></range>
|
||||
</div>
|
||||
<div class="btn"><span @click="buyIn">buy in</span></div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { Component, Prop, Watch, Vue } from 'vue-property-decorator';
|
||||
import range from '../components/range.vue';
|
||||
|
||||
@Component({
|
||||
components: {
|
||||
range,
|
||||
},
|
||||
})
|
||||
export default class BuyIn extends Vue {
|
||||
@Prop() private showBuyIn!: boolean;
|
||||
@Prop() private min!: number;
|
||||
@Prop() private max!: number;
|
||||
private buyInSize: number = 0;
|
||||
|
||||
@Watch('buyInSize')
|
||||
private wBuyInSize(val: number) {
|
||||
this.buyInSize = val > this.max ? this.max : val < this.min ? this.min : val;
|
||||
}
|
||||
|
||||
private getBuyInSize(val: string) {
|
||||
this.buyInSize = Number(val);
|
||||
}
|
||||
|
||||
private closeBuyIn() {
|
||||
this.$emit('update:showBuyIn', false);
|
||||
}
|
||||
|
||||
private async buyIn() {
|
||||
this.closeBuyIn();
|
||||
this.$emit('buyIn', this.buyInSize);
|
||||
}
|
||||
private mounted() {
|
||||
this.buyInSize = this.min;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
||||
<style scoped
|
||||
lang="less">
|
||||
.buy-in {
|
||||
position: fixed;
|
||||
z-index: 99;
|
||||
|
||||
.shadow {
|
||||
position: fixed;
|
||||
z-index: 9;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.buy-in-body {
|
||||
z-index: 99;
|
||||
position: fixed;
|
||||
left: 50%;
|
||||
top: 50%;
|
||||
margin: -100px -150px;
|
||||
width: 300px;
|
||||
border-radius: 12px;
|
||||
box-sizing: border-box;
|
||||
background: #fff;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.input-text {
|
||||
input {
|
||||
width: 100px;
|
||||
}
|
||||
}
|
||||
.input-name{
|
||||
margin-bottom: 15px;
|
||||
font-size: 20px;
|
||||
text-align: center;
|
||||
input{
|
||||
width: 50px;
|
||||
font-size: 20px;
|
||||
}
|
||||
}
|
||||
.btn{
|
||||
margin-top: 20px;
|
||||
}
|
||||
}
|
||||
|
||||
</style>
|
||||
<template>
|
||||
<div class="buy-in"
|
||||
v-show="showBuyIn">
|
||||
<div class="shadow"
|
||||
@click="closeBuyIn"></div>
|
||||
<div class="buy-in-body">
|
||||
<div class="input-bd">
|
||||
<div class="input-name"><span>buy in: </span><input type="number" v-model="buyInSize"></div>
|
||||
<range :max="max"
|
||||
:min="min"
|
||||
v-model="buyInSize"
|
||||
@change="getBuyInSize"></range>
|
||||
</div>
|
||||
<div class="btn"><span @click="buyIn">buy in</span></div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { Component, Prop, Watch, Vue } from 'vue-property-decorator';
|
||||
import range from '../components/range.vue';
|
||||
|
||||
@Component({
|
||||
components: {
|
||||
range,
|
||||
},
|
||||
})
|
||||
export default class BuyIn extends Vue {
|
||||
@Prop() private showBuyIn!: boolean;
|
||||
@Prop() private min!: number;
|
||||
@Prop() private max!: number;
|
||||
private buyInSize: number = 0;
|
||||
|
||||
@Watch('buyInSize')
|
||||
private wBuyInSize(val: number) {
|
||||
this.buyInSize = val > this.max ? this.max : val < this.min ? this.min : val;
|
||||
}
|
||||
|
||||
private getBuyInSize(val: string) {
|
||||
this.buyInSize = Number(val);
|
||||
}
|
||||
|
||||
private closeBuyIn() {
|
||||
this.$emit('update:showBuyIn', false);
|
||||
}
|
||||
|
||||
private async buyIn() {
|
||||
this.closeBuyIn();
|
||||
this.$emit('buyIn', this.buyInSize);
|
||||
}
|
||||
private mounted() {
|
||||
this.buyInSize = this.min;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
||||
<style scoped
|
||||
lang="less">
|
||||
.buy-in {
|
||||
position: fixed;
|
||||
z-index: 99;
|
||||
|
||||
.shadow {
|
||||
position: fixed;
|
||||
z-index: 9;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.buy-in-body {
|
||||
z-index: 99;
|
||||
position: fixed;
|
||||
left: 50%;
|
||||
top: 50%;
|
||||
margin: -100px -150px;
|
||||
width: 300px;
|
||||
border-radius: 12px;
|
||||
box-sizing: border-box;
|
||||
background: #fff;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.input-text {
|
||||
input {
|
||||
width: 100px;
|
||||
}
|
||||
}
|
||||
.input-name{
|
||||
margin-bottom: 15px;
|
||||
font-size: 20px;
|
||||
text-align: center;
|
||||
input{
|
||||
width: 50px;
|
||||
font-size: 20px;
|
||||
}
|
||||
}
|
||||
.btn{
|
||||
margin-top: 20px;
|
||||
}
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
@@ -92,6 +92,7 @@
|
||||
import BuyIn from '@/components/BuyIn.vue';
|
||||
import { PokerStyle } from '@/utils/PokerStyle';
|
||||
import map from '../utils/map';
|
||||
import {IRoom} from '@/interface/IRoom';
|
||||
|
||||
@Component({
|
||||
components: {
|
||||
@@ -107,6 +108,7 @@
|
||||
@Prop() private handCard!: string[];
|
||||
@Prop() private winner!: IPlayer[][];
|
||||
@Prop() private isPlay!: boolean;
|
||||
@Prop() private roomConfig!: IRoom;
|
||||
@Prop() private actionUserId!: string;
|
||||
@Prop() private valueCards!: string;
|
||||
@Prop({ default: 30, type: Number }) private time!: number;
|
||||
@@ -141,7 +143,7 @@
|
||||
handCard = cards;
|
||||
}
|
||||
const card = [...handCard, ...commonCard];
|
||||
const style = new PokerStyle(card);
|
||||
const style = new PokerStyle(card, this.roomConfig.isShort);
|
||||
return style.getPokerStyleName();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
<template>
|
||||
<div class="record-container"
|
||||
v-show="show">
|
||||
<div class="shadow"
|
||||
@click="show = false"></div>
|
||||
<div class="body">
|
||||
<div class="title">record</div>
|
||||
<ul>
|
||||
<li>
|
||||
<i>nickName</i>
|
||||
<i>buy in</i>
|
||||
<i>counter</i>
|
||||
<i>income</i>
|
||||
</li>
|
||||
<li v-for="player in players">
|
||||
<i>{{player.nickName}}</i>
|
||||
<i>{{player.buyIn}}</i>
|
||||
<i>{{player.counter}}</i>
|
||||
<i>{{player.counter - player.buyIn}}</i>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { Component, Prop, Vue } from 'vue-property-decorator';
|
||||
import { IPlayer } from '@/interface/IPlayer';
|
||||
|
||||
@Component({
|
||||
components: {},
|
||||
})
|
||||
export default class Record extends Vue {
|
||||
@Prop() private value!: boolean;
|
||||
@Prop() private players!: IPlayer[];
|
||||
|
||||
get show() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
set show(val) {
|
||||
this.$emit('input', val);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
||||
<style scoped
|
||||
lang="less">
|
||||
.record-container {
|
||||
width: 80vw;
|
||||
height: 100vh;
|
||||
color: #fff;
|
||||
background: #2a2a2a;
|
||||
position: absolute;
|
||||
right: 0;
|
||||
top: 0;
|
||||
z-index: 9999;
|
||||
|
||||
.shadow {
|
||||
background: rgba(0, 0, 0, 0.3);
|
||||
left: 0;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
position: fixed;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.body {
|
||||
position: relative;
|
||||
z-index: 9;
|
||||
}
|
||||
|
||||
.title {
|
||||
color: #fff;
|
||||
text-align: left;
|
||||
line-height: 30px;
|
||||
padding: 5px 10px;
|
||||
border-bottom: 1px solid #fff;
|
||||
}
|
||||
|
||||
ul {
|
||||
li {
|
||||
display: flex;
|
||||
|
||||
i {
|
||||
flex: 1;
|
||||
padding: 5px 10px;
|
||||
font-size: 16px;
|
||||
line-height: 20px;
|
||||
display: inline-block;
|
||||
font-style: normal;
|
||||
font-size: 12px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
</style>
|
||||
@@ -0,0 +1,176 @@
|
||||
<template>
|
||||
<div class="sit-container">
|
||||
<div class="sit-player"
|
||||
v-if="sit.player">
|
||||
<div class="player"
|
||||
:class="{fold: sit.player.status === -1}">
|
||||
<div class="count-down"
|
||||
v-show="actionUserId === sit.player.userId">{{time}}
|
||||
</div>
|
||||
<div class="user-name"
|
||||
v-show="sit.player.nickName">
|
||||
{{ sit.player.nickName }}
|
||||
</div>
|
||||
<div class="icon iconfont icon-user-avatar"></div>
|
||||
<div class="counter"
|
||||
v-show="sit.player.counter || sit.player.actionCommand === 'allin'">
|
||||
{{ sit.player.counter }}
|
||||
</div>
|
||||
<div class="action-size"
|
||||
v-show="sit.player.actionSize > 0">
|
||||
{{ sit.player.actionSize }}
|
||||
</div>
|
||||
<div class="action-command"
|
||||
v-show="sit.player.actionCommand">
|
||||
{{ sit.player.actionCommand }}
|
||||
</div>
|
||||
<div class="type"
|
||||
v-show="sit.player.type">
|
||||
{{ sit.player.type }}
|
||||
</div>
|
||||
<div class="hand-card"
|
||||
v-show="!!!currPlayer || (sit.player.userId !== currPlayer.userId
|
||||
&& sit.player.handCard
|
||||
&& sit.player.handCard.length !== 0)">
|
||||
<cardList :cardList="sit.player.handCard"></cardList>
|
||||
</div>
|
||||
<div class="card-style"
|
||||
v-show="!!!currPlayer || (sit.player.userId !== currPlayer.userId
|
||||
&& sit.player.handCard
|
||||
&& sit.player.handCard.length !== 0)">
|
||||
{{PokeStyle(sit.player.handCard)}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { Component, Prop, Vue } from 'vue-property-decorator';
|
||||
import ISit from '@/interface/ISit';
|
||||
import { IPlayer } from '@/interface/IPlayer';
|
||||
import { PokerStyle } from '@/utils/PokerStyle';
|
||||
|
||||
@Component
|
||||
export default class Sit extends Vue {
|
||||
@Prop() private sit!: ISit;
|
||||
@Prop() private actionUserId!: string;
|
||||
@Prop() private currPlayer!: IPlayer;
|
||||
@Prop() private commonCard!: string[];
|
||||
@Prop() private handCard!: string[];
|
||||
@Prop({ default: 30, type: Number }) private time!: number;
|
||||
|
||||
private PokeStyle(cards: string[]) {
|
||||
if (this.commonCard.length === 0) {
|
||||
return '';
|
||||
}
|
||||
const commonCard = this.commonCard || [];
|
||||
let handCard = this.handCard || [];
|
||||
if (cards) {
|
||||
handCard = cards;
|
||||
}
|
||||
const card = [...handCard, ...commonCard];
|
||||
const style = new PokerStyle(card);
|
||||
return style.getPokerStyleName();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
||||
<style scoped lang="less">
|
||||
.sit-container {
|
||||
.player {
|
||||
position: relative;
|
||||
|
||||
.icon {
|
||||
width: 45 / 3.75vw;
|
||||
height: 45 / 3.75vw;
|
||||
font-size: 45px;
|
||||
line-height: 45 / 3.75vw;
|
||||
border-radius: 50%;
|
||||
margin-bottom: 2px;
|
||||
}
|
||||
|
||||
.user-name {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.count-down {
|
||||
height: 7vh;
|
||||
line-height: 9vh;
|
||||
width: 12vw;
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 14px;
|
||||
color: #fff;
|
||||
font-weight: 700;
|
||||
font-size: 20px;
|
||||
background-image: linear-gradient(0deg, rgba(0, 0, 0, 0.3), transparent);
|
||||
}
|
||||
|
||||
.counter {
|
||||
background-color: rgba(0, 0, 0, 0.6);
|
||||
color: #fff;
|
||||
font-weight: 600;
|
||||
font-size: 12px;
|
||||
border-radius: 2px;
|
||||
|
||||
&.isAction {
|
||||
box-shadow: 0px 0px 6px 4px;
|
||||
}
|
||||
|
||||
&.close-time-out {
|
||||
animation: 300ms timeOut infinite;
|
||||
}
|
||||
}
|
||||
|
||||
.action-command {
|
||||
top: 15 / 6.67vh;
|
||||
left: 45 / 3.75vw;
|
||||
padding: 1px 8px;
|
||||
border-radius: 9px;
|
||||
color: #ffffff;
|
||||
background-color: #2c3e50;
|
||||
text-shadow: 1px 2px 3px rgba(0, 0, 0, 0.3);
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
.card-style {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.type {
|
||||
background-color: #fff;
|
||||
color: #2b2b2b;
|
||||
border-radius: 50%;
|
||||
padding: 2px;
|
||||
width: 15 / 3.75vw;
|
||||
height: 15px;
|
||||
line-height: 16px;
|
||||
position: absolute;
|
||||
top: 53 / 6.67vh;
|
||||
left: 38 / 3.75vw;
|
||||
font-size: 12px;
|
||||
transform: scale(0.8);
|
||||
}
|
||||
|
||||
.action-size {
|
||||
background: rgba(0, 0, 0, 0.3) url("../assets/gold.svg") center left no-repeat;
|
||||
background-size: contain;
|
||||
border-radius: 2px;
|
||||
padding: 1px 4px 1px 12px;
|
||||
text-align: center;
|
||||
min-width: 35 / 3.75vw;
|
||||
color: #fff;
|
||||
font-weight: 600;
|
||||
position: absolute;
|
||||
top: 35 / 6.67vh;
|
||||
left: 40 / 3.75vw;
|
||||
}
|
||||
|
||||
&.fold {
|
||||
opacity: 0.4;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,99 +1,99 @@
|
||||
<template>
|
||||
<div class="slide-bar-container">
|
||||
<!-- <div class="value">{{raiseSize}}</div>-->
|
||||
<div class="range-body">
|
||||
<input type="range"
|
||||
v-model="range"
|
||||
|
||||
:class="{horizontal: !!isHorizontal}">
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { Component, Prop, Vue, Watch } from 'vue-property-decorator';
|
||||
|
||||
@Component
|
||||
export default class Range extends Vue {
|
||||
@Prop({ type: Number, default: 1000 }) private max!: number;
|
||||
@Prop({ type: Number, default: 100 }) private min!: number;
|
||||
@Prop() private value!: any;
|
||||
@Prop({ type: Boolean, default: false }) private isHorizontal!: boolean;
|
||||
// private range = 0;
|
||||
private rangeRound = (this.max - this.min) / 100
|
||||
|
||||
get range() {
|
||||
const valNum = Number(this.value);
|
||||
const size = valNum >= this.max ? this.max / this.rangeRound :
|
||||
valNum < this.min ? 0 : (valNum - this.min) / this.rangeRound;
|
||||
return size;
|
||||
}
|
||||
|
||||
set range(val) {
|
||||
const valNum = Number(val);
|
||||
const size = Number(val) === 0 ? this.min : Math.floor(valNum / 100 * (this.max - this.min)) +
|
||||
this.min;
|
||||
console.log('size', size);
|
||||
this.$emit('change', size);
|
||||
this.$emit('input', size);
|
||||
}
|
||||
|
||||
// @Watch('range')
|
||||
// private raiseSize(val: string) {
|
||||
// const valNum = Number(val);
|
||||
// const size = Number(val) === 0 ? this.min : Math.floor(valNum / 100 * (this.max - this.min)) +
|
||||
// this.min;
|
||||
// console.log('size', size);
|
||||
// this.$emit('change', size);
|
||||
// }
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
||||
<style scoped
|
||||
lang="less">
|
||||
.slide-bar-container {
|
||||
.range-body {
|
||||
line-height: 10px;
|
||||
}
|
||||
|
||||
.value {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
input[type=range] {
|
||||
-webkit-appearance: none;
|
||||
width: 200px;
|
||||
border-radius: 10px; /*这个属性设置使填充进度条时的图形为圆角*/
|
||||
vertical-align: middle;
|
||||
display: inline-block;
|
||||
|
||||
&.horizontal {
|
||||
transform: rotateZ(-90deg) translate3d(-50%, 0, 0);
|
||||
transform-origin: center;
|
||||
margin-left: -8px;
|
||||
}
|
||||
}
|
||||
|
||||
input[type=range]:focus {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
input[type=range]::-webkit-slider-thumb {
|
||||
-webkit-appearance: none;
|
||||
height: 30px;
|
||||
width: 30px;
|
||||
margin-top: -12px; /*使滑块超出轨道部分的偏移量相等*/
|
||||
background: #ffffff;
|
||||
border-radius: 50%; /*外观设置为圆形*/
|
||||
border: solid 0.125em rgba(205, 224, 230, 0.5); /*设置边框*/
|
||||
box-shadow: 0 .125em .125em #3b4547; /*添加底部阴影*/
|
||||
}
|
||||
|
||||
input[type=range]::-webkit-slider-runnable-track {
|
||||
height: 6px;
|
||||
border-radius: 10px; /*将轨道设为圆角的*/
|
||||
box-shadow: 0 1px 1px #def3f8, inset 0 .125em .125em #0d1112; /*轨道内置阴影效果*/
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<template>
|
||||
<div class="slide-bar-container">
|
||||
<!-- <div class="value">{{raiseSize}}</div>-->
|
||||
<div class="range-body">
|
||||
<input type="range"
|
||||
v-model="range"
|
||||
|
||||
:class="{horizontal: !!isHorizontal}">
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { Component, Prop, Vue, Watch } from 'vue-property-decorator';
|
||||
|
||||
@Component
|
||||
export default class Range extends Vue {
|
||||
@Prop({ type: Number, default: 1000 }) private max!: number;
|
||||
@Prop({ type: Number, default: 100 }) private min!: number;
|
||||
@Prop() private value!: any;
|
||||
@Prop({ type: Boolean, default: false }) private isHorizontal!: boolean;
|
||||
// private range = 0;
|
||||
private rangeRound = (this.max - this.min) / 100
|
||||
|
||||
get range() {
|
||||
const valNum = Number(this.value);
|
||||
const size = valNum >= this.max ? this.max / this.rangeRound :
|
||||
valNum < this.min ? 0 : (valNum - this.min) / this.rangeRound;
|
||||
return size;
|
||||
}
|
||||
|
||||
set range(val) {
|
||||
const valNum = Number(val);
|
||||
const size = Number(val) === 0 ? this.min : Math.floor(valNum / 100 * (this.max - this.min)) +
|
||||
this.min;
|
||||
console.log('size', size);
|
||||
this.$emit('change', size);
|
||||
this.$emit('input', size);
|
||||
}
|
||||
|
||||
// @Watch('range')
|
||||
// private raiseSize(val: string) {
|
||||
// const valNum = Number(val);
|
||||
// const size = Number(val) === 0 ? this.min : Math.floor(valNum / 100 * (this.max - this.min)) +
|
||||
// this.min;
|
||||
// console.log('size', size);
|
||||
// this.$emit('change', size);
|
||||
// }
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
||||
<style scoped
|
||||
lang="less">
|
||||
.slide-bar-container {
|
||||
.range-body {
|
||||
line-height: 10px;
|
||||
}
|
||||
|
||||
.value {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
input[type=range] {
|
||||
-webkit-appearance: none;
|
||||
width: 200px;
|
||||
border-radius: 10px; /*这个属性设置使填充进度条时的图形为圆角*/
|
||||
vertical-align: middle;
|
||||
display: inline-block;
|
||||
|
||||
&.horizontal {
|
||||
transform: rotateZ(-90deg) translate3d(-50%, 0, 0);
|
||||
transform-origin: center;
|
||||
margin-left: -8px;
|
||||
}
|
||||
}
|
||||
|
||||
input[type=range]:focus {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
input[type=range]::-webkit-slider-thumb {
|
||||
-webkit-appearance: none;
|
||||
height: 30px;
|
||||
width: 30px;
|
||||
margin-top: -12px; /*使滑块超出轨道部分的偏移量相等*/
|
||||
background: #ffffff;
|
||||
border-radius: 50%; /*外观设置为圆形*/
|
||||
border: solid 0.125em rgba(205, 224, 230, 0.5); /*设置边框*/
|
||||
box-shadow: 0 .125em .125em #3b4547; /*添加底部阴影*/
|
||||
}
|
||||
|
||||
input[type=range]::-webkit-slider-runnable-track {
|
||||
height: 6px;
|
||||
border-radius: 10px; /*将轨道设为圆角的*/
|
||||
box-shadow: 0 1px 1px #def3f8, inset 0 .125em .125em #0d1112; /*轨道内置阴影效果*/
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
export interface IRoom {
|
||||
roomNumber?: string;
|
||||
isShort: boolean;
|
||||
time?: number;
|
||||
smallBlind: number;
|
||||
}
|
||||
+32
-28
@@ -1,28 +1,32 @@
|
||||
import request from '../utils/request';
|
||||
|
||||
export default {
|
||||
register: ({ userAccount = '', password = '', nickName = '' }) => request({
|
||||
url: '/user/register',
|
||||
body: { userAccount, password, nickName },
|
||||
}),
|
||||
login: (userAccount: string, password: string ) => request({
|
||||
url: '/user/login',
|
||||
body: { userAccount, password },
|
||||
}),
|
||||
checkLogin: () => request({
|
||||
url: '/user',
|
||||
body: {},
|
||||
}),
|
||||
createRoom: () => request({
|
||||
url: '/game/room',
|
||||
body: { },
|
||||
}),
|
||||
findRoom: (roomNumber: string) => request({
|
||||
url: '/game/room/find',
|
||||
body: { roomNumber },
|
||||
}),
|
||||
buyIn: (buyInSize: number) => request({
|
||||
url: '/game/buyIn',
|
||||
body: { buyInSize },
|
||||
}),
|
||||
};
|
||||
import request from '../utils/request';
|
||||
|
||||
export default {
|
||||
register: ({ userAccount = '', password = '', nickName = '' }) => request({
|
||||
url: '/user/register',
|
||||
body: { userAccount, password, nickName },
|
||||
}),
|
||||
login: (userAccount: string, password: string ) => request({
|
||||
url: '/user/login',
|
||||
body: { userAccount, password },
|
||||
}),
|
||||
checkLogin: () => request({
|
||||
url: '/user',
|
||||
body: {},
|
||||
}),
|
||||
createRoom: (isShort: boolean, smallBlind: number, time: number) => request({
|
||||
url: '/game/room',
|
||||
body: { isShort, smallBlind, time },
|
||||
}),
|
||||
findRoom: (roomNumber: string) => request({
|
||||
url: '/game/room/find',
|
||||
body: { roomNumber },
|
||||
}),
|
||||
buyIn: (buyInSize: number) => request({
|
||||
url: '/game/buyIn',
|
||||
body: { buyInSize },
|
||||
}),
|
||||
recordList: (roomNumber: string) => request({
|
||||
url: '/game/record/find',
|
||||
body: { roomNumber },
|
||||
}),
|
||||
};
|
||||
|
||||
+326
-265
@@ -1,265 +1,326 @@
|
||||
const POKER_STR = 'abcdefghijklm';
|
||||
|
||||
function sort(cards: string []): string[] {
|
||||
let temp = '';
|
||||
// 排序
|
||||
for (let i = 0; i < cards.length; i++) {
|
||||
for (let j = i + 1; j < cards.length; j++) {
|
||||
if (cards[i] > cards[j]) {
|
||||
temp = cards[i];
|
||||
cards[i] = cards[j];
|
||||
cards[j] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
return cards;
|
||||
}
|
||||
|
||||
interface IPokerStyle {
|
||||
init(): void;
|
||||
|
||||
isStraight(str?: string []): string;
|
||||
}
|
||||
|
||||
enum PokerStyleEnum {
|
||||
'ROYAL_FlUSH',
|
||||
'STRAIGHT_FLUSH',
|
||||
'FOUR_KIND',
|
||||
'FULL_HOUSE',
|
||||
'FLUSH',
|
||||
'STRAIGHT',
|
||||
'THREE_KIND',
|
||||
'TWO_PAIR',
|
||||
'PAIR',
|
||||
'HIGH_CARD',
|
||||
}
|
||||
export class PokerStyle implements IPokerStyle {
|
||||
private readonly cards: string[] = [];
|
||||
private flushObj: { [key: string]: any } = {
|
||||
1: [],
|
||||
2: [],
|
||||
3: [],
|
||||
4: [],
|
||||
};
|
||||
private flushColor: string = '';
|
||||
private straightArr: string[] = [];
|
||||
private styleName = [
|
||||
'ROYAL_FlUSH',
|
||||
'STRAIGHT_FLUSH',
|
||||
'FOUR_KIND',
|
||||
'FULL_HOUSE',
|
||||
'FLUSH',
|
||||
'STRAIGHT',
|
||||
'THREE_KIND',
|
||||
'TWO_PAIR',
|
||||
'PAIR',
|
||||
'HIGH_CARD'];
|
||||
private pokerStyle: string[] = [
|
||||
'0',
|
||||
'0',
|
||||
'0',
|
||||
'0',
|
||||
'0',
|
||||
'0',
|
||||
'0',
|
||||
'0',
|
||||
'0',
|
||||
'0'];
|
||||
private numObj: Map<string, number> = new Map(
|
||||
POKER_STR.split('').map((m) => [m, 0]));
|
||||
|
||||
constructor(cards: string[]) {
|
||||
this.cards = sort(cards);
|
||||
this.init();
|
||||
}
|
||||
|
||||
public isStraight(str?: string []): string {
|
||||
const straightStr = str && str.join('') || [ ...new Set(this.straightArr) ].join('');
|
||||
let first = -1;
|
||||
let second = -1;
|
||||
let three = -1;
|
||||
function indexOf(pokeString: string): number {
|
||||
return POKER_STR.indexOf(pokeString);
|
||||
}
|
||||
if (straightStr.length === 5 && indexOf(straightStr) > -1) {
|
||||
return POKER_STR.slice(indexOf(straightStr), indexOf(straightStr) + 5);
|
||||
}
|
||||
if (straightStr.length === 6) {
|
||||
first = indexOf(straightStr.slice(0, 5));
|
||||
second = indexOf(straightStr.slice(1, 6));
|
||||
if (Math.max(first, second) > -1) {
|
||||
const max = Math.max(first, second);
|
||||
return POKER_STR.slice(max, max + 5);
|
||||
}
|
||||
}
|
||||
if (straightStr.length === 7) {
|
||||
first = indexOf(straightStr.slice(0, 5));
|
||||
second = indexOf(straightStr.slice(1, 6));
|
||||
three = indexOf(straightStr.slice(2, 7));
|
||||
if (Math.max(first, second, three) > -1) {
|
||||
const max = Math.max(first, second, three);
|
||||
return POKER_STR.slice(max, max + 5);
|
||||
}
|
||||
}
|
||||
// special straight "A2345",'m' -> A
|
||||
if (straightStr.indexOf('m') > -1 && straightStr.indexOf('abcd') > -1) {
|
||||
return 'mabcd';
|
||||
}
|
||||
return '0';
|
||||
}
|
||||
|
||||
public getPokerWeight() {
|
||||
return this.pokerStyle.join('');
|
||||
}
|
||||
|
||||
public getPokerStyleName() {
|
||||
for (let i = 0; i < this.pokerStyle.length; i++) {
|
||||
if (this.pokerStyle[i] !== '0') {
|
||||
return this.styleName[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public init() {
|
||||
let i = 0;
|
||||
const isTwo = [];
|
||||
const isThree = [];
|
||||
let isFour = '0';
|
||||
let isFullHouse = '0';
|
||||
// const isStraightFlush = '0';
|
||||
let isFlush: string[] = [];
|
||||
let isRoyalFlush = '0';
|
||||
let isThreeKind = '';
|
||||
let isTowPair = '';
|
||||
let isPair = '';
|
||||
const highCard = [];
|
||||
|
||||
while (i < this.cards.length) {
|
||||
const color = this.cards[i][1];
|
||||
const num = this.cards[i][0];
|
||||
this.straightArr.push(this.cards[i][0]);
|
||||
this.flushObj[color].push(num);
|
||||
let value = this.numObj.get(num) || 0;
|
||||
value++;
|
||||
this.numObj.set(num, value);
|
||||
i++;
|
||||
}
|
||||
|
||||
// find flush
|
||||
for (const f in this.flushObj) {
|
||||
if (this.flushObj[f].length >= 5) {
|
||||
// flush is order,so flush[length - 1] is max flush card
|
||||
isFlush = this.flushObj[f];
|
||||
this.flushColor = f;
|
||||
}
|
||||
}
|
||||
|
||||
// find two,three,four
|
||||
for (const [key, value] of this.numObj) {
|
||||
// high card
|
||||
if (value === 1) {
|
||||
highCard.unshift(key);
|
||||
}
|
||||
// pairs max count 3, source is small to large
|
||||
if (value >= 2) {
|
||||
isTwo.unshift(key);
|
||||
}
|
||||
// three of kind max count 2
|
||||
if (value === 3) {
|
||||
isThree.unshift(key);
|
||||
}
|
||||
// four of kind only one
|
||||
if (value === 4) {
|
||||
isFour = key;
|
||||
}
|
||||
}
|
||||
// straight flush
|
||||
if (isFlush.length !== 0 && this.isStraight(isFlush) !== '0') {
|
||||
if (this.isStraight(isFlush) === 'ijklm') {
|
||||
isRoyalFlush = 'ijklm';
|
||||
this.pokerStyle[0] = isRoyalFlush;
|
||||
return;
|
||||
}
|
||||
this.pokerStyle[1] = this.isStraight(isFlush).split('').reverse().join('');
|
||||
return;
|
||||
}
|
||||
|
||||
// four of kind
|
||||
if (isFour !== '0') {
|
||||
isFour += highCard[0];
|
||||
this.pokerStyle[2] = isFour;
|
||||
return;
|
||||
}
|
||||
|
||||
// full house
|
||||
if (isThree.length > 0 && isTwo.length > isThree.length ||
|
||||
isThree.length === 2) {
|
||||
const maxTwoCard = isThree.length === 2 ? isThree[1] : isThree[0] ===
|
||||
isTwo[0] ? isTwo[1] : isTwo[0];
|
||||
const maxThree = isThree[0];
|
||||
isFullHouse = maxThree + maxTwoCard;
|
||||
this.pokerStyle[3] = isFullHouse;
|
||||
return;
|
||||
}
|
||||
|
||||
// flush
|
||||
if (isFlush.length !== 0) {
|
||||
isFlush.reverse().length = 5;
|
||||
this.pokerStyle[4] = isFlush.join('');
|
||||
return;
|
||||
}
|
||||
|
||||
// straight
|
||||
if (this.isStraight() !== '0') {
|
||||
this.pokerStyle[5] = `${this.isStraight()}`;
|
||||
return;
|
||||
}
|
||||
|
||||
// three of kind
|
||||
if (isThree.length > 0) {
|
||||
isThreeKind = isThree.join('');
|
||||
isThreeKind += highCard[0] + highCard[1];
|
||||
this.pokerStyle[6] = isThreeKind;
|
||||
return;
|
||||
}
|
||||
// tow pair
|
||||
if (isTwo.length >= 2) {
|
||||
isTowPair = isTwo.join('');
|
||||
// third tow pair card big then high card
|
||||
const highCardForTowPair = isTwo[3] && isTwo[3] > highCard[0]
|
||||
? isTwo[3]
|
||||
: highCard[0];
|
||||
isTowPair += highCardForTowPair;
|
||||
this.pokerStyle[7] = isTowPair;
|
||||
return;
|
||||
}
|
||||
// pair
|
||||
if (isTwo.length === 1) {
|
||||
isPair = isTwo.join('');
|
||||
isPair += highCard[0] + highCard[1] + highCard[2];
|
||||
this.pokerStyle[8] = isPair;
|
||||
return;
|
||||
}
|
||||
// High card
|
||||
highCard.length = 5;
|
||||
this.pokerStyle[9] = highCard.join('');
|
||||
}
|
||||
public getPokerValueCard() {
|
||||
let valueStyle = '';
|
||||
let isFlush = false;
|
||||
this.pokerStyle.forEach((style, key) => {
|
||||
if (style !== '0') {
|
||||
isFlush = key === 1 || key === 4;
|
||||
valueStyle = style;
|
||||
}
|
||||
});
|
||||
const cards = this.cards.filter((card) => {
|
||||
if (isFlush) {
|
||||
return valueStyle.indexOf(card[0]) > -1 && card[1] === this.flushColor;
|
||||
}
|
||||
return valueStyle.indexOf(card[0]) > -1;
|
||||
});
|
||||
cards.reverse().length = 5;
|
||||
return cards;
|
||||
}
|
||||
}
|
||||
const POKER_STR = 'abcdefghijklm';
|
||||
|
||||
function sort(cards: string []): string[] {
|
||||
let temp = '';
|
||||
// 排序
|
||||
for (let i = 0; i < cards.length; i++) {
|
||||
for (let j = i + 1; j < cards.length; j++) {
|
||||
if (cards[i] > cards[j]) {
|
||||
temp = cards[i];
|
||||
cards[i] = cards[j];
|
||||
cards[j] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
return cards;
|
||||
}
|
||||
|
||||
interface IPokerStyle {
|
||||
init(): void;
|
||||
|
||||
isStraight(str?: string []): string;
|
||||
}
|
||||
|
||||
enum PokerStyleEnum {
|
||||
'ROYAL_FlUSH',
|
||||
'STRAIGHT_FLUSH',
|
||||
'FOUR_KIND',
|
||||
'FULL_HOUSE',
|
||||
'FLUSH',
|
||||
'STRAIGHT',
|
||||
'THREE_KIND',
|
||||
'TWO_PAIR',
|
||||
'PAIR',
|
||||
'HIGH_CARD',
|
||||
}
|
||||
|
||||
enum ShortPokerStyleEnum {
|
||||
'ROYAL_FlUSH',
|
||||
'STRAIGHT_FLUSH',
|
||||
'FOUR_KIND',
|
||||
'FLUSH',
|
||||
'FULL_HOUSE',
|
||||
'THREE_KIND',
|
||||
'STRAIGHT',
|
||||
'TWO_PAIR',
|
||||
'PAIR',
|
||||
'HIGH_CARD',
|
||||
}
|
||||
|
||||
export class PokerStyle implements IPokerStyle {
|
||||
private readonly cards: string[] = [];
|
||||
private readonly isShort: boolean;
|
||||
private flushObj: { [key: string]: any } = {
|
||||
1: [],
|
||||
2: [],
|
||||
3: [],
|
||||
4: [],
|
||||
};
|
||||
private flushColor: string = '';
|
||||
private straightArr: string[] = [];
|
||||
private styleName = [
|
||||
'ROYAL_FlUSH',
|
||||
'STRAIGHT_FLUSH',
|
||||
'FOUR_KIND',
|
||||
'FULL_HOUSE',
|
||||
'FLUSH',
|
||||
'STRAIGHT',
|
||||
'THREE_KIND',
|
||||
'TWO_PAIR',
|
||||
'PAIR',
|
||||
'HIGH_CARD'];
|
||||
private pokerStyle: string[] = [
|
||||
'0',
|
||||
'0',
|
||||
'0',
|
||||
'0',
|
||||
'0',
|
||||
'0',
|
||||
'0',
|
||||
'0',
|
||||
'0',
|
||||
'0'];
|
||||
private numObj: Map<string, number> = new Map(
|
||||
POKER_STR.split('').map((m) => [m, 0]));
|
||||
|
||||
constructor(cards: string[], isShort= false) {
|
||||
this.cards = sort(cards);
|
||||
this.isShort = isShort;
|
||||
if (this.isShort) {
|
||||
this.styleName = [
|
||||
'ROYAL_FlUSH',
|
||||
'STRAIGHT_FLUSH',
|
||||
'FOUR_KIND',
|
||||
'FLUSH',
|
||||
'FULL_HOUSE',
|
||||
'THREE_KIND',
|
||||
'STRAIGHT',
|
||||
'TWO_PAIR',
|
||||
'PAIR',
|
||||
'HIGH_CARD',
|
||||
];
|
||||
}
|
||||
this.init();
|
||||
}
|
||||
|
||||
public isStraight(str?: string []): string {
|
||||
const straightStr = str && str.join('') || [ ...new Set(this.straightArr) ].join('');
|
||||
let first = -1;
|
||||
let second = -1;
|
||||
let three = -1;
|
||||
function indexOf(pokeString: string): number {
|
||||
return POKER_STR.indexOf(pokeString);
|
||||
}
|
||||
if (straightStr.length === 5 && indexOf(straightStr) > -1) {
|
||||
return POKER_STR.slice(indexOf(straightStr), indexOf(straightStr) + 5);
|
||||
}
|
||||
if (straightStr.length === 6) {
|
||||
first = indexOf(straightStr.slice(0, 5));
|
||||
second = indexOf(straightStr.slice(1, 6));
|
||||
if (Math.max(first, second) > -1) {
|
||||
const max = Math.max(first, second);
|
||||
return POKER_STR.slice(max, max + 5);
|
||||
}
|
||||
}
|
||||
if (straightStr.length === 7) {
|
||||
first = indexOf(straightStr.slice(0, 5));
|
||||
second = indexOf(straightStr.slice(1, 6));
|
||||
three = indexOf(straightStr.slice(2, 7));
|
||||
if (Math.max(first, second, three) > -1) {
|
||||
const max = Math.max(first, second, three);
|
||||
return POKER_STR.slice(max, max + 5);
|
||||
}
|
||||
}
|
||||
// special straight "A2345",'m' -> A
|
||||
if (!this.isShort && straightStr.indexOf('m') > -1 && straightStr.indexOf('abcd') > -1) {
|
||||
return 'abcdm';
|
||||
}
|
||||
// special straight "A2345",'m' -> A
|
||||
if (this.isShort && straightStr.indexOf('m') > -1 && straightStr.indexOf('efgh') > -1) {
|
||||
return 'efghm';
|
||||
}
|
||||
return '0';
|
||||
}
|
||||
|
||||
public getPokerWeight() {
|
||||
return this.pokerStyle.join('');
|
||||
}
|
||||
|
||||
public getPokerStyleName() {
|
||||
for (let i = 0; i < this.pokerStyle.length; i++) {
|
||||
if (this.pokerStyle[i] !== '0') {
|
||||
return this.styleName[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public init() {
|
||||
let i = 0;
|
||||
const isTwo = [];
|
||||
const isThree = [];
|
||||
let isFour = '0';
|
||||
let isFullHouse = '0';
|
||||
// const isStraightFlush = '0';
|
||||
let isFlush: string[] = [];
|
||||
let isRoyalFlush = '0';
|
||||
let isThreeKind = '';
|
||||
let isTowPair = '';
|
||||
let isPair = '';
|
||||
const highCard = [];
|
||||
|
||||
while (i < this.cards.length) {
|
||||
const color = this.cards[i][1];
|
||||
const num = this.cards[i][0];
|
||||
this.straightArr.push(this.cards[i][0]);
|
||||
this.flushObj[color].push(num);
|
||||
let value = this.numObj.get(num) || 0;
|
||||
value++;
|
||||
this.numObj.set(num, value);
|
||||
i++;
|
||||
}
|
||||
|
||||
// find flush
|
||||
for (const f in this.flushObj) {
|
||||
if (this.flushObj[f].length >= 5) {
|
||||
// flush is order,so flush[length - 1] is max flush card
|
||||
isFlush = this.flushObj[f];
|
||||
this.flushColor = f;
|
||||
}
|
||||
}
|
||||
|
||||
// find two,three,four
|
||||
for (const [key, value] of this.numObj) {
|
||||
// high card
|
||||
if (value === 1) {
|
||||
highCard.unshift(key);
|
||||
}
|
||||
// pairs max count 3, source is small to large
|
||||
if (value >= 2) {
|
||||
isTwo.unshift(key);
|
||||
}
|
||||
// three of kind max count 2
|
||||
if (value === 3) {
|
||||
isThree.unshift(key);
|
||||
}
|
||||
// four of kind only one
|
||||
if (value === 4) {
|
||||
isFour = key;
|
||||
}
|
||||
}
|
||||
// straight flush
|
||||
if (isFlush.length !== 0 && this.isStraight(isFlush) !== '0') {
|
||||
if (this.isStraight(isFlush) === 'ijklm') {
|
||||
isRoyalFlush = 'ijklm';
|
||||
this.pokerStyle[0] = isRoyalFlush;
|
||||
return;
|
||||
}
|
||||
this.pokerStyle[1] = this.isStraight(isFlush).split('').reverse().join('');
|
||||
return;
|
||||
}
|
||||
|
||||
// four of kind
|
||||
if (isFour !== '0') {
|
||||
isFour += highCard[0];
|
||||
this.pokerStyle[2] = isFour;
|
||||
return;
|
||||
}
|
||||
|
||||
// full house
|
||||
if (isThree.length > 0 && isTwo.length > isThree.length ||
|
||||
isThree.length === 2) {
|
||||
const maxTwoCard = isThree.length === 2 ? isThree[1] : isThree[0] ===
|
||||
isTwo[0] ? isTwo[1] : isTwo[0];
|
||||
const maxThree = isThree[0];
|
||||
isFullHouse = maxThree + maxTwoCard;
|
||||
if (this.isShort) {
|
||||
this.pokerStyle[4] = isFullHouse;
|
||||
} else {
|
||||
this.pokerStyle[3] = isFullHouse;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// flush
|
||||
if (isFlush.length !== 0) {
|
||||
isFlush.reverse().length = 5;
|
||||
if (this.isShort) {
|
||||
this.pokerStyle[3] = isFlush.join('');
|
||||
} else {
|
||||
this.pokerStyle[4] = isFlush.join('');
|
||||
}
|
||||
return;
|
||||
}
|
||||
console.log('come in -------', isThree)
|
||||
|
||||
if (this.isShort) {
|
||||
// three of kind
|
||||
if (isThree.length > 0) {
|
||||
isThreeKind = isThree.join('');
|
||||
isThreeKind += highCard[0] + highCard[1];
|
||||
this.pokerStyle[5] = isThreeKind;
|
||||
return;
|
||||
}
|
||||
|
||||
// straight
|
||||
if (this.isStraight() !== '0') {
|
||||
this.pokerStyle[6] = `${this.isStraight()}`;
|
||||
return;
|
||||
}
|
||||
|
||||
} else {
|
||||
// straight
|
||||
if (this.isStraight() !== '0') {
|
||||
this.pokerStyle[5] = `${this.isStraight()}`;
|
||||
return;
|
||||
}
|
||||
|
||||
// three of kind
|
||||
if (isThree.length > 0) {
|
||||
isThreeKind = isThree.join('');
|
||||
isThreeKind += highCard[0] + highCard[1];
|
||||
this.pokerStyle[6] = isThreeKind;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// tow pair
|
||||
if (isTwo.length >= 2) {
|
||||
const towPair = isTwo;
|
||||
towPair.length = 2;
|
||||
isTowPair = towPair.join('');
|
||||
// third tow pair card big then high card
|
||||
const highCardForTowPair = isTwo[3] && isTwo[3] > highCard[0] ? isTwo[3] : highCard[0];
|
||||
isTowPair += highCardForTowPair;
|
||||
this.pokerStyle[7] = isTowPair;
|
||||
return;
|
||||
}
|
||||
// pair
|
||||
if (isTwo.length === 1) {
|
||||
isPair = isTwo.join('');
|
||||
isPair += highCard[0] + highCard[1] + highCard[2];
|
||||
this.pokerStyle[8] = isPair;
|
||||
return;
|
||||
}
|
||||
// High card
|
||||
highCard.length = 5;
|
||||
this.pokerStyle[9] = highCard.join('');
|
||||
}
|
||||
public getPokerValueCard() {
|
||||
let valueStyle = '';
|
||||
let isFlush = false;
|
||||
this.pokerStyle.forEach((style, key) => {
|
||||
if (style !== '0') {
|
||||
isFlush = key === 1 || this.isShort ? key === 3 : key === 4;
|
||||
valueStyle = style;
|
||||
}
|
||||
});
|
||||
const cards = this.cards.filter((card) => {
|
||||
if (isFlush) {
|
||||
return valueStyle.indexOf(card[0]) > -1 && card[1] === this.flushColor;
|
||||
}
|
||||
return valueStyle.indexOf(card[0]) > -1;
|
||||
});
|
||||
cards.reverse().length = 5;
|
||||
return cards;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,29 @@
|
||||
<div class="home-container container">
|
||||
<div class="room-btn"
|
||||
v-show="showBtn">
|
||||
<div class="input-bd">
|
||||
<div class="input-name">smallBlind:</div>
|
||||
<div class="input-text">
|
||||
<input type="tel"
|
||||
v-model="smallBlind"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="input-bd">
|
||||
<div class="input-name">isShort:</div>
|
||||
<div class="input-text">
|
||||
<input type="checkbox"
|
||||
v-model="isShort"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="create-room btn"
|
||||
@click="createRoom"><span>create room</span>
|
||||
</div>
|
||||
<div class="btn"
|
||||
@click="joinRoom"><span>join room</span>
|
||||
</div>
|
||||
<div class="btn"
|
||||
@click="getRecord"><span>test record</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="room-number"
|
||||
v-show="isJoin">
|
||||
@@ -34,6 +51,7 @@
|
||||
import { Vue } from 'vue-property-decorator';
|
||||
import Component from 'vue-class-component';
|
||||
import service from '../service';
|
||||
import cookie from 'js-cookie';
|
||||
|
||||
@Component
|
||||
export default class Home extends Vue {
|
||||
@@ -41,12 +59,18 @@
|
||||
private isJoin = false;
|
||||
private showBtn = true;
|
||||
private isError = false;
|
||||
private isShort = false;
|
||||
private smallBlind = 1;
|
||||
|
||||
private async createRoom() {
|
||||
try {
|
||||
const result = await service.createRoom();
|
||||
const result = await service.createRoom(this.isShort, this.smallBlind, 0);
|
||||
const { roomNumber } = result.data;
|
||||
console.log(result);
|
||||
const roomConfig = {
|
||||
isShort: this.isShort,
|
||||
smallBlind: this.smallBlind,
|
||||
}
|
||||
cookie.set('roomConfig', roomConfig, {expires: 1});
|
||||
this.$router.push({ name: 'game', params: { roomNumber, isOwner: '1' } });
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
@@ -65,7 +89,11 @@
|
||||
}
|
||||
try {
|
||||
const { data } = await service.findRoom(this.roomNumber);
|
||||
if (data.hasRoom) {
|
||||
if (data) {
|
||||
const roomConfig ={
|
||||
...data
|
||||
}
|
||||
cookie.set('roomConfig', roomConfig, {expires: 1});
|
||||
this.$router.push({ name: 'game', params: { roomNumber: this.roomNumber } });
|
||||
} else {
|
||||
this.$plugin.toast('can\'t find the room');
|
||||
@@ -75,6 +103,15 @@
|
||||
this.$plugin.toast('can\'t find the room');
|
||||
}
|
||||
}
|
||||
|
||||
private async getRecord() {
|
||||
try {
|
||||
const { data } = await service.recordList('170432');
|
||||
console.log(data);
|
||||
} catch (e) {
|
||||
this.$plugin.toast('can\'t find the room');
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<style lang="less"
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
@buyIn="buyIn"
|
||||
:isPlay='isPlay'
|
||||
:valueCards='valueCards'
|
||||
:roomConfig = 'roomConfig'
|
||||
:time='time'
|
||||
:winner="winner"
|
||||
:actionUserId='actionUserId'
|
||||
@@ -77,6 +78,7 @@
|
||||
import map from '../utils/map';
|
||||
import { PokerStyle } from '@/utils/PokerStyle';
|
||||
import origin from '../utils/origin';
|
||||
import { IRoom } from '@/interface/IRoom';
|
||||
|
||||
export enum ECommand {
|
||||
CALL = 'call',
|
||||
@@ -133,6 +135,10 @@
|
||||
private msg = '';
|
||||
private time = 30;
|
||||
private timeSt = 0;
|
||||
private roomConfig: IRoom = {
|
||||
isShort: false,
|
||||
smallBlind: 1
|
||||
};
|
||||
private messageList: any[] = [];
|
||||
private showRecord = false;
|
||||
|
||||
@@ -186,7 +192,7 @@
|
||||
get valueCards() {
|
||||
if (this.gameOver && this.winner[0] && this.winner[0][0].handCard) {
|
||||
const handCards = this.winner[0][0].handCard;
|
||||
const style = new PokerStyle([...handCards, ...this.commonCard]);
|
||||
const style = new PokerStyle([...handCards, ...this.commonCard], this.roomConfig.isShort);
|
||||
return style.getPokerValueCard();
|
||||
} else {
|
||||
return [];
|
||||
@@ -260,7 +266,7 @@
|
||||
}
|
||||
const commonCards = this.commonCard || [];
|
||||
const card = [...cards, ...commonCards];
|
||||
const style = new PokerStyle(card);
|
||||
const style = new PokerStyle(card, this.roomConfig.isShort);
|
||||
return style.getPokerStyleName();
|
||||
}
|
||||
|
||||
@@ -295,12 +301,16 @@
|
||||
|
||||
private socketInit() {
|
||||
const token = cookie.get('token');
|
||||
const roomConfig = cookie.get('roomConfig') || '';
|
||||
const log = console.log;
|
||||
this.roomConfig = JSON.parse(roomConfig);
|
||||
console.log(JSON.parse(roomConfig), 'roomConfig');
|
||||
this.socket = io(`${origin.url}/socket`, {
|
||||
// 实际使用中可以在这里传递参数
|
||||
query: {
|
||||
room: this.roomId,
|
||||
token,
|
||||
roomConfig: roomConfig,
|
||||
},
|
||||
transports: ['websocket'],
|
||||
});
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,79 @@
|
||||
import { Context, inject, controller, post, provide } from 'midway';
|
||||
import BaseController from '../../lib/baseController';
|
||||
import { IPlayerService } from '../../interface/IPlayer';
|
||||
import {
|
||||
ICommandRecord,
|
||||
ICommandRecordService,
|
||||
} from '../../interface/ICommandRecord';
|
||||
import { IGameService } from '../../interface/IGame';
|
||||
import { EGameOverType } from '../core/PokerGame';
|
||||
|
||||
interface IFindGameRecord {
|
||||
gameId: number;
|
||||
winners: string;
|
||||
handCard: string;
|
||||
gameInfo: ICommandRecord [];
|
||||
}
|
||||
|
||||
@provide()
|
||||
@controller('/node/game/record')
|
||||
export class GameRecordController extends BaseController {
|
||||
|
||||
@inject()
|
||||
ctx: Context;
|
||||
|
||||
@inject('PlayerRecordService')
|
||||
playerService: IPlayerService;
|
||||
|
||||
@inject('GameService')
|
||||
gameService: IGameService;
|
||||
|
||||
@inject('CommandRecordService')
|
||||
commandService: ICommandRecordService;
|
||||
|
||||
@post('/find')
|
||||
async find() {
|
||||
try {
|
||||
const { body } = this.getRequestBody();
|
||||
const state = this.ctx.state;
|
||||
const playerList = await this.playerService.findByRoomNumber(body.roomNumber);
|
||||
const commandList = await this.commandService.findByRoomNumber(body.roomNumber);
|
||||
const gameList = await this.gameService.findByRoomNumber(body.roomNumber);
|
||||
const result: IFindGameRecord [] = [];
|
||||
console.log(state, 'user');
|
||||
gameList.forEach(g => {
|
||||
if (g.status === EGameOverType.GAME_OVER) {
|
||||
const winner = JSON.parse(g.winners || '')[0][0];
|
||||
delete winner.handCard;
|
||||
g.winners = JSON.stringify([[ winner ]]);
|
||||
}
|
||||
const dateItem: IFindGameRecord = {
|
||||
gameId: g.id || 0,
|
||||
winners: JSON.parse(g.winners || ''),
|
||||
handCard: playerList.find(p => state.user.user.userId !== p.userId)?.handCard || '',
|
||||
gameInfo: commandList.filter(c => c.gameId === g.id) || [],
|
||||
};
|
||||
result.push(dateItem);
|
||||
});
|
||||
|
||||
this.success({
|
||||
result,
|
||||
});
|
||||
} catch (e) {
|
||||
this.fail('invalid game record');
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
@post('/')
|
||||
async index() {
|
||||
try {
|
||||
this.success({
|
||||
test: '1111',
|
||||
});
|
||||
} catch (e) {
|
||||
this.fail('create room error');
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,8 @@ export class RoomController extends BaseController {
|
||||
@post('/')
|
||||
async index() {
|
||||
try {
|
||||
const result = await this.roomService.add();
|
||||
const { body } = this.getRequestBody();
|
||||
const result = await this.roomService.add(body.isShort, body.smallBlind);
|
||||
this.success(result);
|
||||
} catch (e) {
|
||||
this.fail('create room error');
|
||||
@@ -29,8 +30,8 @@ export class RoomController extends BaseController {
|
||||
async find() {
|
||||
try {
|
||||
const { body } = this.getRequestBody();
|
||||
const result = await this.roomService.findByRoomNumber(body.roomNumber);
|
||||
this.success({ hasRoom: result });
|
||||
const result = await this.roomService.findRoomNumber(body.roomNumber);
|
||||
this.success({ ...result });
|
||||
} catch (e) {
|
||||
this.fail('invalid room');
|
||||
console.log(e);
|
||||
|
||||
@@ -11,13 +11,15 @@ export interface IPoker {
|
||||
*/
|
||||
export class Poker implements IPoker {
|
||||
private pokers: string [] = [];
|
||||
private readonly isShort: boolean;
|
||||
|
||||
constructor() {
|
||||
constructor(isShort = false) {
|
||||
this.isShort = isShort;
|
||||
this.init();
|
||||
}
|
||||
|
||||
init(): void {
|
||||
const size = [
|
||||
let size = [
|
||||
'a',
|
||||
'b',
|
||||
'c',
|
||||
@@ -31,6 +33,18 @@ export class Poker implements IPoker {
|
||||
'k',
|
||||
'l',
|
||||
'm' ];
|
||||
if (this.isShort) {
|
||||
size = [
|
||||
'e',
|
||||
'f',
|
||||
'g',
|
||||
'h',
|
||||
'i',
|
||||
'j',
|
||||
'k',
|
||||
'l',
|
||||
'm' ];
|
||||
}
|
||||
const color = [ 1, 2, 3, 4 ];
|
||||
for (const i of size) {
|
||||
for (const j of color) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Created by jorky on 2020/2/23.
|
||||
*/
|
||||
import { Poker } from './Poker';
|
||||
import { IPoker, Poker } from './Poker';
|
||||
import { ECommand, EPlayerType, IPlayer, Player } from './Player';
|
||||
import { PokerStyle } from './PokerStyle';
|
||||
import { ILinkNode, Link } from '../../utils/Link';
|
||||
@@ -10,11 +10,17 @@ import Timeout = NodeJS.Timeout;
|
||||
interface IPokerGame {
|
||||
users: IPlayer[];
|
||||
smallBlind: number;
|
||||
isShort: boolean;
|
||||
actionRoundComplete: () => void;
|
||||
gameOverCallBack: () => void;
|
||||
autoActionCallBack: (actionType: string, userId: string) => void;
|
||||
}
|
||||
|
||||
export enum EGameOverType {
|
||||
GAME_SHOWDOWN = 1,
|
||||
GAME_OVER = 2,
|
||||
}
|
||||
|
||||
export enum EGameStatus {
|
||||
GAME_READY,
|
||||
GAME_START,
|
||||
@@ -33,10 +39,14 @@ export class PokerGame {
|
||||
fireCards: string[] = [];
|
||||
playerLink: Link<Player>;
|
||||
allPlayer: Player[] = [];
|
||||
poker = new Poker();
|
||||
SBPlayer: Player;
|
||||
BBPlayer: Player;
|
||||
poker: IPoker;
|
||||
isShort: boolean;
|
||||
pot: number;
|
||||
slidePots: number [] = [];
|
||||
status: EGameStatus;
|
||||
gameOverType: EGameOverType;
|
||||
currPlayer: ILinkNode<Player>;
|
||||
smallBlind: number;
|
||||
playerSize: number;
|
||||
@@ -56,6 +66,9 @@ export class PokerGame {
|
||||
this.actionRoundComplete = config.actionRoundComplete;
|
||||
this.gameOverCallBack = config.gameOverCallBack;
|
||||
this.autoActionCallBack = config.autoActionCallBack;
|
||||
console.log(config.isShort, 'poker--------------');
|
||||
this.isShort = config.isShort;
|
||||
this.poker = new Poker(this.isShort);
|
||||
if (config.users.length < 2) {
|
||||
throw 'player Inadequate';
|
||||
}
|
||||
@@ -76,16 +89,14 @@ export class PokerGame {
|
||||
getBlind() {
|
||||
// sb blind
|
||||
const SBPlayerNode = this.playerLink.getNode(1);
|
||||
const SBPlayer = SBPlayerNode.node;
|
||||
this.SBPlayer = SBPlayerNode.node;
|
||||
if (SBPlayerNode.next) {
|
||||
// big blind
|
||||
const BBPlayerNode: ILinkNode<Player> = SBPlayerNode.next;
|
||||
const BBPlayer = BBPlayerNode.node;
|
||||
SBPlayer.action(`sb:${this.smallBlind}`);
|
||||
BBPlayer.action(`bb:${this.smallBlind * 2}`);
|
||||
this.BBPlayer = BBPlayerNode.node;
|
||||
this.SBPlayer.action(`sb:${this.smallBlind}`);
|
||||
this.BBPlayer.action(`bb:${this.smallBlind * 2}`);
|
||||
this.prevSize = this.smallBlind * 2;
|
||||
// add counter to pot
|
||||
// this.pots.push(this.smallBlind * 3);
|
||||
this.pot = this.smallBlind * 3;
|
||||
// todo straddle
|
||||
} else {
|
||||
@@ -417,6 +428,7 @@ export class PokerGame {
|
||||
if (this.allInPlayers.length === 0 && this.playerSize === 1
|
||||
|| this.allInPlayers.length === 1 && this.playerSize === 0) {
|
||||
console.log('only one player');
|
||||
this.gameOverType = EGameOverType.GAME_OVER;
|
||||
const winner = this.allInPlayers[0] || this.currPlayer.node;
|
||||
this.status = EGameStatus.GAME_OVER;
|
||||
this.winner.push([ winner ]);
|
||||
@@ -427,6 +439,7 @@ export class PokerGame {
|
||||
this.setSate();
|
||||
}
|
||||
this.status = EGameStatus.GAME_OVER;
|
||||
this.gameOverType = EGameOverType.GAME_SHOWDOWN;
|
||||
|
||||
this.getPlayerPokeStyle();
|
||||
|
||||
@@ -448,7 +461,7 @@ export class PokerGame {
|
||||
|
||||
getPlayerPokeStyle() {
|
||||
this.allPlayer.map(p => {
|
||||
p.pokeStyle = new PokerStyle([ ...p.getHandCard(), ...this.commonCard ]).getPokerWeight();
|
||||
p.pokeStyle = new PokerStyle([ ...p.getHandCard(), ...this.commonCard ], this.isShort).getPokerWeight();
|
||||
return p;
|
||||
});
|
||||
}
|
||||
@@ -465,7 +478,7 @@ export class PokerGame {
|
||||
const maxPlayer = lastPlayers.reduce((acc, cur) => {
|
||||
return this.compareCard(acc, cur) === 1 ? acc : cur;
|
||||
});
|
||||
// has many winner ,equal max player
|
||||
// has many winner equal max player
|
||||
lastPlayers.forEach(p => {
|
||||
if (this.compareCard(p, maxPlayer) === 0) {
|
||||
_maxPlayers.push(p);
|
||||
|
||||
@@ -29,13 +29,15 @@ export class PokerStyle implements IPokerStyle {
|
||||
4: [] as string[],
|
||||
};
|
||||
flushColor: string = '';
|
||||
isShort: boolean;
|
||||
straightArr: string[] = [];
|
||||
pokerStyle: string[] = [ '0', '0', '0', '0', '0', '0', '0', '0', '0', '0' ];
|
||||
numObj: Map<string, number> = new Map(
|
||||
POKER_STR.split('').map(m => [ m, 0 ]));
|
||||
|
||||
constructor(cards: string[]) {
|
||||
constructor(cards: string[], isShort= false) {
|
||||
this.cards = sort(cards);
|
||||
this.isShort = isShort;
|
||||
this.init();
|
||||
}
|
||||
|
||||
@@ -115,33 +117,63 @@ export class PokerStyle implements IPokerStyle {
|
||||
const maxTwoCard = isThree.length === 2 ? isThree[1] : isThree[0] === isTwo[0] ? isTwo[1] : isTwo[0];
|
||||
const maxThree = isThree[0];
|
||||
isFullHouse = maxThree + maxTwoCard;
|
||||
this.pokerStyle[3] = isFullHouse;
|
||||
if (this.isShort) {
|
||||
this.pokerStyle[4] = isFullHouse;
|
||||
} else {
|
||||
this.pokerStyle[3] = isFullHouse;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// flush
|
||||
if (isFlush.length !== 0) {
|
||||
isFlush.reverse().length = 5;
|
||||
this.pokerStyle[4] = isFlush.join('');
|
||||
if (this.isShort) {
|
||||
this.pokerStyle[3] = isFlush.join('');
|
||||
} else {
|
||||
this.pokerStyle[4] = isFlush.join('');
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// straight
|
||||
if (this.isStraight() !== '0') {
|
||||
this.pokerStyle[5] = `${this.isStraight()}`;
|
||||
return;
|
||||
console.log('come in -------', isThree);
|
||||
|
||||
if (this.isShort) {
|
||||
// three of kind
|
||||
if (isThree.length > 0) {
|
||||
isThreeKind = isThree.join('');
|
||||
isThreeKind += highCard[0] + highCard[1];
|
||||
this.pokerStyle[5] = isThreeKind;
|
||||
return;
|
||||
}
|
||||
|
||||
// straight
|
||||
if (this.isStraight() !== '0') {
|
||||
this.pokerStyle[6] = `${this.isStraight()}`;
|
||||
return;
|
||||
}
|
||||
|
||||
} else {
|
||||
// straight
|
||||
if (this.isStraight() !== '0') {
|
||||
this.pokerStyle[5] = `${this.isStraight()}`;
|
||||
return;
|
||||
}
|
||||
|
||||
// three of kind
|
||||
if (isThree.length > 0) {
|
||||
isThreeKind = isThree.join('');
|
||||
isThreeKind += highCard[0] + highCard[1];
|
||||
this.pokerStyle[6] = isThreeKind;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// three of kind
|
||||
if (isThree.length > 0) {
|
||||
isThreeKind = isThree.join('');
|
||||
isThreeKind += highCard[0] + highCard[1];
|
||||
this.pokerStyle[6] = isThreeKind;
|
||||
return;
|
||||
}
|
||||
// tow pair
|
||||
if (isTwo.length >= 2) {
|
||||
isTowPair = isTwo.join('');
|
||||
const towPair = isTwo;
|
||||
towPair.length = 2;
|
||||
isTowPair = towPair.join('');
|
||||
// third tow pair card big then high card
|
||||
const highCardForTowPair = isTwo[3] && isTwo[3] > highCard[0] ? isTwo[3] : highCard[0];
|
||||
isTowPair += highCardForTowPair;
|
||||
@@ -189,8 +221,12 @@ export class PokerStyle implements IPokerStyle {
|
||||
}
|
||||
}
|
||||
// special straight "A2345",'m' -> A
|
||||
if (straightStr.indexOf('m') > -1 && straightStr.indexOf('abcd') > -1) {
|
||||
return 'mabcd';
|
||||
if (!this.isShort && straightStr.indexOf('m') > -1 && straightStr.indexOf('abcd') > -1) {
|
||||
return 'abcdm';
|
||||
}
|
||||
// special straight "A2345",'m' -> A
|
||||
if (this.isShort && straightStr.indexOf('m') > -1 && straightStr.indexOf('efgh') > -1) {
|
||||
return 'efghm';
|
||||
}
|
||||
return '0';
|
||||
}
|
||||
|
||||
@@ -6,13 +6,14 @@ import { IPlayer } from '../../core/Player';
|
||||
import { ILinkNode, Link } from '../../../utils/Link';
|
||||
import { IGame } from '../../../interface/IGame';
|
||||
import { ICommandRecord } from '../../../interface/ICommandRecord';
|
||||
import { IPlayerDTO } from '../../../interface/IPlayer';
|
||||
|
||||
class GameController extends BaseSocketController {
|
||||
|
||||
async playGame() {
|
||||
try {
|
||||
const roomInfo = await this.getRoomInfo();
|
||||
const gameService = await this.app.applicationContext.getAsync('GameService');
|
||||
const playerRecordService = await this.app.applicationContext.getAsync('PlayerRecordService');
|
||||
console.log('players===============sit11111111111', roomInfo.sit);
|
||||
let sitDownPlayer: IPlayer[] = [];
|
||||
if (roomInfo.sitLink) {
|
||||
@@ -40,10 +41,12 @@ class GameController extends BaseSocketController {
|
||||
if (sitDownPlayer.length < 2) {
|
||||
throw 'player not enough';
|
||||
}
|
||||
console.log('roomConfig-------------------', roomInfo.config);
|
||||
if (!roomInfo.game) {
|
||||
roomInfo.game = null;
|
||||
roomInfo.game = new PokerGame({
|
||||
users: sitDownPlayer,
|
||||
isShort: roomInfo.config.isShort,
|
||||
smallBlind: 1,
|
||||
actionRoundComplete: () => {
|
||||
let slidePots: number [] = [];
|
||||
@@ -136,7 +139,7 @@ class GameController extends BaseSocketController {
|
||||
pot: roomInfo.game?.pot || 0,
|
||||
commonCard: roomInfo.game?.commonCard.join(',') || '',
|
||||
winners: JSON.stringify(roomInfo.game?.winner).replace(' ', ''),
|
||||
status: 2,
|
||||
status: roomInfo.game?.gameOverType || 0,
|
||||
};
|
||||
const result = await gameService.update(gameRecord);
|
||||
if (!result.succeed) {
|
||||
@@ -172,20 +175,26 @@ class GameController extends BaseSocketController {
|
||||
console.log('hand card', roomInfo.game.allPlayer);
|
||||
// update counter, pot, status
|
||||
await this.updateGameInfo();
|
||||
roomInfo.players.forEach(p => {
|
||||
// console.log('game msg---------1');
|
||||
for (const p of roomInfo.players) {
|
||||
const player = roomInfo.game?.allPlayer.find(
|
||||
player => player.userId === p.userId);
|
||||
console.log(player, 'game msg---------1');
|
||||
const msg = this.ctx.helper.parseMsg('handCard', {
|
||||
handCard: player?.getHandCard(),
|
||||
}, { client: p.socketId });
|
||||
console.log(msg, 'game msg---------', p.socketId);
|
||||
this.nsp.emit(p.socketId, msg);
|
||||
});
|
||||
const playerRecord: IPlayerDTO = {
|
||||
roomNumber: this.roomNumber,
|
||||
gameId: roomInfo.gameId || 0,
|
||||
userId: player?.userId || '',
|
||||
buyIn: p.buyIn,
|
||||
counter: p.counter,
|
||||
handCard: player?.getHandCard().join(',') || '',
|
||||
};
|
||||
await playerRecordService.add(playerRecord);
|
||||
}
|
||||
// add game record
|
||||
const gameRecord: IGame = {
|
||||
roomId: this.roomNumber,
|
||||
roomNumber: this.roomNumber,
|
||||
pot: 0,
|
||||
commonCard: '',
|
||||
status: 0,
|
||||
@@ -196,6 +205,34 @@ class GameController extends BaseSocketController {
|
||||
} else {
|
||||
throw 'game add error';
|
||||
}
|
||||
// add game BB SB action record
|
||||
const BB = roomInfo.game.BBPlayer;
|
||||
const SB = roomInfo.game.SBPlayer;
|
||||
const BBCommandRecord: ICommandRecord = {
|
||||
roomNumber: this.roomNumber,
|
||||
userId: BB.userId,
|
||||
type: BB.type,
|
||||
gameStatus: 0,
|
||||
pot: 3,
|
||||
commonCard: '',
|
||||
command: 'bb:2',
|
||||
gameId: result.id,
|
||||
counter: BB.counter,
|
||||
};
|
||||
const SBCommandRecord: ICommandRecord = {
|
||||
roomNumber: this.roomNumber,
|
||||
userId: SB.userId,
|
||||
type: SB.type,
|
||||
gameStatus: 0,
|
||||
pot: 1,
|
||||
commonCard: '',
|
||||
command: 'sb:1',
|
||||
gameId: result.id,
|
||||
counter: SB.counter,
|
||||
};
|
||||
const commandRecordService = await this.app.applicationContext.getAsync('CommandRecordService');
|
||||
await commandRecordService.add(SBCommandRecord);
|
||||
await commandRecordService.add(BBCommandRecord);
|
||||
} else {
|
||||
throw 'game already paling';
|
||||
}
|
||||
@@ -221,22 +258,25 @@ class GameController extends BaseSocketController {
|
||||
// calculate re buy in
|
||||
roomInfo.sit.forEach((s: ISit) => {
|
||||
if (s.player) {
|
||||
if (s.player.counter === 0) {
|
||||
delete s.player;
|
||||
} else {
|
||||
console.log('roomInfo.players===============', roomInfo.players);
|
||||
const player = roomInfo.players.find(
|
||||
p => p.userId === s.player?.userId);
|
||||
if (player) {
|
||||
s.player.counter += Number(player.reBuy);
|
||||
console.log('cal reBuy ===============================', s.player,
|
||||
player.reBuy);
|
||||
player.reBuy = 0;
|
||||
s.player.reBuy = 0;
|
||||
}
|
||||
const player = roomInfo.players.find(
|
||||
p => p.userId === s.player?.userId);
|
||||
if (player) {
|
||||
s.player.counter += Number(player.reBuy);
|
||||
console.log('cal reBuy ===============================', s.player,
|
||||
player.reBuy);
|
||||
player.reBuy = 0;
|
||||
s.player.reBuy = 0;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// clear counter not enough player
|
||||
roomInfo.sit.forEach((s: ISit) => {
|
||||
if (s.player && s.player.counter === 0) {
|
||||
delete s.player;
|
||||
}
|
||||
});
|
||||
|
||||
const players = roomInfo.sit.filter(s => s.player && s.player.counter > 0)
|
||||
.map(s => s.player) || [];
|
||||
let link: ILinkNode<IPlayer> | null = new Link<IPlayer>(players).link;
|
||||
@@ -289,6 +329,7 @@ class GameController extends BaseSocketController {
|
||||
const roomInfo: IRoomInfo = await this.getRoomInfo();
|
||||
const { payload } = this.ctx.args[0] || {};
|
||||
const { buyInSize } = payload;
|
||||
// find current player
|
||||
const player = roomInfo.players.find(
|
||||
(p: IPlayer) => p.userId === userInfo.userId);
|
||||
console.log(userInfo, 'userInfo------', player);
|
||||
@@ -431,10 +472,12 @@ class GameController extends BaseSocketController {
|
||||
status = EGameStatus.GAME_SHOWDOWN;
|
||||
}
|
||||
const commandRecord: ICommandRecord = {
|
||||
roomId: this.roomNumber,
|
||||
roomNumber: this.roomNumber,
|
||||
userId: userInfo.userId,
|
||||
type: currPlayer.type,
|
||||
gameStatus: status,
|
||||
pot: roomInfo.game?.pot || 0,
|
||||
commonCard: roomInfo.game?.commonCard.join(',') || '',
|
||||
command: payload.command,
|
||||
gameId: roomInfo.gameId || 0,
|
||||
counter: currPlayer.counter,
|
||||
|
||||
@@ -23,8 +23,9 @@ export default function join(): any {
|
||||
const app = ctx.app as any;
|
||||
const nsp = app.io.of('/socket');
|
||||
const query = socket.handshake.query;
|
||||
const { room, token } = query;
|
||||
const { room, token, roomConfig } = query;
|
||||
console.log('socket-----join', id);
|
||||
console.log('roomConfig-----roomConfig', JSON.parse(roomConfig));
|
||||
// room缓存信息是否存在
|
||||
if (!nsp.gameRooms) {
|
||||
nsp.gameRooms = [];
|
||||
@@ -48,6 +49,10 @@ export default function join(): any {
|
||||
players: [],
|
||||
game: null,
|
||||
sitLink: null,
|
||||
config: JSON.parse(roomConfig) || {
|
||||
isShort: false,
|
||||
smallBlind: 1,
|
||||
},
|
||||
},
|
||||
};
|
||||
if (!hasRoom) {
|
||||
@@ -58,6 +63,10 @@ export default function join(): any {
|
||||
players: [ player ],
|
||||
game: null,
|
||||
sitLink: null,
|
||||
config: JSON.parse(roomConfig) || {
|
||||
isShort: false,
|
||||
smallBlind: 1,
|
||||
},
|
||||
};
|
||||
updatePlayer(room, gameRoom.roomInfo.players, 'players', nsp);
|
||||
} else {
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
|
||||
export interface ICommandRecord {
|
||||
roomId: string;
|
||||
roomNumber: string;
|
||||
gameId: number;
|
||||
userId: string;
|
||||
type: string;
|
||||
pot: number;
|
||||
commonCard: string;
|
||||
gameStatus: number;
|
||||
command: string;
|
||||
counter: number;
|
||||
@@ -11,6 +13,6 @@ export interface ICommandRecord {
|
||||
|
||||
export interface ICommandRecordService {
|
||||
findById(gid: number): Promise<ICommandRecord>;
|
||||
|
||||
findByRoomNumber(roomNumber: number): Promise<ICommandRecord[]>;
|
||||
add(commandRecord: ICommandRecord): Promise<any>;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
export interface IGame {
|
||||
id?: number;
|
||||
roomId?: string;
|
||||
roomNumber?: string;
|
||||
pot: number;
|
||||
status: number;
|
||||
commonCard: string;
|
||||
@@ -10,6 +10,7 @@ export interface IGame {
|
||||
|
||||
export interface IGameService {
|
||||
findById(gid: number): Promise<IGame>;
|
||||
findByRoomNumber(roomNumber: number): Promise<IGame []>;
|
||||
add(game: IGame): Promise<any>;
|
||||
update(game: IGame): Promise<any>;
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
export interface IGameRecord {
|
||||
room_number: number;
|
||||
user_id: number;
|
||||
game_id: number;
|
||||
hand_cards: string;
|
||||
buy_in: number;
|
||||
}
|
||||
|
||||
export interface IGameRecordService {
|
||||
findById(gid: number): Promise<IGameRecord>;
|
||||
|
||||
add(gameRecord: IGameRecord): Promise<any>;
|
||||
}
|
||||
@@ -12,10 +12,17 @@ export interface ISit {
|
||||
position: number;
|
||||
}
|
||||
|
||||
export interface IRoomConfig {
|
||||
isShort: boolean;
|
||||
smallBlind: number;
|
||||
time?: number;
|
||||
}
|
||||
|
||||
export interface IRoomInfo {
|
||||
players: IPlayer[];
|
||||
sit: ISit[];
|
||||
game: PokerGame | null;
|
||||
sitLink: ILinkNode<IPlayer> | null;
|
||||
gameId?: number;
|
||||
config: IRoomConfig;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
export interface IPlayerDTO {
|
||||
roomNumber: number;
|
||||
userId: string;
|
||||
counter: number;
|
||||
gameId: number;
|
||||
handCard: string;
|
||||
buyIn: number;
|
||||
}
|
||||
|
||||
export interface IPlayerService {
|
||||
findByRoomNumber(roomNumber: number): Promise<IPlayerDTO []>;
|
||||
|
||||
add(gameRecord: IPlayerDTO): Promise<any>;
|
||||
}
|
||||
@@ -1,11 +1,15 @@
|
||||
export interface IRoom {
|
||||
roomNumber: string;
|
||||
roomNumber?: string;
|
||||
isShort: boolean;
|
||||
time?: number;
|
||||
smallBlind: number;
|
||||
}
|
||||
|
||||
export interface IRoomService {
|
||||
findById(uid: string): Promise<IRoom>;
|
||||
findRoomNumber(roomNumber: number): Promise<IRoom>;
|
||||
findByRoomNumber(roomNumber: number): Promise<boolean>;
|
||||
add(): Promise<any>;
|
||||
add(isShort: boolean, smallBlind: number, time?: number): Promise<any>;
|
||||
// join(roomNumber: string, userName: string): void;
|
||||
// leave(roomNumber: string, message: string): void;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export interface IUser {
|
||||
nick_name: string;
|
||||
nickName: string;
|
||||
account: string;
|
||||
password?: string;
|
||||
id?: string;
|
||||
|
||||
@@ -73,10 +73,10 @@ export class AccountService extends BaseService implements IAccountService {
|
||||
}
|
||||
|
||||
private async getToken(userAccount: string) {
|
||||
const { nick_name, account, id } = await this.user.findByAccount(userAccount);
|
||||
const { nickName, account, id } = await this.user.findByAccount(userAccount);
|
||||
const token = this.jwt.sign({
|
||||
user: {
|
||||
nickName: nick_name,
|
||||
nickName,
|
||||
account,
|
||||
userId: id,
|
||||
},
|
||||
|
||||
@@ -15,17 +15,30 @@ export class CommandRecord implements ICommandRecordService {
|
||||
|
||||
async add(commandRecord: ICommandRecord) {
|
||||
return await this.mysql.insert('command_record', {
|
||||
room_id: commandRecord.roomId,
|
||||
game_id: commandRecord.gameId,
|
||||
command: commandRecord.command,
|
||||
type: commandRecord.type,
|
||||
user_id: commandRecord.userId,
|
||||
counter: commandRecord.counter,
|
||||
game_status: commandRecord.gameStatus,
|
||||
...commandRecord,
|
||||
});
|
||||
}
|
||||
|
||||
async findById(gid: number): Promise<ICommandRecord> {
|
||||
return await this.mysql.get('game_record', { id: gid });
|
||||
}
|
||||
|
||||
async findByRoomNumber(roomNumber: number): Promise<ICommandRecord []> {
|
||||
const result = await this.mysql.query('SELECT\n' +
|
||||
'\tcounter,\n' +
|
||||
'\tcommand,\n' +
|
||||
'\tnickName,\n' +
|
||||
'\ttype,\n' +
|
||||
'\tgameStatus,\n' +
|
||||
'\tcommonCard,\n' +
|
||||
'\tpot,\n' +
|
||||
'\tgameId\n' +
|
||||
'FROM\n' +
|
||||
'\tcommand_record\n' +
|
||||
'INNER JOIN USER ON `user`.id = command_record.userId\n' +
|
||||
'WHERE\n' +
|
||||
'\tcommand_record.roomNumber = ?', roomNumber);
|
||||
console.log(result, '=============command');
|
||||
return JSON.parse(JSON.stringify(result));
|
||||
}
|
||||
}
|
||||
|
||||
+10
-10
@@ -13,11 +13,7 @@ export class GameService implements IGameService {
|
||||
async add(game: IGame) {
|
||||
console.log('this.mysql', this.mysql);
|
||||
const gameInfo = await this.mysql.insert('game', {
|
||||
room_id: game.roomId,
|
||||
status: game.status,
|
||||
common_card: game.commonCard,
|
||||
pot: game.pot,
|
||||
winners: game.winners,
|
||||
...game,
|
||||
});
|
||||
console.log(gameInfo);
|
||||
return { succeed: gameInfo.affectedRows === 1, id: gameInfo.insertId };
|
||||
@@ -25,11 +21,7 @@ export class GameService implements IGameService {
|
||||
|
||||
async update(game: IGame) {
|
||||
const gameInfo = await this.mysql.update('game', {
|
||||
id: game.id,
|
||||
status: game.status,
|
||||
common_card: game.commonCard,
|
||||
pot: game.pot,
|
||||
winners: game.winners,
|
||||
...game,
|
||||
});
|
||||
console.log(gameInfo);
|
||||
return { succeed: gameInfo.affectedRows === 1 };
|
||||
@@ -38,4 +30,12 @@ export class GameService implements IGameService {
|
||||
async findById(gid: number): Promise<IGame> {
|
||||
return await this.mysql.get('game', { id: gid });
|
||||
}
|
||||
|
||||
async findByRoomNumber(roomNumber: number): Promise<IGame []> {
|
||||
const result = await this.mysql.select('game', {
|
||||
where: { roomNumber },
|
||||
});
|
||||
console.log(result, 'game -======================');
|
||||
return JSON.parse(JSON.stringify(result));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
import { IGameRecord, IGameRecordService } from '../interface/IGameRecord';
|
||||
import { Context, inject, plugin, provide } from 'midway';
|
||||
|
||||
@provide('GameRecordService')
|
||||
export class GameRecordService implements IGameRecordService {
|
||||
|
||||
@inject()
|
||||
ctx: Context;
|
||||
|
||||
@plugin()
|
||||
mysql: any;
|
||||
|
||||
async add(gameRecord: IGameRecord) {
|
||||
return await this.mysql.insert('game_record', {
|
||||
...gameRecord,
|
||||
});
|
||||
}
|
||||
|
||||
async findById(gid: number): Promise<IGameRecord> {
|
||||
return await this.mysql.get('game_record', { id: gid });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { IPlayerDTO, IPlayerService } from '../interface/IPlayer';
|
||||
import { Context, inject, plugin, provide } from 'midway';
|
||||
|
||||
@provide('PlayerRecordService')
|
||||
export class PlayerService implements IPlayerService {
|
||||
|
||||
@inject()
|
||||
ctx: Context;
|
||||
|
||||
@plugin()
|
||||
mysql: any;
|
||||
|
||||
async add(gameRecord: IPlayerDTO) {
|
||||
return await this.mysql.insert('player', {
|
||||
...gameRecord,
|
||||
});
|
||||
}
|
||||
|
||||
async findByRoomNumber(roomNumber: number): Promise<IPlayerDTO []> {
|
||||
const result = await this.mysql.select('player', {
|
||||
where: { roomNumber },
|
||||
});
|
||||
console.log(result);
|
||||
return result ? JSON.parse(JSON.stringify(result)) : [];
|
||||
}
|
||||
}
|
||||
@@ -18,14 +18,28 @@ export class RoomService extends BaseService {
|
||||
return await this.mysql.get('room', { id: uid });
|
||||
}
|
||||
|
||||
async findRoomNumber(roomNumber: string): Promise<IRoom> {
|
||||
const result = await this.mysql.get('room', { roomNumber });
|
||||
return {
|
||||
isShort: !!result.isShort,
|
||||
smallBlind: result.smallBlind,
|
||||
time: result.time,
|
||||
};
|
||||
}
|
||||
|
||||
async findByRoomNumber(number: string): Promise<boolean> {
|
||||
const roomNumber = await this.redis.get(`room:${number}`);
|
||||
return !!roomNumber;
|
||||
}
|
||||
|
||||
async add(expires: number = 36000) {
|
||||
async add(isShort: boolean, smallBlind: number, expires: number = 36000) {
|
||||
const number = Math.floor(Math.random() * (1000000 - 100000)) + 100000;
|
||||
const result = await this.mysql.insert('room', { room_number: number });
|
||||
const result = await this.mysql.insert('room', {
|
||||
roomNumber: number,
|
||||
time: expires,
|
||||
isShort,
|
||||
smallBlind,
|
||||
});
|
||||
const roomRedis = await this.redis.set(`room:${number}`, `${number}`, 'ex', expires);
|
||||
if (result.affectedRows === 1 && roomRedis === 'OK') {
|
||||
return { roomNumber: number };
|
||||
|
||||
@@ -26,7 +26,7 @@ export class UserService implements IUserService {
|
||||
const user = await this.mysql.insert('user', {
|
||||
account: accountInfo.userAccount,
|
||||
password: accountInfo.password,
|
||||
nick_name: accountInfo.nickName,
|
||||
nickName: accountInfo.nickName,
|
||||
});
|
||||
return { succeed: user.affectedRows === 1 };
|
||||
}
|
||||
|
||||
@@ -212,6 +212,7 @@ describe('test/app/core/pokerGame.test.ts', () => {
|
||||
const game = new PokerGame({
|
||||
smallBlind: 1,
|
||||
users,
|
||||
isShort: false,
|
||||
actionRoundComplete: () => {
|
||||
if (game.status < 6) {
|
||||
game.startActionRound();
|
||||
|
||||
@@ -60,4 +60,10 @@ describe('test/app/core/pokerStyle.test.ts', () => {
|
||||
console.log('getPokerValueCard', pokerStyle.getPokerValueCard())
|
||||
assert.strictEqual(pokerStyle.getPokerWeight() , '000000000miged')
|
||||
});
|
||||
it('compare card', async () => {
|
||||
let pokerStyle: PokerStyle = new PokerStyle(['k2','g3','i2','h4','j3', 'm1', 'l1'], true)
|
||||
let pokerStyle2: PokerStyle = new PokerStyle(['k2','g3','i2','h4','j3','h1', 'h2'], true)
|
||||
console.log('getPokerValueCard', pokerStyle.getPokerValueCard())
|
||||
assert.strictEqual(pokerStyle.getPokerWeight() , pokerStyle2.getPokerWeight())
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user