public GameMaster(GameMasterConfiguration configuration) { Logger.Get().Info("[GM] Creating GameMaster"); Configuration = configuration; ConnectionLogic = new ConnectionLogicComponent(this); GameLogic = new GameLogicComponent(this); ScoreComponent = new ScoreComponent(this); BoardLogic = new BoardLogicComponent(this); PresentationComponent = new PresentationComponent(this); }
public void SetConfiguration(GameMasterConfiguration configuration) { if (state == GameMasterState.Configuration) { Configuration = configuration; ScoreComponent.LoadNewConfiguration(); BoardLogic.LoadNewConfiguration(); } else { Logger.Get().Error("[GM] Cannot Set Configuration, because GM is not in configuration state."); } }
//called from window system each frame, updates all components public void Update(double dt) { if (state != GameMasterState.Configuration && NetworkComponent?.Exception != null) { SetCriticalException(NetworkComponent.Exception); } if (state == GameMasterState.Configuration || state == GameMasterState.Summary || state == GameMasterState.CriticalError) { return; } foreach (var agent in Agents) { agent.Update(dt); } var messages = GetIncomingMessages(); if (messages.Count > 0) { Logger.Get().Debug("[GM] Processing {n} message(s)", messages.Count); NLog.NestedDiagnosticsContext.Push(" "); foreach (var message in messages) { var response = currentMessageProcessor.ProcessMessage(message); response.SetCorrelationId(message.CorrelationId); SendMessage(response); } NLog.NestedDiagnosticsContext.Pop(); } var result = ScoreComponent.GetGameResult(); if (result != Enums.GameResult.None) { state = GameMasterState.Summary; Logger.Get().Info("[GM] Ending game"); var resultMessages = GameLogic.GetEndGameMessages(result == Enums.GameResult.BlueWin ? TeamId.Blue : TeamId.Red); foreach (var m in resultMessages) { SendMessage(m); } } }
public PresentationScore(ScoreComponent score) { RedTeamScore = score.GetScore(TeamId.Red); BlueTeamScore = score.GetScore(TeamId.Blue); GameResult = score.GetGameResult(); }