0

所以我意识到我一直在写上帝的对象,我正在尝试重构一些对象,但我正在努力弄清楚我应该如何分离所有东西。这里只是看一下 Table 对象中的属性和一些函数存根

    id = "1"
    settings = {} as TableSettings;
    players: ServerPlayer[] = Array(7);
    game = new Holdem(this);
    round: Round = new WaitRound(this);
    running = false;

    dealer: number = 0;
    firstToBet: number = 0;

    logString: string = "";;
    post?: Function;
    firstUp = true;
    
    disconnected = new Map();
    
    tableCards: Card[] = [];

    muck: Card[] = [];
    deck: Card[] = [];
    
    pot = 0;
    bet = 0;

    getPlayer(id)
    shuffle(Card[])
    newDeck()
    dealTableCards()
    newHand()
    sitPlayer()
    setDealer(position)
    startNextRound()
    setRound(newRound)
    playerCount()
    countPlayersIn()
    gameStart()
    updateClients()
    giveMoney(player)
    placeBet(player, amount)
    awardMoney(player, amount)
    playerLeave(player)
    popCardFromDeck()
    dealCard(player, up)

这显然是一团糟,但我正在努力将其分解。我能看到的最明显的事情是将甲板/洗牌/弹出放入甲板对象。我应该将玩家与 satPlayer/playerLeave/playerCount/countPlayersIn 一起放入 PlayerServer 或 PlayerManager 吗?如果是这样,我是否也应该移动 giveMoney 和 AwardMoney?

我一直在谷歌搜索,在所有示例代码中,我发现它是如此的小而清晰,你应该在哪里对行为进行分组,但在一个大型复杂的类上,我只能挑出几件事来分开

4

0 回答 0