예제 #1
0
        /// <summary>
        /// Gets all scores for each users which has played in given parameter as GroupName
        /// </summary>
        /// <param name="GroupName">Name of group which want to get user scores from</param>
        /// <returns>Scores containing information about user scores.</returns>
        public Scores GetAllScores(string GroupName)
        {
            Scores scores = new Scores();

            DataTable dt = TableMethods.GetTable(BaseMethod.DbPath, "UserValues",
                "GroupName", "=", new object[] { GroupName });

            if (dt != null && dt.Rows.Count > 0)
            {
                Dictionary<int, string> AllFields = new Dictionary<int, string>();
                FieldsManager fm = new FieldsManager();
                UserValuesManager userFieldsManager = new UserValuesManager();
                ValidItems validItems = new ValidItems();
                var allFields = fm.GetAllFields();
                foreach (var field in allFields)
                    AllFields.Add(field.ID, field.Title);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    int FieldID = (int)dt.Rows[i]["FieldID"];
                    string UserNick = (string)dt.Rows[i]["UserNick"];
                    string FieldValue = (string)dt.Rows[i]["FieldValue"];
                    if (!AllFields.ContainsKey(FieldID))
                        continue;
                    string FieldTitle = AllFields[FieldID];

                    int score = 0;
                    bool isValidValue = validItems.IsValidValue(FieldID, FieldValue);
                    if (isValidValue)
                    {
                        if (userFieldsManager.IsValueDuplicate(FieldID, GroupName, FieldValue))
                            score = 5;
                        else score = 10;
                    }

                    UserScores us = scores.GetUserScores(UserNick);
                    ScoreItem si = new ScoreItem()
                    {
                        ID = FieldID,
                        Value = FieldValue,
                        Title = FieldTitle,
                        Score = score
                    };
                    us.AddNewScoreItem(si);
                }
            }
            return scores;
        }
예제 #2
0
 public MainWindowViewModel()
 {
     FieldsManager fm = new FieldsManager();
     var Fields = fm.GetAllFields();
     this.Fields.AllFields = new ObservableCollection<Field>(Fields);
 }
예제 #3
0
 public override void OnData(Data data)
 {
     base.OnData(data);
     if (!string.IsNullOrEmpty(this.GroupName) && !Group.Groups.ContainsKey(this.GroupName))
     {
         Dispose();
         return;
     }
     // process each requsts depending of its message type
     switch (data.MessageType)
     {
         case MessageTypes.Connect:
             Auth auth = Deserializer.DeserializeFrmString<Auth>(data.Body);
             if (NickNames.Contains(auth.Username))
             {
                 this.Send(MessageTypes.Error, "کاربری با این نام کاربری قبلا وارد شده است");
                 return;
             }
             if (!new UserAuthManager().IsValidUser(auth.Username, auth.MacAddress))
             {
                 this.Send(MessageTypes.Error, "شما اجازه دسترسی به سرور را ندارید");
                 return;
             }
             this.NickName = auth.Username;
             NickNames.Add(this.NickName);
             this.Send(MessageTypes.Login, null);
             return;
         case MessageTypes.Join:
             this.GroupName = data.Body;
             if (!Group.Groups.ContainsKey(this.GroupName))
             {
                 Group.Groups.Add(this.GroupName, new Group() { Name = this.GroupName });
                 new UserValuesManager().RemoveAllUserValues(this.GroupName);
             }
             else if (Group.Groups[this.GroupName].GameStarted)
             {
                 this.Send(MessageTypes.Error, "بازی در این گروه قبلا اجرا شده است");
                 return;
             }
             if (Group.Groups[this.GroupName].GetClientByNickname(this.NickName) != null)
                 return;
             Group.Groups[this.GroupName].AddNewClient(this);
             return;
         case MessageTypes.StartGame:
             Group.Groups[this.GroupName].StartGame();
             return;
         case MessageTypes.Field:
             Field field = Deserializer.DeserializeFrmString<Field>(data.Body);
             FieldsManager fm = new FieldsManager();
             field.IsValid = fm.IsValidValue(field);
             new UserValuesManager().AddNewUserValue(field, this.GroupName, this.NickName);
             Send(MessageTypes.Field, Serializer.GetSerializedClass<Field>(field));
             return;
         case MessageTypes.Stop:
             if (Group.Groups[this.GroupName].GameStarted)
                 Group.Groups[this.GroupName].StopGame();
             return;
         case MessageTypes.Close:
             this.FireOnDisconnect();
             return;
     }
 }