예제 #1
0
        /// <summary>
        /// Updates the players UI when a player joins or ready status changes
        /// When all players are ready (min 2) it will start the game
        /// </summary>
        private void UpdatePlayers()
        {
            int readyPlayers = 0;

            if (players.Count == 0)
            {
                return;
            }
            // update the ui
            for (int i = 0; i <= playerLabels.Count; i++)
            {
                if (players.Count <= i)
                {
                    break;
                }
                string ready = players[i].isReady ? "(Ready)" : "(Not Ready)";
                readyPlayers        += players[i].isReady ? 1 : 0;
                playerLabels[i].Text = $@"{players[i]} {ready}";
            }
            // when ready condition is met, start the game
            if (readyPlayers >= 2 && readyPlayers == players.Count)
            {
                GameStarted = true;
                wheel.StartGame();
                Hide();
                gamePanel ??= new GamePanel(wheel, players, user);
                gamePanel.Show();
                gamePanel.FormClosed += (_, _) => wheel.LeaveGame();
                gamePanel.FormClosed += (_, _) => Close();
                gamePanel.PlayersUpdated(players.ToArray());
            }
        }