Пример #1
0
        public List <LeaderBoardData> GetLeaderBoardData()
        {
            List <LeaderBoardData> datas = new List <LeaderBoardData>();

            try
            {
                List <User> users = conn.Query <User>("Select * from User");
                for (int index = 0; index < users.Count; index++)
                {
                    datas.Add(GetLeaderBoardData(users[index].UserName));
                }
            }
            catch (Exception ex)
            {
            }
            if (datas.Count > 0)
            {
                for (int i = 0; i < datas.Count - 1; i++)
                {
                    for (int j = 0; j < datas.Count - i - 1; j++)
                    {
                        if (datas[j].Score < datas[j + 1].Score)
                        {
                            LeaderBoardData temp = datas[j];
                            datas[j]     = datas[j + 1];
                            datas[j + 1] = temp;
                        }
                    }
                }
            }
            return(datas);
        }
Пример #2
0
        public LeaderBoardData GetLeaderBoardData(string username)
        {
            LeaderBoardData data = new LeaderBoardData();

            data.UserName = username;
            try
            {
                string           query = "Select * from UserGames Where UserName='******'";
                List <UserGames> games = conn.Query <UserGames>(query);
                for (int index = 0; index < games.Count; index++)
                {
                    data.Score += games[index].TotalScore;
                    if (games[index].GameStatus.Equals("WIN"))
                    {
                        data.Win += 1;
                    }
                    else
                    {
                        data.Lose += 1;
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(data);
        }