示例#1
0
        public List <HighscoreModel> getHighscores()
        {
            List <HighscoreModel> highscores = new List <HighscoreModel>();

            try
            {
                string query = "SELECT * FROM dbo.Highscores ORDER BY TIME ASC";

                using (SqlConnection cn = new SqlConnection(connectionString))
                    using (SqlCommand cmd = new SqlCommand(query, cn))
                    {
                        cn.Open();
                        SqlDataReader reader = cmd.ExecuteReader();

                        while (reader.Read())
                        {
                            int            id       = (int)reader["ID"];
                            string         userName = (string)reader["USERNAME"];
                            int            time     = (int)reader["TIME"];
                            HighscoreModel hs       = new HighscoreModel();
                            hs.Id       = id;
                            hs.Username = userName;
                            hs.Time     = time;
                            highscores.Add(hs);
                        }
                        cn.Close();
                    }
            }
            catch (SqlException e)
            {
                throw e;
            }
            return(highscores);
        }
        public void InitiateNewGame()
        {
            if (string.IsNullOrEmpty(username))
            {
                username = config.DefaultUsername + random.Next(10000, 99999).ToString() + "_" + DateTime.Now.ToString("yy/MM/dd");
            }

            highscore = InputOutputService.Load <HighscoreModel>(highscorePath);

            gameTime = new Stopwatch();
            gameTime.Start();
        }
示例#3
0
        private async Task DisplayHighscore(HighscoreModel result, string map, string className)
        {
            var builder = new EmbedBuilder
            {
                Title = $"**{result.Name}'s** {className} time on **{await SimplyDataAccess.GetFullMapName(map)}**"
            };

            if (EqualityComparer <HighscoreModel> .Default.Equals(result, default(HighscoreModel)))
            {
                builder.WithDescription("No time available");
            }

            builder.WithDescription($"**{result.Name}**: {result.GetTimeSpan:c}");

            await ReplyEmbed(builder);
        }
示例#4
0
    public async Task <List <HighscoreModel> > GetOverAllHighscores()
    {
        List <HighscoreModel> models    = new List <HighscoreModel>();
        DatabaseReference     reference = FirebaseDatabase.DefaultInstance.GetReference("GalaticRangers").Child("Highscore").Child("Overall");
        await reference.GetValueAsync().ContinueWithOnMainThread(task =>
        {
            DataSnapshot snapshot = task.Result;
            foreach (DataSnapshot data in snapshot.Children)
            {
                string highscoreJSON = data.GetRawJsonValue();
                HighscoreModel model = JsonUtility.FromJson <HighscoreModel>(highscoreJSON);
                models.Add(model);
            }
        });

        return(models);
    }
示例#5
0
    IEnumerator GetScore()
    {
        WWWForm form = new WWWForm();

        var download = UnityWebRequest.Get(GetHighScoreUrl);

        yield return(download.SendWebRequest());

        if (download.isNetworkError || download.isHttpError)
        {
            Debug.Log("Shit has hit the fan");
        }
        else
        {
            HighscoreModel highscore = new HighscoreModel();
            highscore = JsonUtility.FromJson <HighscoreModel>(download.downloadHandler.text);
            Debug.Log(download.downloadHandler.text);
            Debug.Log("Player name is: " + highscore.Name + " with score " + highscore.Score);
        }
    }
示例#6
0
    public void SaveOverAllHighscore(HighscoreModel model)
    {
        DatabaseReference reference = FirebaseDatabase.DefaultInstance.GetReference("GalaticRangers").Child("Highscore").Child("Overall").Push();

        string JSONHighscore = JsonUtility.ToJson(model);

        Debug.Log("Json: " + JSONHighscore);

        reference.SetRawJsonValueAsync(JSONHighscore).ContinueWithOnMainThread(task =>
        {
            if (task.Exception != null)
            {
                Debug.Log("failed: Couldn't save highscore the data to the database.");
            }
            else if (task.IsCompleted)
            {
                Debug.Log("saving completed.");
            }
        });
    }
示例#7
0
        public IActionResult Highscore(string qr)
        {
            var uri      = configuration.GetValue <string>("ApiUri");
            var gamerId  = Guid.Parse(qr);
            var gamer    = gamerContextMethods.GetGamer(gamerId);
            var userJson = new List <string>();

            try
            {
                using (var client = new HttpClient())
                {
                    if (!float.TryParse(gamer.QrCode, out float number))
                    {
                        userJson.Add($"Invalid QR: {gamer.QrCode}");
                    }
                    var userUri = $"{uri}{gamer.QrCode}";
                    //var userUri = $"{uri}{"9626442211223632793001"}";
                    var task = client.GetStringAsync(userUri);
                    task.Wait();
                    if (!task.IsCompletedSuccessfully)
                    {
                        throw new ApplicationException($"error on lookup. code: {task.Result}");
                    }
                    userJson.Add(task.Result);
                }
            }
            catch (Exception ex)
            {
                userJson.Add($"Lookup failed for qr {gamer.QrCode}");
            }


            var model = new HighscoreModel
            {
                UserJson = userJson
            };

            return(View(model));
        }
示例#8
0
        public List <HighscoreModel> getUserHighscore(string username)
        {
            List <HighscoreModel> highscore = new List <HighscoreModel>();

            try
            {
                string query = "SELECT TOP 1 * FROM dbo.Highscores WHERE USERNAME=@Username ORDER BY TIME ASC";

                using (SqlConnection cn = new SqlConnection(connectionString))
                    using (SqlCommand cmd = new SqlCommand(query, cn))
                    {
                        cmd.Parameters.Add("@Username", SqlDbType.VarChar, 50).Value = username;

                        cn.Open();
                        SqlDataReader reader = cmd.ExecuteReader();

                        while (reader.Read())
                        {
                            int    id       = (int)reader["ID"];
                            string userName = (string)reader["USERNAME"];
                            int    time     = (int)reader["TIME"];

                            HighscoreModel hs = new HighscoreModel();
                            hs.Id       = id;
                            hs.Username = userName;
                            hs.Time     = time;

                            highscore.Add(hs);
                        }
                        cn.Close();
                    }
            }
            catch (SqlException e)
            {
                throw e;
            }
            return(highscore);
        }