コード例 #1
0
 public async Task GetUserData()
 {
     await FirebaseDatabase.DefaultInstance.GetReference("Users").GetValueAsync().ContinueWith(task =>
     {
         if (task.IsFaulted)
         {
             Debug.Log("task faulted");
         }
         else if (task.IsCompleted)
         {
             //it will return datasnapshot as a list
             DataSnapshot test = task.Result;
             Debug.Log(test.ChildrenCount);
             IEnumerator <DataSnapshot> childEnumerator = test.Children.GetEnumerator();
             string json;
             userList = new List <LeaderboardUser>();
             //im in an attempt id in each loop
             while (childEnumerator.MoveNext())
             {
                 DataSnapshot child = childEnumerator.Current;
                 Debug.Log(child.Key);
                 json = child.GetRawJsonValue();
                 LeaderboardUser user1 = JsonUtility.FromJson <LeaderboardUser>(json);
                 user1.userId          = child.Key.ToString();
                 userList.Add(user1);
             }
         }
     });
 }
コード例 #2
0
        public List <LeaderboardUser> GetLeagueUsers(int leagueId)
        {
            List <LeaderboardUser> users = new List <LeaderboardUser>();
            string getLeaderboardUserSql = @"select courses.holeCount, count(matches.id) as totalMatches, 
                                             sum(users_matches.score) as totalStrokes, users.firstName, users.lastName
                                             from users join users_matches on users_matches.userId = users.id
                                             join matches on matches.id = users_matches.matchId
                                             join users_leagues on users_leagues.userId = users.id
                                             join leagues on leagues.id = users_leagues.leagueId
                                             join courses on leagues.courseId = courses.id where leagues.id = @leagueId AND users_matches.score IS NOT NULL
                                             group by courses.holeCount, users.firstName, users.lastName;";

            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                conn.Open();
                SqlCommand cmd = new SqlCommand(getLeaderboardUserSql, conn);
                cmd.Parameters.AddWithValue("@leagueId", leagueId);

                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    LeaderboardUser user = AssembleLeaderboardUser(reader);
                    users.Add(user);
                }
                conn.Close();
            }
            return(users);
        }
コード例 #3
0
    IEnumerator GetLeaderboard()
    {
        WWWForm form = new WWWForm();

        form.AddField("email", userEmail);
        form.AddField("username", userName);

        using (UnityWebRequest www = UnityWebRequest.Post(rootURL + "leaderboard.php", form))
        {
            yield return(www.SendWebRequest());

            if (www.isNetworkError)
            {
                Debug.Log(www.error);
            }
            else
            {
                string responseText = www.downloadHandler.text;

                if (responseText.StartsWith("User"))
                {
                    string[] dataChunks = responseText.Split('|');
                    //Retrieve our player score and rank
                    if (dataChunks[0].Contains(","))
                    {
                        string[] tmp = dataChunks[0].Split(',');
                        highestScore = int.Parse(tmp[1]);
                        playerRank   = int.Parse(tmp[2]);
                    }
                    else
                    {
                        highestScore = 0;
                        playerRank   = -1;
                    }

                    //Retrieve player leaderboard
                    leaderboardUsers = new LeaderboardUser[dataChunks.Length - 1];
                    for (int i = 1; i < dataChunks.Length; i++)
                    {
                        string[]        tmp  = dataChunks[i].Split(',');
                        LeaderboardUser user = new LeaderboardUser();
                        user.username           = tmp[0];
                        user.score              = int.Parse(tmp[1]);
                        leaderboardUsers[i - 1] = user;
                        Debug.Log(leaderboardUsers[i - 1].username);
                        Debug.Log("Score dell'utente preso!");
                        Debug.Log("Ecco lo score dell'utente: " + user.score);
                    }
                }
                else
                {
                    Debug.Log(responseText);
                }
            }
        }
    }
