Exemple #1
0
        private void stateChanged(ValueChangedEvent <TourneyState> state)
        {
            try
            {
                if (state.NewValue == TourneyState.Ranking)
                {
                    if (warmup.Value || CurrentMatch.Value == null)
                    {
                        return;
                    }

                    if (ipc.Score1.Value > ipc.Score2.Value)
                    {
                        CurrentMatch.Value.Team1Score.Value++;
                    }
                    else
                    {
                        CurrentMatch.Value.Team2Score.Value++;
                    }
                }

                scheduledOperation?.Cancel();

                void expand()
                {
                    chat?.Contract();

                    using (BeginDelayedSequence(300))
                    {
                        scoreDisplay.FadeIn(100);
                        SongBar.Expanded = true;
                    }
                }

                void contract()
                {
                    SongBar.Expanded = false;
                    scoreDisplay.FadeOut(100);
                    using (chat?.BeginDelayedSequence(500))
                        chat?.Expand();
                }

                switch (state.NewValue)
                {
                case TourneyState.Idle:
                    contract();

                    const float delay_before_progression = 4000;

                    // if we've returned to idle and the last screen was ranking
                    // we should automatically proceed after a short delay
                    if (lastState == TourneyState.Ranking && !warmup.Value)
                    {
                        if (CurrentMatch.Value?.Completed.Value == true)
                        {
                            scheduledOperation = Scheduler.AddDelayed(() => { sceneManager?.SetScreen(typeof(TeamWinScreen)); }, delay_before_progression);
                        }
                        else if (CurrentMatch.Value?.Completed.Value == false)
                        {
                            scheduledOperation = Scheduler.AddDelayed(() => { sceneManager?.SetScreen(typeof(MapPoolScreen)); }, delay_before_progression);
                        }
                    }

                    break;

                case TourneyState.Ranking:
                    scheduledOperation = Scheduler.AddDelayed(contract, 10000);
                    break;

                default:
                    chat.Contract();
                    expand();
                    break;
                }
            }
            finally
            {
                lastState = state.NewValue;
            }
        }
Exemple #2
0
 /// <summary>
 /// Create a new tourney
 /// </summary>
 /// <param name="Name">The name of the tourney</param>
 /// <param name="State">The state of the tourney (mostly needed for loading from storage)</param>
 public Tourney(string Name, TourneyState State = TourneyState.NotStarted)
 {
     //Link the name and state of the tourney
     name  = Name;
     state = State;
 }
Exemple #3
0
 public void TestStartupStateNoCurrentMatch([Values] TourneyState state)
 {
     AddStep("set null current", () => Ladder.CurrentMatch.Value = null);
     AddStep("set state", () => IPCInfo.State.Value = state);
     createScreen();
 }
Exemple #4
0
        //Determine next round's matches
        public void DetermineNextRound()
        {
            List <Player> matchWinners    = new List <Player>();
            List <Match>  matchesUnplayed = new List <Match>();
            List <Match>  markAsComplete  = new List <Match>();

            //Check which matches are played
            foreach (Match match in matches)
            {
                switch (match.matchState)
                {
                //Undecided matches are Unplayed
                case MatchState.Undecided:
                    matchesUnplayed.Add(match);
                    break;

                //If matches aren't finished yet, skip this function
                case MatchState.NotStarted: return;

                //Skipped matches get checked if the match has been decided already before adding to any list
                case MatchState.Skip:

                    if (match.players[0] != null)
                    {
                        matchWinners.Add(match.players[0]);
                        markAsComplete.Add(match);
                    }
                    else
                    {
                        matchesUnplayed.Add(match);
                    }
                    break;

                //Finished matches get added to played matches
                case MatchState.Finished:
                    matchWinners.Add(match.winner);
                    markAsComplete.Add(match);
                    break;

                //Matches whose round is finished are skipped
                case MatchState.RoundFinished: break;
                }
            }

            //Mark finished or skipped round as completed
            foreach (Match match in markAsComplete)
            {
                match.matchState = MatchState.RoundFinished;
            }

            //Check if the final match is played
            if (matchWinners.Count == 1)
            {
                //Show a message to the user
                System.Windows.Forms.MessageBox.Show(matchWinners[0].name + " heeft het toernooi gewonnen!", "Informatie");
                //Set state to finished and return
                state = TourneyState.Finished;
                return;
            }

            //Determine next round with the previous round's winners
            Random rng = new Random();

            Player[] nextRoundPlayers = matchWinners.OrderBy(x => rng.Next()).ToArray();

            for (int i = 0, j = 0; j < nextRoundPlayers.Length; i++, j += 2)
            {
                //If the match is to be skipped, add player to it
                if (matchesUnplayed[i].matchState == MatchState.Skip)
                {
                    matchesUnplayed[i].players[0] = nextRoundPlayers[j];
                    j--; //revert j one back because only one winner is used
                }
                else //Else add a normal match
                {
                    matchesUnplayed[i].players[0] = nextRoundPlayers[j];
                    matchesUnplayed[i].players[1] = nextRoundPlayers[j + 1];
                    matchesUnplayed[i].matchState = MatchState.NotStarted;
                }
            }
        }
Exemple #5
0
 public void TestStartupState([Values] TourneyState state)
 {
     AddStep("set state", () => IPCInfo.State.Value = state);
     createScreen();
 }