private void SetUserList() { ManagementObjectSearcher usersSearcher = new ManagementObjectSearcher(@"SELECT * FROM Win32_UserAccount"); ManagementObjectCollection users = usersSearcher.Get(); var rawAllUsers = users.Cast <ManagementObject>(); var rawActiveUsers = rawAllUsers.Where(u => { return((bool)u["LocalAccount"] == true && (bool)u["Disabled"] == false && (bool)u["Lockout"] == false && int.Parse(u["SIDType"].ToString()) == 1 && u["Name"].ToString() != "HomeGroupUser$"); }); var allUsers = (from item in rawAllUsers select item["Name"].ToString()).ToList(); var activeUsers = (from item in rawActiveUsers select item["Name"].ToString()).ToList(); AllUsernameList.AddRange(allUsers); if (activeUsers.Count < 2) { return; } UsernameList.Clear(); PickUsername = ""; var username = Environment.UserName; foreach (var activeUser in activeUsers) { if (activeUser != username) { UsernameList.Add(activeUser); } } }
public GameState(string dealerUsername, List <Player> allusers, bool bWithNines) { cardsRevealed = 0; allusers.Sort(Player.Compare); this.UsernameList = new List <string>(); foreach (Player p in allusers) { UsernameList.Add(p.name); } List <string> activePlayers = new List <string>(); if (allusers.Count < 4) { // only for debugging purposes! activePlayers = UsernameList; for (int i = UsernameList.Count; i < 4; i++) { activePlayers.Add("(Platzhalter) " + (i + 1).ToString()); } int idxDealer = UsernameList.IndexOf(dealerUsername); int idxStartingPlayer = 0; StartingPlayer = activePlayers[idxStartingPlayer]; // throw new System.InvalidOperationException("at least 4 players required"); } else if (UsernameList.Count == 4) { activePlayers = UsernameList; int idxDealer = UsernameList.IndexOf(dealerUsername); int idxStartingPlayer = (idxDealer + 1) % 4; StartingPlayer = activePlayers[idxStartingPlayer]; } else if (UsernameList.Count == 5) { activePlayers = UsernameList; int idxDealer = UsernameList.IndexOf(dealerUsername); StartingPlayer = activePlayers[(idxDealer + 1) % 5]; activePlayers.Remove(dealerUsername); } else if (UsernameList.Count == 6) { activePlayers = UsernameList; int idxDealer = UsernameList.IndexOf(dealerUsername); string otherPassingPlayer = UsernameList[(idxDealer + 3) % 6]; StartingPlayer = activePlayers[(idxDealer + 1) % 6]; activePlayers.Remove(dealerUsername); activePlayers.Remove(otherPassingPlayer); } else if (UsernameList.Count == 7) { activePlayers = UsernameList; int idxDealer = UsernameList.IndexOf(dealerUsername); string otherPassingPlayer = UsernameList[(idxDealer + 2) % 7]; string otherPassingPlayer2 = UsernameList[(idxDealer + 4) % 7]; StartingPlayer = activePlayers[(idxDealer + 1) % 7]; activePlayers.Remove(dealerUsername); activePlayers.Remove(otherPassingPlayer); activePlayers.Remove(otherPassingPlayer2); } else if (allusers.Count >= 8) { throw new System.NotImplementedException("8 players want to play: might follow some day..."); } var deck = new Shared.Deck(bWithNines); deck.Shuffle(); CurrentTrick = new Dictionary <string, Card>(); LastTrick = new Dictionary <string, Card>(); PlayerStates = new Dictionary <string, PlayerGameState>(); for (int i = 0; i < activePlayers.Count; i++) { var gameStatePlayer = new PlayerGameState(deck.GetCardsForPlayer(i)); PlayerStates.Add(activePlayers[i], gameStatePlayer); } AllPlayedCards = new List <Card>(); AllPlayedCardsNames = new List <string>(); gamePhase = GamePhase.Dealt; }
public ComInitializeMFDialogViewModel() { _ConfigManager = GVar.Instance.ConfigManager; UsernameList.Add(pickUserPlaceholder); SetUserList(); }