コード例 #4
0
    public void Setup(LeaderboardUser ldbUser, bool last)
    {
        this.XpText.text       = ldbUser.Xp.ToString();
        this.PositionText.text = ldbUser.Position.ToString();

        if (last)
        {
            Border.enabled = false;
        }
    }
コード例 #5
0
        private LeaderboardUser AssembleLeaderboardUser(SqlDataReader reader)
        {
            LeaderboardUser user = new LeaderboardUser()
            {
                FirstName     = Convert.ToString(reader["firstName"]),
                LastName      = Convert.ToString(reader["lastName"]),
                TotalMatches  = Convert.ToInt32(reader["totalMatches"]),
                NumberOfHoles = Convert.ToInt32(reader["holeCount"]),
                TotalStrokes  = Convert.ToInt32(reader["totalStrokes"])
            };

            return(user);
        }
コード例 #6
0
    async void GetAllUsers()
    {
        Query         allUsersQery         = MainManager.Instance.firebaseManager.firestore.Collection("users");
        QuerySnapshot allUsersQerySnapshot = await allUsersQery.GetSnapshotAsync();

        List <LeaderboardUser> tempUsers = new List <LeaderboardUser>();

        foreach (DocumentSnapshot documentSnapshot in allUsersQerySnapshot.Documents)
        {
            Debug.Log(documentSnapshot.Id);
            Dictionary <string, object> userDict = documentSnapshot.ToDictionary();
            LeaderboardUser             user     = new LeaderboardUser();
            foreach (KeyValuePair <string, object> pair in userDict)
            {
                switch (pair.Key)
                {
                case "Username":
                    user.username = (string)pair.Value;
                    break;

                case "Wins":
                    user.wins = System.Convert.ToInt32(pair.Value);
                    break;

                default:
                    break;
                }
            }

            tempUsers.Add(user);
            //users.Add(documentSnapshot.Id, user);

            //Debug.Log(allUsernames);
            //Debug.Log(allWins);
            Debug.Log("Done!");
            //decks.Add(documentSnapshot.Id, selectedCards);
            //AddChild();
        }

        List <LeaderboardUser> sortedUsers = tempUsers.OrderBy(u => u.wins).Reverse().ToList();

        RenderUserOnLeaderboard(sortedUsers);
    }
コード例 #7
0
        //Generate a Leaderboard View by grabbing an ApplicationUser from Identity
        //and using that data we popuplate a LeaderboardUser
        public ActionResult DisplayLeaderboard()
        {
            RecipeDBEntities     ORM     = new RecipeDBEntities();
            ApplicationDbContext UserORM = new ApplicationDbContext();

            List <LeaderboardUser> LBlist = new List <LeaderboardUser>();

            List <string> tempList = ORM.RecipeAttempts.Select(x => x.User_ID).Distinct().ToList();

            foreach (string UserID in tempList)
            {
                LeaderboardUser temp     = new LeaderboardUser();
                ApplicationUser tempUser = UserORM.Users.Find(UserID);
                temp.UserName       = tempUser.Email;
                temp.TotalAttempts  = ORM.RecipeAttempts.Where(x => x.User_ID == UserID).Count();
                temp.AveDifficulty  = Math.Round(ORM.RecipeAttempts.Where(x => x.User_ID == UserID).Select(x => x.Difficulty).Select(int.Parse).Average(), 3);
                temp.AveIngredients = Math.Round((double)ORM.RecipeAttempts.Where(x => x.User_ID == UserID).Select(x => x.Recipe.Ingredients_Num).Average(), 3);

                LBlist.Add(temp);
            }
            List <int?> RatingList = ORM.Ratings.Select(x => x.AttemptID).Distinct().ToList();

            List <LeaderboardRating> LBRatingList = new List <LeaderboardRating>();


            foreach (var Attempt in RatingList)
            {
                RecipeAttempt   AttemptForLB = ORM.RecipeAttempts.Find(Attempt);
                ApplicationUser tempUser     = UserORM.Users.Find(AttemptForLB.User_ID);

                LeaderboardRating temp = new LeaderboardRating();
                temp.UserName = tempUser.Email;
                temp.Image    = AttemptForLB.image;
                temp.Title    = AttemptForLB.Recipe.Title;
                double AveRating = (double)ORM.Ratings.Where(x => x.RecipeAttempt.AttemptID == AttemptForLB.AttemptID).Select(x => x.Rating1).Average();
                temp.AveRating       = String.Format("{0:P2}.", AveRating);
                temp.NumberOfRatings = ORM.Ratings.Where(x => x.RecipeAttempt.AttemptID == AttemptForLB.AttemptID).Count();
                LBRatingList.Add(temp);
            }
            ViewBag.Ratings = LBRatingList;
            ViewBag.Users   = LBlist;
            return(View("../Home/Leaderboard"));
        }
