private bool CanBet(BlackjackPlayer player, BlackjackBet bet) { if (bet.initialBet >= minimumBet && bet.initialBet <= maximumBet) { return(player.money >= bet.totalBet); } return(false); }
private bool AddBet(BlackjackPlayer player, int betAdd) { if (CanAddBet(player, betAdd)) { BlackjackBet bet = playerBetsDic[player]; bet.totalBet += betAdd; playerBetsDic[player] = bet; return(true); } return(false); }
public void BroadcastBetDone(BlackjackPlayer player) { BlackjackBet bet = playerBetsDic[player]; BetDoneEvent betDone = new BetDoneEvent(); betDone.Actor = player.key.ID; betDone.BetMoney = bet.totalBet; var eventData = new EventData(EventCode.BlackjackBetDone, betDone); BroadcastMessage(player.peer, eventData, new SendParameters()); var response = new OperationResponse(CommonOperationCode.BlackjackBet, new Dictionary <byte, object> { { (byte)CommonParameterKey.Success, true } }); player.peer.SendOperationResponse(response, new SendParameters()); }
public void OnPlayerAction(GamePeer peer, ActionRequest action) { if (peer.ValidateOperation(action, new SendParameters()) == false) { return; } BlackjackPlayer player = playerManager.GetPlayer(peer) as BlackjackPlayer; if (player.status != PlayerStatus.Playing) { return; } if (playerCards[player][action.DeckIndex].Finished) { return; } BlackjackBet bet = playerBetsDic[player]; ActionEvent actionEvent = new ActionEvent(); actionEvent.Actor = player.key.ID; actionEvent.ActionType = action.ActionType; actionEvent.DeckIndex = action.DeckIndex; switch (action.ActionType) { case BlackjackActionType.Hit: PlayerHit(player, action.DeckIndex); FillActionEventDeck(ref actionEvent, player, action.DeckIndex); break; case BlackjackActionType.Split: if (AddBet(player, bet.initialBet) == false) { return; } Card originalDeckCard; Card newDeckCard; Split(player, action.DeckIndex, out originalDeckCard, out newDeckCard); FillActionEventDeck(ref actionEvent, player, action.DeckIndex, playerCards[player].Count - 1); break; case BlackjackActionType.Stand: Finish(player, action.DeckIndex); FillActionEventDeck(ref actionEvent, player, action.DeckIndex); break; case BlackjackActionType.DoubleDown: if (AddBet(player, bet.initialBet) == false) { return; } DoubleDown(player, action.DeckIndex); PlayerHit(player, action.DeckIndex); FillActionEventDeck(ref actionEvent, player, action.DeckIndex); break; } EventData eventData = new EventData(EventCode.BlackjackAction, actionEvent); BroadcastMessage(peer, eventData, new SendParameters()); var response = new OperationResponse(CommonOperationCode.BlackjackAction, actionEvent); peer.SendOperationResponse(response, new SendParameters()); PlayerActionDone(player, action.DeckIndex); }