Esempio n. 1
0
        public ClientForm()
        {
            InitializeComponent();
            Player = new Players();
            LockMe = new Object();

            RolePicture = global::AvalonClient.Properties.Resources.Uknown;

            List<Bitmap> background = new List<Bitmap>();
            background.Add(global::AvalonClient.Properties.Resources.BackDrop);
            background.Add(global::AvalonClient.Properties.Resources.BackDrop2);
            background.Add(global::AvalonClient.Properties.Resources.BackDrop3);
            background.Add(global::AvalonClient.Properties.Resources.BackDrop4);
            background.Add(global::AvalonClient.Properties.Resources.BackDrop5);
            roundsPanel.BackgroundImage = background[new Random().Next(0, background.Count)];

            PlayersPlaying = new List<Players>();

            Task.Factory.StartNew(delegate { ConnectionStatus(); });
        }
Esempio n. 2
0
        private int ParseExtraInformation(string message)
        {
            int result = 0;

            string[] extraInfo = message.Split(';');
            if (message.StartsWith("PLAYERS_IN_GAME")) {
                lock (LockMe) {
                    PlayersPlaying.Clear();
                    foreach (string str in extraInfo) {
                        if (!string.IsNullOrEmpty(str)) {
                            string cleaned = str.Replace("PLAYERS_IN_GAME", "").Replace(";", "").Trim();
                            Players player = new Players();
                            player.Name = cleaned;
                            PlayersPlaying.Add(player);
                        }
                    }
                }

                result = (int)ServerRequest.PLAYERS_IN_GAME;
            }
            else if (message.StartsWith("TEAM_VOTE_RESULTS")) {
                lock (LockMe) {
                    PlayersOnTeam = new List<string>();
                    foreach (string str in extraInfo) {
                        if (!string.IsNullOrEmpty(str)) {
                            string cleaned = str.Replace("TEAM_VOTE_RESULTS", "").Replace(";", "").Trim();
                            foreach (Players player in PlayersPlaying) {
                                if (player.Name == cleaned.Replace(" True", "").Replace(" False", "")) {
                                    player.TeamVote = bool.Parse(cleaned.Replace(player.Name + " ", ""));
                                }
                            }
                        }
                    }
                }
                result = (int)ServerRequest.NONE;
            }
            else if (message.StartsWith("TEAM_VOTE")) {
                lock (LockMe) {
                   PlayersOnTeam = new List<string>();
                    foreach (string str in extraInfo) {
                        if (!string.IsNullOrEmpty(str)) {
                            string cleaned = str.Replace("TEAM_VOTE", "").Trim();
                            PlayersOnTeam.Add(cleaned);
                        }
                    }
                }
                result = (int)ServerRequest.TEAM_VOTE;
            }

            else if (message.StartsWith("KING")) {
                lock (LockMe) {
                    string msg = extraInfo[0].Replace("KING", "").Trim();
                    if (msg == Player.Name) {
                        Player.IsKing = true;
                    }
                    else {
                        Player.IsKing = false;
                    }
                }
                result = (int)ServerRequest.KING;
            }
            else if (message.StartsWith("LADY_OF_THE_LAKE")) {
                lock (LockMe) {
                    string msg = extraInfo[0].Replace("LADY_OF_THE_LAKE", "").Trim();
                    if (msg == Player.Name) {
                        Player.IsLadyLake = true;
                    }
                    else {
                        Player.IsLadyLake = false;
                    }
                }
                result = (int)ServerRequest.LADY_OF_THE_LAKE;
            }
            else if (message.StartsWith("ROLES")) {
                lock (LockMe) {
                    foreach (string str in extraInfo) {
                        if (!string.IsNullOrEmpty(str)) {
                            string cleaned = str.Replace("ROLES ", "").Replace(";", "").Trim();
                            string[] role = cleaned.Split(' ');
                            PlayersPlaying.Where(p => p.Name == role[0]).Single().Card = (PlayingCards)Enum.Parse(typeof(PlayingCards), role[1]);
                        }
                    }
                }
                result = (int)ServerRequest.ROLES;
            }
            else if (message.StartsWith("CHOOSE_TEAM")) {
                lock (LockMe) {
                    string msg = extraInfo[0].Replace("CHOOSE_TEAM", "").Trim();
                    MaxPlayersInTeam = int.Parse(msg);
                }
                result = (int)ServerRequest.CHOOSE_TEAM;
            }
            else if (message.StartsWith("MISSION_VOTE_FAILS")) {
                lock (LockMe) {
                    string msg = extraInfo[0].Replace("MISSION_VOTE_FAILS", "").Trim();
                    FailedVotesInRound = int.Parse(msg);
                    NeededFailVotes = int.Parse(extraInfo[1]);
                }
                result = (int)ServerRequest.MISSION_VOTE_FAILS;
            }
            else if (message.StartsWith("MERLIN_KILLED")) {
                lock (LockMe) {
                    string msg = extraInfo[0].Replace("MERLIN_KILLED", "").Trim();
                    MerlinKilled = bool.Parse(msg);
                }
                result = (int)ServerRequest.MERLIN_KILLED;
            }
            return result;
        }