コード例 #8
0
        public ActionResult OrderByTotalAttempts()
        {
            RecipeDBEntities     ORM     = new RecipeDBEntities();
            ApplicationDbContext UserORM = new ApplicationDbContext();

            List <LeaderboardUser> LBlist = new List <LeaderboardUser>();

            List <string> tempList = ORM.RecipeAttempts.Select(x => x.User_ID).Distinct().ToList();

            foreach (string UserID in tempList)
            {
                LeaderboardUser temp     = new LeaderboardUser();
                ApplicationUser tempUser = UserORM.Users.Find(UserID);
                temp.UserName       = tempUser.Email;
                temp.TotalAttempts  = ORM.RecipeAttempts.Where(x => x.User_ID == UserID).Count();
                temp.AveDifficulty  = Math.Round(ORM.RecipeAttempts.Where(x => x.User_ID == UserID).Select(x => x.Difficulty).Select(int.Parse).Average(), 3);
                temp.AveIngredients = Math.Round((double)ORM.RecipeAttempts.Where(x => x.User_ID == UserID).Select(x => x.Recipe.Ingredients_Num).Average(), 3);

                LBlist.Add(temp);
            }
            ViewBag.Users = LBlist.OrderBy(x => x.TotalAttempts);
            return(View("../Home/Leaderboard"));
        }
コード例 #9
0
	void Init(){
		m_Highscore 	= PlayerPrefs.GetInt(HIGH_SCORE_KEY, 0);
		m_PlayerEXP 	= PlayerPrefs.GetInt(PLAYER_EXP_KEY, 0);

		Volume_BGM 	= PlayerPrefs.GetFloat(VOLUME_BGM_KEY, 1f);
		Volume_FX 	= PlayerPrefs.GetFloat(VOLUME_FX_KEY, 1f);
		Weapon_Level = new int[(int)WeaponType.Limit];
		for (int i = 0; i < (int)WeaponType.Limit; i++) {
			Weapon_Level[i] = PlayerPrefs.GetInt(WEAPON_KEY + i.ToString(), 0);
		}
		Leaderboard = new List<LeaderboardUser>();
		for (int i = 0; i < LEADERBOARD_NUM; i++) {
			string name = PlayerPrefs.GetString (LEADERBOARD_NAME_KEY + i.ToString (), "");
			int score =  PlayerPrefs.GetInt (LEADERBOARD_VALUE_KEY + i.ToString (), -1);
			LeaderboardUser data = new LeaderboardUser(name,score,i); 
			Leaderboard.Add(data);
		}
	}
