add pokerGame test

This commit is contained in:
wzdwc
2020-04-06 23:51:56 +08:00
parent e5ea0f6b28
commit 1af06f02a1
3 changed files with 73 additions and 6 deletions
+12
View File
@@ -0,0 +1,12 @@
sudo: false
language: node_js
node_js:
- '10'
before_install:
- npm i npminstall -g
install:
- npminstall
script:
- npm run ci
after_script:
- npminstall codecov && codecov
+30 -3
View File
@@ -1,5 +1,6 @@
import { Application } from 'midway';
export interface IPoker {
init(): void;
init(redis: any): void;
getCard(): string;
@@ -12,8 +13,23 @@ export interface IPoker {
export class Poker implements IPoker {
pokers: string[] = [];
constructor() {
this.init();
redis: any = '';
roomId = '';
gameId = '';
constructor(app: Application, roomId: string, gameId: string) {
this.roomId = roomId;
this.gameId = gameId;
this.redis = app.redis;
const hasPoker = this.hasPokers();
if (hasPoker) {
this.pokers = hasPoker;
} else {
this.init();
}
}
init() {
@@ -37,6 +53,16 @@ export class Poker implements IPoker {
this.pokers.push(`${i}:${j}`);
}
}
// start game ,init pokers
this.setPokers();
}
hasPokers() {
return this.redis.get(`${this.roomId}:${this.gameId}`);
}
setPokers() {
this.redis.set(`${this.roomId}:${this.gameId}`, this.pokers.join(''));
}
getCard(): string {
@@ -44,6 +70,7 @@ export class Poker implements IPoker {
const currCardIndex = this.getRandom(this.pokers.length);
const currCard = this.pokers[currCardIndex];
this.pokers.splice(currCardIndex, 1);
this.setPokers();
return currCard;
}
+31 -3
View File
@@ -1,9 +1,37 @@
import { PokerGame } from '../../../src/app/core/PokerGame';
const assert = require('assert');
import { expect } from 'chai';
describe('test/app/core/pokerGame.test.ts', () => {
it('', async () => {
/**
* game ready
*/
it('game init', async () => {
});
/**
* game playing
*/
it('game init', async () => {
});
// flop
// turn
// river
// chip in
// has Allin need separate pot
/**
* game over
*/
it('game over', async () => {
});
/**
* count
*/
it('count', async () => {
});
// has other pot
});