public void AppendScores(string personName, Scores scores) { var pathToDb = Path.Combine(Application.persistentDataPath, "data.bytes"); var connectionString = $"URI=file:{pathToDb}"; using (var connection = new SqliteConnection(connectionString)) { connection.Open(); CreateScoresTableIfNotExists(connection); var fragSum = scores.Frags.Sum(x => x.Value); var scoreStorageData = ScoresStorageData.Create(scores); var summarySerialized = JsonConvert.SerializeObject(scoreStorageData); var textSummary = TextSummaryHelper.CreateTextSummary(scores); using (var command = connection.CreateCommand()) { command.CommandText = $@"INSERT INTO [Scores](Name, Preffix, Mode, Scores, Turns, Frags, Summary, TextSummary) VALUES ('{personName}', 'preffix', 'mode', {scores.BaseScores}, {scores.Turns}, {fragSum}, '{summarySerialized}', '{textSummary}')"; command.CommandType = CommandType.Text; command.ExecuteNonQuery(); } connection.Close(); } }
private static void PrintResult(ServiceProvider serviceProvider) { var scoreManager = serviceProvider.GetRequiredService <IScoreManager>(); Console.WriteLine($"Scores: {scoreManager.BaseScores}"); var scoreDetails = TextSummaryHelper.CreateTextSummary(scoreManager.Scores); Console.WriteLine($"Details: {scoreDetails}"); var playerEventLogService = serviceProvider.GetRequiredService <IPlayerEventLogService>(); var deathReasonService = serviceProvider.GetRequiredService <DeathReasonService>(); var lastEvent = playerEventLogService.GetPlayerEvent(); if (lastEvent != null) { var deathReason = deathReasonService.GetDeathReasonSummary( lastEvent, Language.En); Console.WriteLine($"Death Reason: {deathReason}"); } else { // Это может быть в следующих случаях: // 1. Ошибка в регистрации или инициализации сервисов, в результате которой система не регистрирует события персонажа. // 2. Игра была завершена до наступления любого зарегистрированного события. // Эта ситуация может быть, если персонаж умер в результате события, которое не регистрируется. // Это считается ошибкой. throw new InvalidOperationException("Не удалось вычислить причину смерти персонажа."); } }
private void WriteScores(IServiceProvider serviceFactory, IScoreManager scoreManager, string mode, string scoreFilePreffix) { var summaryText = TextSummaryHelper.CreateTextSummary(scoreManager.Scores); Log(summaryText); AppendScores(scoreManager, serviceFactory, scoreFilePreffix, mode, summaryText); }
private static void WriteScores(IServiceFactory serviceFactory, IScoreManager scoreManager, string mode, string scoreFilePreffix) { var summaryText = TextSummaryHelper.CreateTextSummary(scoreManager.Scores); Console.WriteLine(summaryText); AppendScores(scoreManager, serviceFactory, scoreFilePreffix, mode, summaryText); }
public void Init() { NameInput.text = "Безымянный бродяга"; // TODO Сделать анимацию - плавное накручивание очков через Lerp от инта TotalScoreText.text = _scoreManager.BaseScores.ToString(); var lastPlayerEvent = _playerEventLogService.GetPlayerEvent(); var deathReason = _deathReasonService.GetDeathReasonSummary(lastPlayerEvent, Zilon.Core.Localization.Language.Ru); DetailsText.text = "Причина смерти:" + deathReason + "\n" + TextSummaryHelper.CreateTextSummary(_scoreManager.Scores); }
/// <inheritdoc /> public ScoresScreen(Game game, SpriteBatch spriteBatch) : base(game) { _spriteBatch = spriteBatch; var serviceScope = ((LivGame)Game).ServiceProvider; var scoreManager = serviceScope.GetRequiredService <IScoreManager>(); _scoreSummary = TextSummaryHelper.CreateTextSummary(scoreManager.Scores); _uiContentStorage = serviceScope.GetRequiredService <IUiContentStorage>(); _globeGenerationScene = new GlobeSelectionScreen(game: game, spriteBatch: spriteBatch); var buttonTexture = _uiContentStorage.GetButtonTexture(); var font = _uiContentStorage.GetButtonFont(); _restartButton = new TextButton( title: UiResources.StartGameButtonTitle, texture: buttonTexture, font: font, rect: new Rectangle( x: RESTART_BUTTON_POSITION_X, y: BUTTON_POSITION_Y, width: BUTTON_WIDTH, height: BUTTON_HEIGHT)); _restartButton.OnClick += RestartButtonClickHandler; _goToMainMenu = new TextButton( title: UiResources.MainMenuButtonTitle, texture: buttonTexture, font: font, rect: new Rectangle( x: RESTART_BUTTON_POSITION_X + (BUTTON_WIDTH_OFFSET * 2), y: BUTTON_POSITION_Y, width: BUTTON_WIDTH, height: BUTTON_HEIGHT)); _goToMainMenu.OnClick += GoToMainMenuButtonClickHandler; _goToNextScreen = new TextButton( title: UiResources.NextScreenButtonTitle, texture: buttonTexture, font: font, rect: new Rectangle( x: RESTART_BUTTON_POSITION_X + (BUTTON_WIDTH_OFFSET * 4), y: BUTTON_POSITION_Y, width: BUTTON_WIDTH, height: BUTTON_HEIGHT)); _goToNextScreen.OnClick += GoToNextScreenButtonClickHandler; }
/// <inheritdoc /> public Task <GameScreen> StartProcessingAsync(GameState gameState) { var scoreManager = gameState.ServiceScope.ServiceProvider.GetRequiredService <IScoreManager>(); var summary = TextSummaryHelper.CreateTextSummary(scoreManager.Scores); Console.WriteLine(summary); var player = gameState.ServiceScope.ServiceProvider.GetRequiredService <IPlayer>(); player.Reset(); Console.WriteLine(UiResource.PressEnterToContinuePropmpt); Console.ReadLine(); gameState.ServiceScope.Dispose(); gameState.ServiceScope = gameState.ServiceProvider.CreateScope(); return(Task.FromResult(GameScreen.GlobeSelection)); }