コード例 #10
0
        void lstAll_DrawItem(object sender, Tenor.Mobile.UI.DrawItemEventArgs e)
        {
            var             listBox = (Tenor.Mobile.UI.KListControl)sender;
            LeaderboardUser lboard  = (LeaderboardUser)e.Item.Value;

            User user = lboard.User;

            string     rankText = "#" + lboard.Rank.ToString();
            SizeF      rankSize = e.Graphics.MeasureString(rankText, medFont);
            RectangleF rankRect = new RectangleF(
                3 * factorF.Width,
                e.Bounds.Y + (e.Bounds.Height / 2 - rankSize.Height / 2),
                rankSize.Width,
                rankSize.Height
                );

            Size factor = Tenor.Mobile.UI.Skin.Current.ScaleFactor;

            if (!string.IsNullOrEmpty(user.ToString()))
            {
                int padding   = 5 * factor.Width;
                int imageSize = listBox.DefaultItemHeight - padding;

                RectangleF rect = new RectangleF
                                      (imageSize + (padding * 2) + rankRect.Right,
                                      e.Bounds.Y,
                                      e.Bounds.Width - (imageSize) - (padding * 2),
                                      e.Bounds.Height);

                if (user.FriendStatus != null && user.FriendStatus.Value == FriendStatus.self)
                {
                    Tenor.Mobile.Drawing.RoundedRectangle.Fill(e.Graphics,
                                                               borderPen, selectedBrush, e.Bounds, new Size(8 * factor.Width, 8 * factor.Height));
                }
                e.Graphics.DrawString(rankText, medFont, brush, rankRect);

                if (imageList != null && imageList.ContainsKey(user.ImageUrl))
                {
                    if (!imageListBuffer.ContainsKey(user.ImageUrl))
                    {
                        imageListBuffer.Add(user.ImageUrl, new AlphaImage(Main.CreateRoundedAvatar(imageList[user.ImageUrl], imageSize, factorF)));
                    }
                    AlphaImage image = imageListBuffer[user.ImageUrl];

                    Rectangle imgRect =
                        new Rectangle(Convert.ToInt32(rankRect.Right + padding),
                                      Convert.ToInt32(rect.Y + (rect.Height / 2) - (imageSize / 2)), imageSize, imageSize);
                    try
                    {
                        //e.Graphics.DrawImage(image, imgRect, new Rectangle(0, 0, image.Width, image.Height), GraphicsUnit.Pixel);
                        image.Draw(e.Graphics, imgRect);
                    }
                    catch (Exception ex) { Log.RegisterLog("gdi", ex); }
                }

                rect.Y += 2 * factor.Height;
                SizeF size = e.Graphics.MeasureString(user.ToString(), fontBold);
                e.Graphics.DrawString(
                    user.ToString(), fontBold, brush, rect);

                if (lboard.Scores != null)
                {
                    string text = "7-day high score: ";
                    text += lboard.Scores.Max.ToString();


                    rect.Y += size.Height + (3 * factor.Height);
                    e.Graphics.DrawString(
                        text, font, brush, rect, format);


                    var   scoreText = lboard.Scores.Recent.ToString();
                    SizeF sizeScore = e.Graphics.MeasureString(scoreText, bigFont);
                    rect = new RectangleF(
                        e.Bounds.Width - sizeScore.Width - (10 * factorF.Width),
                        e.Bounds.Y + (e.Bounds.Height / 2 - sizeScore.Height / 2),
                        sizeScore.Width, sizeScore.Height
                        );

                    e.Graphics.DrawString(
                        scoreText, bigFont, brush, rect, format);
                }


                if (user.FriendStatus != null && user.FriendStatus.Value != FriendStatus.self)
                {
                    Rectangle rect2 = new Rectangle(
                        e.Bounds.X, e.Bounds.Bottom - 2, e.Bounds.Width / 3, 1);
                    Tenor.Mobile.Drawing.GradientFill.Fill(e.Graphics, rect2, this.BackColor, Color.Gray, Tenor.Mobile.Drawing.GradientFill.FillDirection.LeftToRight);
                    rect2.X += rect2.Width;
                    Tenor.Mobile.Drawing.GradientFill.Fill(e.Graphics, rect2, Color.Gray, Color.Gray, Tenor.Mobile.Drawing.GradientFill.FillDirection.LeftToRight);
                    rect2.X += rect2.Width;
                    Tenor.Mobile.Drawing.GradientFill.Fill(e.Graphics, rect2, Color.Gray, this.BackColor, Tenor.Mobile.Drawing.GradientFill.FillDirection.LeftToRight);
                }
            }
        }