private IList <int> GetValidActionIdList(string playerId) { if (GameStage == null) { return(new List <int>()); } return(GameStage.GetValidActionIdList(playerId)); }
private CardPile GetPlayerHand(GameStage gameStage, string playerId) { var playerHandDictionary = GameStage?.CurrentGameRound?.PlayerHandDictionary; var hand = playerHandDictionary != null && playerHandDictionary.ContainsKey(playerId) ? playerHandDictionary[playerId] : null; return(hand); }
public bool ProcessAction(ActionBase action) { if (GameStage == null) { return(false); } if (!CheckAndSetBusy()) { return(false); } try { var validPlayerActions = GetValidActionIdList(action.PlayerInfo.PlayerId); if (!validPlayerActions.Contains(action.GetActionId())) { return(false); } } catch (Exception e) { Log.Error($"Exception in GetValidActionIdList of ProcessAction: {e.Message}", e); throw; } RunBusyAction(() => { try { GameStage.ProcessAction(action); } catch (Exception e) { Log.Error($"Exception in ProcessAction: {e}", e); throw; } try { UpdatePlayers(); } catch (Exception e) { Log.Error($"Exception in UpdatePlayers: {e.Message}", e); throw; } }); return(true); }
public bool StartGame() { if (GameStage != null) { return(false); } if (PlayerGroupInfo.GetPlayerList().Count != 4) { return(false); } if (!CheckAndSetBusy()) { return(false); } RunBusyAction(() => { try { GameStage = new GameStage(GameInfo.Rules, PlayerGroupInfo, ConfirmAction); } catch (Exception e) { Log.Error($"Exception in StartGame: {e.Message}", e); throw; } try { UpdatePlayers(); } catch (Exception e) { Log.Error($"Exception in UpdatePlayers: {e.Message}", e); throw; } }); return(true); }