Example #1
0
        public bool SaveSnakeRating(SnakeRecord record)
        {
            lock (locker)
            {
                SnakeRecord old = dbConnection.Table <SnakeRecord>().FirstOrDefault();

                if (old == null)
                {
                    dbConnection.Insert(record);
                    return(true);
                }
                else
                {
                    if (record.MaxScore > old.MaxScore)
                    {
                        record.SnakeRtId = old.SnakeRtId;
                        dbConnection.Update(record, typeof(SnakeRecord));
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
        }
Example #2
0
        public void SaveResult()
        {
            Timer.Stop();
            long        mills  = Timer.ElapsedMilliseconds;
            SnakeRecord record = new SnakeRecord
            {
                GameTime     = mills,
                LastModified = DateTime.UtcNow,
                MaxScore     = BlockCount
            };

            App.Rest.UpdateSnake(record);
        }
Example #3
0
        public async void UpdateSnake(SnakeRecord record)
        {
            bool needsUpdate = Db.SaveSnakeRating(record);

            if (needsUpdate)
            {
                object toSend = new
                {
                    SnakeRtId    = 0,
                    MaxScore     = record.MaxScore,
                    GameTime     = record.GameTime,
                    LastModified = DateTime.UtcNow,
                    PlayerId     = Db.GetUser().ReturnableUser
                };
                string              jsonContent = JsonConvert.SerializeObject(toSend);
                StringContent       data        = new StringContent(jsonContent, Encoding.UTF8, "application/json");
                HttpResponseMessage response    = await client.PostAsync(snakeRecordUrl, data);
            }
        }