public Task Handle(PlayerStartingEvent notification, CancellationToken cancellationToken) { try { var playerStats = _gameStats.CurrentPlayerStats; foreach (IGhost ghost in _ghostCollection.Ghosts) { ghost.Reset(); } _fruit.HandlePlayerStarted(playerStats, false); _maze.HandlePlayerStarted(playerStats, _mazeCanvases.GetForPlayer(playerStats.PlayerIndex)); _pacman.HandlePlayerStarting(playerStats, false); var act = _acts.GetActNamed("PlayerIntroAct"); act.Reset(); _game.SetAct(act); return(Task.CompletedTask); } catch (Exception e) { Console.WriteLine(e); throw; } }
public async Task Handle(NewGameEvent notification, CancellationToken cancellationToken) { await _mazeCanvases.GetForPlayer(0).Reset(); await _mazeCanvases.GetForPlayer(1).Reset(); _coinBox.UseCredits(notification.AmountOfPlayers); await _gameStats.Reset(notification.AmountOfPlayers); _gameStats.ChoseNextPlayer(); var playerStartingEvent = new PlayerStartingEvent(); await _mediator.Publish(playerStartingEvent, cancellationToken); }
public async Task Handle(DemoStartedEvent notification, CancellationToken cancellationToken) { _gameStats.ResetForDemo(); await _gameSoundPlayer.Disable(); var canvasWrapper = _mazeCanvases.GetForPlayer(0); await canvasWrapper.Reset(); var playerStartedEvent = new DemoPlayerStartingEvent(); await _mediator.Publish(playerStartedEvent, cancellationToken); }
public async Task Handle(DemoPlayerStartingEvent notification, CancellationToken cancellationToken) { var playerStats = _gameStats.CurrentPlayerStats; await _gameSoundPlayer.Disable(); _ghostCollection.Ghosts.ForEach(g => g.Reset()); _fruit.HandlePlayerStarted(playerStats, true); await _maze.HandlePlayerStarted(playerStats, _mazeCanvases.GetForPlayer(_gameStats.CurrentPlayerStats.PlayerIndex)); await _pacman.HandlePlayerStarting(playerStats, true); var act = _acts.GetActNamed("DemoPlayerIntroAct"); await act.Reset(); _game.SetAct(act); }
public async Task Handle(LevelFinishedEvent notification, CancellationToken cancellationToken) { try { var playerStats = _gameStats.CurrentPlayerStats; var maze = _mazeCanvases.GetForPlayer(playerStats.PlayerIndex); await maze.Reset(); _gameStats.LevelFinished(); var cutScene = playerStats.LevelStats.GetLevelProps().CutScene; if (cutScene == IntroCutScene.None) { await _mediator.Publish(new PlayerStartingEvent(), cancellationToken); return; } var act = cutScene switch { IntroCutScene.BigPac => await getAct("BigPacChaseAct"), IntroCutScene.GhostSnagged => await getAct("GhostTearAct"), IntroCutScene.TornGhostAndWorm => await getAct("TornGhostChaseAct"), // ReSharper disable once HeapView.BoxingAllocation _ => throw new InvalidOperationException($"Don't know how to handle cut scene of {cutScene}") }; await act.Reset(); _game.SetAct(act); } catch (Exception e) { Console.WriteLine(e); throw; } }