This commit is contained in:
yuexin 2021-03-05 13:24:38 +08:00
commit 2f4e95df53
3 changed files with 35 additions and 6 deletions

View File

@ -1,6 +1,7 @@
import { singleton } from '../decorators/singleton.decorator'
import { GameEnv } from './GameEnv'
import { CardGameState } from '../rooms/schema/CardGameState'
import { checkBitIdx, checkBitNumber } from '../utils/number.util'
/**
*
@ -66,11 +67,18 @@ export class RoomOptions {
return 0
}
public initGameRule(state: CardGameState) {
state.rules.set(RULE_CANEAT, this.canEat({advMode: state.advMode}))
state.rules.set(RULE_MULTIPLEEAT, this.multipleEat())
state.rules.set(RULE_DROPCARD, this.autoDiscard())
state.rules.set(RULE_SINGLEEAT, this.singleEat())
public initGameRule(state: CardGameState, val: number) {
if (val) {
state.rules.set(RULE_CANEAT, checkBitNumber(val, 1))
state.rules.set(RULE_MULTIPLEEAT, checkBitNumber(val, 2))
state.rules.set(RULE_DROPCARD, checkBitNumber(val, 3))
state.rules.set(RULE_SINGLEEAT, checkBitNumber(val, 4))
} else {
state.rules.set(RULE_CANEAT, this.canEat({advMode: state.advMode}))
state.rules.set(RULE_MULTIPLEEAT, this.multipleEat())
state.rules.set(RULE_DROPCARD, this.autoDiscard())
state.rules.set(RULE_SINGLEEAT, this.singleEat())
}
}
}

View File

@ -61,7 +61,11 @@ export class GeneralRoom extends Room {
if (options.score) {
this.score = options.score
}
new RoomOptions().initGameRule(this.state)
let val = 0
if (options.debug_cv) {
val = +options.debug_cv
}
new RoomOptions().initGameRule(this.state, val)
this.battleMan.init(cs, this)
this.clock.start()
this.state.gameState = GameStateConst.STATE_WAIT_JOIN

View File

@ -8,3 +8,20 @@ export function getRandom(max: number, min: number): number {
min = min || 0;
return Math.floor(Math.random()*(max-min)+min);
}
export function setBitVal(value: number, index: number, yes: boolean) {
if (yes) {
value |= (1<<index)
} else {
value &= ~(1<<index)
}
return value
}
export function checkBitIdx(value: number, index: number): boolean {
return ((value >> (index)) & 1 ) == 1
}
export function checkBitNumber(value: number, index: number): number {
return (((value >> (index)) & 1 ) == 1) ? 1 : 0
}