private void OnRoundEnded(object?sender, GameIdEventArgs e)
 {
     if (string.Equals(e.GameId, GameId, StringComparison.Ordinal))
     {
         RoundEnded?.Invoke(this, EventArgs.Empty);
     }
 }
Example #2
0
    public void EndRound()
    {
        RoundIsRunning = false;
        PlayerIsDead   = true;

        RoundEnded?.Invoke(this, new EventArgs());
    }
Example #3
0
            public void OnNext(GameSeriesEvent e)
            {
                var message = e
                              switch
                {
                    GameSeriesStarted start => $"a new game series of {start.Plan.Rounds.Count} rounds was started",
                    RoundStarted roundStarted => $"a new round started",
                    RoundEnded roundEnded => $"round finished. {PointInfo(roundEnded.Result.PlayerResults)}",
                    _ => e.ToString(),
                };

                Render(message, ConsoleColor.DarkMagenta);
                if (e is GameSeriesStarted s)
                {
                    _playerNames = s.Players.Select(p => p.Name).ToList();
                    _totalScores = s.Players.Select(_ => 0).ToList();
                }
                else if (e is RoundEnded end)
                {
                    foreach (var(r, i) in end.Result.PlayerResults.Select((r, i) => (r, i)))
                    {
                        _totalScores[i] += r.Score;
                    }
                    Render("Total scores: " + string.Join(", ", Enumerable.Zip(_playerNames, _totalScores)), ConsoleColor.DarkMagenta);
                }
            }
Example #4
0
 public void EndRound()
 {
     Units.ForEach(u => { u.OnRoundEnd(); });
     if (RoundEnded != null)
     {
         RoundEnded.Invoke(this, new EventArgs());
     }
     StartCoroutine(RoundStart());
 }
Example #5
0
        public void OnNext(RoundEnded ended)
        {
            var roundData  = ConvertRoundSettingsToDto(ended.Settings);
            var resultData = new RoundResultDto(ended.GameUuid, roundData, ended.Result.PlayerResults.Select(
                                                    pres => new PlayerRoundResultDto(pres.Guesses, pres.TricksWon, pres.Score)
                                                    ));

            _client.GameRoundEnded(resultData);
        }
Example #6
0
    public void EndRound()
    {
        Units.ForEach(u => { u.OnRoundEnd(); });
        if (RoundEnded != null)
        {
            RoundEnded.Invoke(this, new EventArgs());
        }
        StartCoroutine(RoundStart());

        //CellGridState = new CellGridStateTurnChanging(this);
    }
Example #7
0
        public Task GameRoundEnded(RoundResultDto data)
        {
            var settings = new EumelRoundSettings(data.GameRound.StartingPlayer, data.GameRound.TricksToPlay);
            var res      = new RoundResult(data.PlayerResults.Select(
                                               player => new PlayerRoundResult(player.Guesses, player.TricksWon, player.Score)
                                               ).ToList());
            var e = new RoundEnded(data.GameId, settings, res);

            _gameSeriesEventCallback(e);
            return(Task.CompletedTask);
        }
        public void End()
        {
            if (_gameState == GameState.Ended)
            {
                return;
            }

            _gameState = GameState.Ended;

            RoundEnded?.Invoke();

            Start();
        }
Example #9
0
        private IEnumerator StartTimer()
        {
            var duration = _roundSettings.Duration;

            while (duration > _timer)
            {
                _timer += Time.deltaTime;

                yield return(null);
            }

            _gameState = GameState.Ended;
            _isStarted = false;

            RoundEnded?.Invoke();
        }
Example #10
0
        public async Task Connect()
        {
            _hubConnection = new HubConnectionBuilder().WithUrl(_hubUri).Build();
            _hubConnection.On(GameEvents.GameSessionStarted, () => GameSessionStarted?.Invoke());
            _hubConnection.On <bool>(nameof(IsSessionOpen), (isOpen) => IsSessionOpen?.Invoke(isOpen));
            _hubConnection.On(GameEvents.PlayerCreated, () => PlayerCreated?.Invoke());
            _hubConnection.On <ICollection <string> >(nameof(IncomingPlayers), (players) => IncomingPlayers?.Invoke(players));
            _hubConnection.On(GameEvents.GameStarted, () => GameStarted?.Invoke());
            _hubConnection.On <int>(GameEvents.TimeElapsed, countDownSeconds => TimeElapsed?.Invoke(countDownSeconds));
            _hubConnection.On(GameEvents.GameStopped, () => GameStopped?.Invoke());
            _hubConnection.On <int>(GameEvents.RightAnswer, newScore => SentRightAnswer?.Invoke(newScore));
            _hubConnection.On <int>(GameEvents.WrongAnswer, newScore => SentWrongAnswer?.Invoke(newScore));
            _hubConnection.On(GameEvents.RoundEnded, () => RoundEnded?.Invoke());
            _hubConnection.On <string>(GameEvents.Question, question => QuestionSent?.Invoke(question));
            _hubConnection.On <AnswerAndPlayers>(GameEvents.AnswerAndPlayers, answerAndPlayers => GotAnswerAndPlayers?.Invoke(answerAndPlayers));
            _hubConnection.On(GameEvents.NextRoundStarted, () => NextRoundStarted?.Invoke());

            await _hubConnection.StartAsync();
        }
Example #11
0
        public Result StartGame()
        {
            round = new Round();
            RoundStarted?.Invoke();

            round.WinnerFound += player => {
                if (player == player1)
                {
                    round.result = Result.PlayerOneWon;
                    scores.player1Score++;
                }

                if (player == player2)
                {
                    round.result = Result.PlayerTwoWon;
                    scores.player2Score++;
                }
            };

            DrawBoard?.Invoke();
            do
            {
                round.Move(player1);
                DrawBoard?.Invoke();

                if (round.inPlay)
                {
                    round.Move(player2);
                    DrawBoard?.Invoke();
                }
            } while (round.inPlay);

            if (round.result == Result.Draw)
            {
                scores.draws++;
            }

            RoundEnded?.Invoke();
            return(round.result);
        }
Example #12
0
 protected void InvokeEndRound()
 {
     RoundEnded.Invoke();
 }
Example #13
0
 public RoundEndedPayload(RoundEnded roundEnded)
 {
     Settings      = roundEnded.Settings;
     PlayerResults = roundEnded.Result.PlayerResults.ToList();
 }
Example #14
0
        public void EndRound(string gameId)
        {
            DeleteGameState(gameId);

            RoundEnded?.Invoke(this, new GameIdEventArgs(gameId));
        }
Example #15
0
 public void RoundHasEnded(TimeSpan timeout)
 {
     RoundEnded?.Invoke(this, timeout);
 }
Example #16
0
 /// <summary>
 /// Called after the end of a round.
 /// </summary>
 /// <param name="ev">The <see cref="RoundEndedEventArgs"/> instance.</param>
 public static void OnRoundEnded(RoundEndedEventArgs ev) => RoundEnded.InvokeSafely(ev);
Example #17
0
 protected virtual void OnRoundEnded(object sender, DndGameEventArgs ea)
 {
     RoundEnded?.Invoke(sender, ea);
 }
 protected virtual void OnRoundEnded(object source, EventArgs e)
 {
     RoundEnded?.Invoke(source, e);
 }