public bool PerformRoll() { if (ConsecutiveRolls > 0) { if (!HasScoringDiceGuard(GameAction.Roll)) { return(false); } Board.UpdateScoreFromSelected(); } Board.RollDice(); if (!Board.HasScoringDiceSelected()) { GameError?.Invoke(this, new NoScoringDiceSelected(GameAction.Roll)); // Rolled no scoring dice NextPlayer(); return(false); } ConsecutiveRolls += 1; return(true); }
private void HandleMessage(DateTimeOffset t, HttpMessage m) { try { var status = Convert <SvData>(m.Response); if (status.api_result != 1) { GameError?.Invoke(t, new Events.GameError(status.api_result, status.api_result_msg)); return; } lock (lockObj) switch (m.Key) { case "api_start2": case "api_start2/getData": if (savedMasterData != null) { savedMasterData.Value = m.Response.ToString(); } masterDataUpdated?.InvokeEach(t, ParseMasterData(Response <MasterDataJson>(m)), HandlerError); break; case "api_get_member/require_info": var requireInfo = Response <GameStartupInfoJson>(m); AllEquipmentUpdated?.InvokeEach(t, requireInfo.api_slot_item, HandlerError); UseItemUpdated?.InvokeEach(t, requireInfo.api_useitem, HandlerError); FreeEquipmentUpdated?.InvokeEach(t, requireInfo.api_unsetslot, HandlerError); BuildingDockUpdated?.InvokeEach(t, requireInfo.api_kdock, HandlerError); break; case "api_req_member/get_incentive": IncentiveRewarded?.InvokeEach(t, Response <IncentiveJson>(m).api_item, HandlerError); break; case "api_port/port": var homeport = Response <HomeportJson>(m); AdmiralUpdated?.InvokeEach(t, homeport.api_basic, HandlerError); RepairingDockUpdated?.InvokeEach(t, homeport.api_ndock, HandlerError); HomeportReturned?.InvokeEach(t, ParseHomeport(homeport), HandlerError); FleetsUpdated?.InvokeEach(t, homeport.api_deck_port, HandlerError); MaterialsUpdated?.InvokeEach(t, homeport.api_material, HandlerError); if (homeport.api_event_object?.api_m_flag2 == true) { EnemyDebuffConfirmed?.InvokeEach(t, default, HandlerError); } break; case "api_get_member/slot_item": AllEquipmentUpdated?.InvokeEach(t, Response <RawEquipment[]>(m), HandlerError); break;
private bool HasScoringDiceGuard(GameAction action) { if (!Board.GetDice().Any(x => x.Selected)) { // No selected dice GameError?.Invoke(this, new NoDiceSelected(action)); return(false); } if (!Board.HasScoringDiceSelected()) { // No selected dice with scores GameError?.Invoke(this, new NoScoringDiceSelected(action)); return(false); } return(true); }
public void Start() { CurrentCard = Board.Deck.Draw(); while (true) { // pass control to player bool passAllowed = AllowPass(); TurnFulfilled = false; Turn?.Invoke(CurrentPlayer); while (true) { CurrentPlayer.Play(this); // make sure the turn was completed if (!TurnFulfilled && !passAllowed && CurrentCard != 7) { GameError?.Invoke(CurrentPlayer, new IncompleteTurnException("Player returned without completing turn")); } else { break; } } if (TurnFulfilled && PlayerWon()) { GameOver?.Invoke(CurrentPlayer); break; } else if (TurnFulfilled || passAllowed) { // end turn if (CurrentCard != 2) { NextPlayer(); } // draw card CurrentCard = Board.Deck.Draw(); } } }
public void PerformSelect(IEnumerable <int> selection) { if (ConsecutiveRolls == 0) { GameError?.Invoke(this, new DiceNotRolled(GameAction.Select)); return; } var dice = Board.GetDice(); foreach (var select in selection) { if (dice[select].Selected) { Board.DeselectDice(select); } else { Board.SelectDice(select); } } }
public bool PerformStop() { if (ConsecutiveRolls == 0) { // Haven't rolled GameError?.Invoke(this, new DiceNotRolled(GameAction.Stop)); return(false); } if (!HasScoringDiceGuard(GameAction.Stop)) { return(false); } Board.UpdateScoreFromSelected(); var player = GetCurrentPlayer(); player.IncreaseScore(Board.GetScore()); NextPlayer(); return(true); }
private void Game_GameError(object sender, IGameError e) { GameError?.Invoke(this, e); }