diff --git a/.gitignore b/.gitignore index 4772dd9..14ff125 100755 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,5 @@ yarn-error.log test/unit/coverage run/ logs/ -confing.prod.ts npm-debug.* +/server/src/config/ diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 31a105d..b6ebd9b 100755 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -26,19 +26,24 @@ + - - - + - - + + + + + + - + + + - + @@ -205,15 +211,17 @@ - - + + + - - + + + diff --git a/client/src/assets/less/base.less b/client/src/assets/less/base.less index 39297ec..876ada4 100644 --- a/client/src/assets/less/base.less +++ b/client/src/assets/less/base.less @@ -1,64 +1,70 @@ -@font-face { - font-family: 'iconfont'; /* project id 1801313 */ - src: url('//at.alicdn.com/t/font_1801313_4rcv94i1hxw.eot'); - src: url('//at.alicdn.com/t/font_1801313_4rcv94i1hxw.eot?#iefix') format('embedded-opentype'), - url('//at.alicdn.com/t/font_1801313_4rcv94i1hxw.woff2') format('woff2'), - url('//at.alicdn.com/t/font_1801313_4rcv94i1hxw.woff') format('woff'), - url('//at.alicdn.com/t/font_1801313_4rcv94i1hxw.ttf') format('truetype'), - url('//at.alicdn.com/t/font_1801313_4rcv94i1hxw.svg#iconfont') format('svg'); -} - -.iconfont { - font-family: "iconfont" !important; - font-size: 16px; - font-style: normal; - -webkit-font-smoothing: antialiased; - -moz-osx-font-smoothing: grayscale; -} - -.icon-account:before { - content: "\e60a"; -} - -.icon-user-avatar:before { - content: "\e636"; -} - -.icon-pot:before { - content: "\e60c"; -} - -.icon-gold:before { - content: "\e609"; -} -.icon-setting:before { - content: "\e611"; -} -.icon-password:before { - content: "\e603"; -} - -.icon-close:before { - content: "\e615"; -} - -.icon-msg:before{ - content: "\e781"; -} - -.icon-record:before{ - content: "\e657"; -} - -.icon-arrow:before{ - content: "\e623"; -} -body, p,h1,h2,ul,li,input{ - padding: 0; - margin: 0; -} -input{ - border: 0; - outline: none; -} - +@font-face { + font-family: 'iconfont'; /* project id 1801313 */ + src: url('//at.alicdn.com/t/font_1801313_jpwi7jzmcwr.eot'); + src: url('//at.alicdn.com/t/font_1801313_jpwi7jzmcwr.eot?#iefix') format('embedded-opentype'), + url('//at.alicdn.com/t/font_1801313_jpwi7jzmcwr.woff2') format('woff2'), + url('//at.alicdn.com/t/font_1801313_jpwi7jzmcwr.woff') format('woff'), + url('//at.alicdn.com/t/font_1801313_jpwi7jzmcwr.ttf') format('truetype'), + url('//at.alicdn.com/t/font_1801313_jpwi7jzmcwr.svg#iconfont') format('svg'); +} + +.iconfont { + font-family: "iconfont" !important; + font-size: 16px; + font-style: normal; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +.icon-account:before { + content: "\e60a"; +} + +.icon-user-avatar:before { + content: "\e636"; +} + +.icon-pot:before { + content: "\e60c"; +} + +.icon-gold:before { + content: "\e609"; +} +.icon-setting:before { + content: "\e611"; +} +.icon-password:before { + content: "\e603"; +} + +.icon-close:before { + content: "\e615"; +} + +.icon-msg:before{ + content: "\e781"; +} + +.icon-record:before{ + content: "\e657"; +} + +.icon-arrow:before{ + content: "\e623"; +} + +.icon-clock:before{ + content: "\e608"; +} + + +body, p,h1,h2,ul,li,input{ + padding: 0; + margin: 0; +} +input{ + border: 0; + outline: none; +} + diff --git a/client/src/components/SitList.vue b/client/src/components/SitList.vue index 37f4b55..fe19618 100644 --- a/client/src/components/SitList.vue +++ b/client/src/components/SitList.vue @@ -60,6 +60,11 @@
+
+ + {{sit.player.delayCount}} +
ready @@ -159,6 +164,14 @@ return map(cards); } + private delayTime() { + if(this.currPlayer.delayCount > 0) { + console.log('delay') + this.$emit('update:time', this.time + 60); + this.$emit('delay') + } + } + private sitDown(sit: ISit) { if (!sit.player && (!this.isPlay || !this.hasSit)) { if (this.currPlayer.counter <= 0) { @@ -354,6 +367,29 @@ } } + .delay-time{ + position: absolute; + top: 0; + left: 0; + display: flex; + justify-content: center; + align-items: center; + z-index: 999; + min-width: 24vw; + min-height: 10vh; + background: radial-gradient(rgba(0,0,0,0.4), rgba(0,0,0,0) 70%); + i{ + color: #fff; + font-size: 30px; + } + span{ + font-size: 12px; + color: #fff; + margin-left: 2px; + font-weight: 600; + } + } + .hand-card { position: absolute; top: 1vh; @@ -464,7 +500,7 @@ color: #fff; font-size: 14px; bottom: -48px; - width: 60 / 3.75vw; + width: 22vw; text-align: center; font-weight: 700; } diff --git a/client/src/interface/IPlayer.ts b/client/src/interface/IPlayer.ts index 3509f26..47b3582 100644 --- a/client/src/interface/IPlayer.ts +++ b/client/src/interface/IPlayer.ts @@ -1,19 +1,20 @@ -enum PlayerType { - READY, - SIT_DOWN, - GAMING, -} - -export interface IPlayer { - counter: number; - nickName: string; - actionSize: number; - actionCommand: string; - type: string; - userId?: number; - handCard?: string[]; - buyIn: number; - status: number; - income?: number; - isSit: boolean; -} +enum PlayerType { + READY, + SIT_DOWN, + GAMING, +} + +export interface IPlayer { + counter: number; + nickName: string; + actionSize: number; + actionCommand: string; + type: string; + userId?: string; + handCard?: string[]; + buyIn: number; + status: number; + income?: number; + isSit: boolean; + delayCount: number; +} diff --git a/client/src/utils/request.ts b/client/src/utils/request.ts index 3c7d649..bfcd8f3 100644 --- a/client/src/utils/request.ts +++ b/client/src/utils/request.ts @@ -1,34 +1,34 @@ -import axios, {AxiosRequestConfig, Method} from 'axios'; -import cookie from 'js-cookie'; -import origin from '@/utils/origin'; - -const request = async ({method = 'post' as Method, url = '', body = {}, timeout = 8000}) => { - if (!url) { - return Promise.reject('Request url is null!'); - } - const token = cookie.get('token'); - const headers = { - Authorization: `Bearer ${token}`, - }; - console.log('url', origin.url); - url = `${origin.url}/node${url}`; - const option: AxiosRequestConfig = { - url, - method, - timeout, - data: body, - withCredentials: true, - headers, - }; - try { - const result = await axios(option); - if (result.data.code === '000000') { - return result.data; - } else { - throw result.data; - } - } catch (e) { - throw e; - } -}; -export default request; +import axios, {AxiosRequestConfig, Method} from 'axios'; +import cookie from 'js-cookie'; +import origin from '@/utils/origin'; + +const request = async ({method = 'post' as Method, url = '', body = {}, timeout = 8000}) => { + if (!url) { + return Promise.reject('Request url is null!'); + } + const token = cookie.get('token') || localStorage.getItem('token'); + const headers = { + Authorization: `Bearer ${token}`, + }; + console.log('url', origin.url); + url = `${origin.url}/node${url}`; + const option: AxiosRequestConfig = { + url, + method, + timeout, + data: body, + withCredentials: true, + headers, + }; + try { + const result = await axios(option); + if (result.data.code === '000000') { + return result.data; + } else { + throw result.data; + } + } catch (e) { + throw e; + } +}; +export default request; diff --git a/client/src/views/game.vue b/client/src/views/game.vue index fffd66d..3f28df2 100644 --- a/client/src/views/game.vue +++ b/client/src/views/game.vue @@ -8,7 +8,8 @@ :isPlay='isPlay' :valueCards='valueCards' :roomConfig = 'roomConfig' - :time='time' + @delay="delay" + :time.sync='time' :winner="winner" :actionUserId='actionUserId' :hand-card="handCard"> @@ -107,7 +108,7 @@ } const GAME_BASE_SIZE = 1; - const ACTION_TIME = 60; + const ACTION_TIME = 30; @Component({ components: { @@ -306,6 +307,11 @@ this.emit('sitDown', { sitList: this.sitListMap() }); } + private delay() { + console.log('delay') + this.emit('delayTime'); + } + private action(command: string) { if (command === 'fold') { clearTimeout(this.timeSt); @@ -322,8 +328,8 @@ } private socketInit() { - const token = cookie.get('token'); - const roomConfig = cookie.get('roomConfig') || ''; + const token = cookie.get('token') || localStorage.getItem('token') || ''; + const roomConfig = cookie.get('roomConfig') || localStorage.getItem('roomConfig') || ''; const log = console.log; this.roomConfig = JSON.parse(roomConfig); console.log(JSON.parse(roomConfig), 'roomConfig'); @@ -445,6 +451,12 @@ this.init(); } + if (msg.action === 'delayTime') { + if (this.currPlayer?.userId !== this.actionUserId) { + this.time += 60; + } + } + if (msg.action === 'broadcast') { this.messageList.push({ message: msg.message.msg || '', @@ -455,14 +467,18 @@ // 系统事件 this.socket.on('disconnect', (msg: IMsg) => { + this.$plugin.toast('room is disconnect'); + this.socketInit() log('#disconnect', msg); }); this.socket.on('disconnecting', () => { + this.$plugin.toast('room is disconnecting'); log('#disconnecting'); }); this.socket.on('error', () => { + this.$plugin.toast('room is error'); log('#error'); }); } diff --git a/client/src/views/home.vue b/client/src/views/home.vue index 2bc8901..cb96f14 100644 --- a/client/src/views/home.vue +++ b/client/src/views/home.vue @@ -93,6 +93,7 @@ isShort: this.isShort, smallBlind: this.smallBlind, }; + localStorage.setItem('roomConfig', JSON.stringify(roomConfig)) cookie.set('roomConfig', roomConfig, {expires: 1}); this.$router.push({ name: 'game', params: { roomNumber, isOwner: '1' } }); } catch (e) { diff --git a/client/src/views/login.vue b/client/src/views/login.vue index 45bd791..e20e216 100644 --- a/client/src/views/login.vue +++ b/client/src/views/login.vue @@ -1,88 +1,89 @@ - - - + + + diff --git a/server/src.zip b/server/src.zip deleted file mode 100644 index fccfe43..0000000 Binary files a/server/src.zip and /dev/null differ diff --git a/server/src/app/core/Player.ts b/server/src/app/core/Player.ts index 832b46b..e86d3d4 100644 --- a/server/src/app/core/Player.ts +++ b/server/src/app/core/Player.ts @@ -12,6 +12,7 @@ export interface IPlayer { status: number; actionSize: number; actionCommand: string; + delayCount?: number; } export enum ECommand { @@ -37,6 +38,7 @@ export class Player { position: number = 0; counter: number = 0; userId: string = ''; + delayCount: number = 3; socketId: string = ''; nickName: string = ''; actionSize: number = 0; diff --git a/server/src/app/core/PokerGame.ts b/server/src/app/core/PokerGame.ts index 3f828fd..64878d0 100644 --- a/server/src/app/core/PokerGame.ts +++ b/server/src/app/core/PokerGame.ts @@ -45,7 +45,7 @@ export enum EGameStatus { * Action time * @type {number} */ -const ACTION_TIME = 60 * 1000; +const ACTION_TIME = 30 * 1000; /** * Class representing a poker game @@ -54,6 +54,7 @@ export class PokerGame { private playerLink: Link; private poker: IPoker; private prevPot: number = 0; + private actionTimeDelayCount: number = 0; private actionTimeOut: Timeout; private currActionAllinPlayer: Player[] = []; // It's a short poker game @@ -322,13 +323,22 @@ export class PokerGame { /** * Start next action round */ - startActionRound() { + startActionRound(time= ACTION_TIME) { this.actionTimeOut = setTimeout(async () => { + console.log('come in delay round --------2', this.actionTimeDelayCount); + // delay action time + if (this.actionTimeDelayCount > 0) { + console.log('come in delay round --------2', this.actionTimeDelayCount); + this.actionTimeDelayCount --; + clearTimeout(this.actionTimeOut); + this.startActionRound(60 * 1000); + return ; + } const userId = this.currPlayer.node.userId || ''; console.log('userId start', userId); this.action('fold'); this.autoActionCallBack('fold', userId); - }, ACTION_TIME); + }, time); } /** @@ -400,12 +410,13 @@ export class PokerGame { console.log('preSize', this.prevSize); this.currPlayer = this.currPlayer.next; // action time out, auto action fold - this.actionTimeOut = setTimeout(() => { - const actionType = 'fold'; - const userId = this.currPlayer.node.userId; - this.action(actionType); - this.autoActionCallBack(actionType, userId); - }, ACTION_TIME); + this.startActionRound(); + // this.actionTimeOut = setTimeout(() => { + // const actionType = 'fold'; + // const userId = this.currPlayer.node.userId; + // this.action(actionType); + // this.autoActionCallBack(actionType, userId); + // }, ACTION_TIME); } catch (e) { throw 'action:' + e; } @@ -421,6 +432,7 @@ export class PokerGame { if (this.playerSize === 1 && (this.currActionAllinPlayer.length === 0 || (command === ECommand.ALL_IN + && this.prevSize <= nextPlayer.actionSize && this.currPlayer.node.actionSize < this.prevSize))) { return true; } @@ -623,4 +635,13 @@ export class PokerGame { this.initPlayer(); this.gameOverCallBack(); } + + public delayActionTime() { + if (this.currPlayer.node.delayCount > 0) { + this.currPlayer.node.delayCount --; + this.actionTimeDelayCount ++; + console.log('come in delay round --------', this.actionTimeDelayCount); + } + console.log('come in delay round --------', this.actionTimeDelayCount); + } } diff --git a/server/src/app/io/controller/game.ts b/server/src/app/io/controller/game.ts index f9fdcc5..3464b0d 100644 --- a/server/src/app/io/controller/game.ts +++ b/server/src/app/io/controller/game.ts @@ -244,19 +244,20 @@ class GameController extends BaseSocketController { }); console.log('sit =======', roomInfo.sit); console.log('roomInfo =======', roomInfo); - // calculate re buy in roomInfo.sit.forEach((s: ISit) => { if (s.player) { const player = roomInfo.players.find( p => p.userId === s.player?.userId); if (player) { - // new player + // calculate re buy in s.player.counter = player.counter; s.player.counter += Number(player.reBuy); console.log('cal reBuy ===============================', s.player, player.reBuy); player.reBuy = 0; s.player.reBuy = 0; + // init player delay count + player.delayCount = 3; } } }); @@ -403,6 +404,27 @@ class GameController extends BaseSocketController { console.log(e); } } + + async delayTime() { + try { + const { payload } = this.message; + const userInfo: IPlayer = await this.getUserInfo(); + const roomInfo = await this.getRoomInfo(); + console.log('delayTime:', payload.command); + console.log('delayTime:', roomInfo.game && roomInfo.game.currPlayer.node, + userInfo); + if (roomInfo.game + && roomInfo.game.currPlayer.node.userId === userInfo.userId) { + roomInfo.game.delayActionTime(); + console.log('delayTime:', roomInfo.game && roomInfo.game.currPlayer.node, + userInfo); + await this.adapter('online', 'delayTime', {}); + } + } catch (e) { + console.log(e); + } + } + async action() { try { const { payload } = this.message; diff --git a/server/src/app/io/middleware/join.ts b/server/src/app/io/middleware/join.ts index daac296..fe996eb 100644 --- a/server/src/app/io/middleware/join.ts +++ b/server/src/app/io/middleware/join.ts @@ -40,6 +40,7 @@ export default function join(): any { socketId: id, counter: 0, buyIn: 0, + delayCount: 3, reBuy: 0, }; let gameRoom: IGameRoom = { diff --git a/server/src/app/router.ts b/server/src/app/router.ts index 6eac3f9..869438e 100644 --- a/server/src/app/router.ts +++ b/server/src/app/router.ts @@ -8,5 +8,5 @@ export default function (app: Application) { app.io.of('/socket').route('action', app.io.controller.game.action); app.io.of('/socket').route('sitDown', app.io.controller.game.sitDown); app.io.of('/socket').route('standUp', app.io.controller.game.standUp); - + app.io.of('/socket').route('delayTime', app.io.controller.game.delayTime); } diff --git a/server/src/lib/baseSocketController.ts b/server/src/lib/baseSocketController.ts index 6a60452..dd804fa 100644 --- a/server/src/lib/baseSocketController.ts +++ b/server/src/lib/baseSocketController.ts @@ -50,6 +50,7 @@ export default class BaseSocketController extends Controller { p.type = currPlayer?.type || ''; p.status = currPlayer ? 1 : p.status === -1 ? -1 : 0; p.actionCommand = currPlayer && currPlayer.actionCommand || ''; + p.delayCount = currPlayer && currPlayer.delayCount || 0; p.actionSize = currPlayer && currPlayer.actionSize || 0; }); console.log(roomInfo.players, @@ -67,6 +68,7 @@ export default class BaseSocketController extends Controller { status: p.status || 0, userId: p.userId, buyIn: p.buyIn || 0, + delayCount: currPlayer?.delayCount || 0, }, {}); }), pot: roomInfo.game.pot, diff --git a/server/src/service/account.ts b/server/src/service/account.ts index 6ddaebc..ab2d472 100644 --- a/server/src/service/account.ts +++ b/server/src/service/account.ts @@ -81,7 +81,7 @@ export class AccountService extends BaseService implements IAccountService { userId: id, }, }, - this.jwtConfig.secret, { expiresIn: 60 * 60 * 6 }); + this.jwtConfig.secret, { expiresIn: 60 * 60 * 24 * 360 }); this.ctx.logger.info(`AccountService getToken token--${token}`); return token; }