Ejemplo n.º 1
0
        public int CompareTo(Object other)
        {
            DatabaseRead otherRead   = (DatabaseRead)other;
            int          returnValue = this.Score.CompareTo(otherRead.Score);

            return(returnValue * -1);
        }
Ejemplo n.º 2
0
        //Used to grab database elements to display
        public static ArrayList readDatabase()
        {
            command             = new SQLiteCommand(connection);
            command.CommandText = "SELECT * FROM scores";
            SQLiteDataReader rdr;

            ArrayList databaseReads = new ArrayList();

            try {
                rdr = command.ExecuteReader();
            }catch (Exception e)
            {
                return(databaseReads);
            }

            while (rdr.Read())
            {
                DatabaseRead dbRead = new DatabaseRead()
                {
                    Name = rdr.GetString(0), Score = rdr.GetInt32(1)
                };
                databaseReads.Add(dbRead);
            }

            return(databaseReads);
        }
        private void updateScoresToDatabase(String Username)
        {
            ArrayList    dbReads = new ArrayList();
            DatabaseRead lastPlace;

            dbReads = DatabaseHandler.readDatabase();
            if (dbReads.Count != 0) //If HighScores are empty
            {
                dbReads.Sort();
                if (dbReads.Count == 10)
                {
                    lastPlace = (DatabaseRead)dbReads[9];
                    //Get a Name to add to the database
                    if (currentScore > lastPlace.Score) //If new score is high score-TODO
                    {
                        dbReads.RemoveAt(9);
                        dbReads.Add(new DatabaseRead {
                            Name = Username, Score = currentScore
                        });
                        dbReads.Sort();
                        DatabaseHandler.clearDBTable("scores");
                        DatabaseHandler.initializeDatabase();
                        for (int i = 0; i < 10; i++)
                        {
                            DatabaseRead read = (DatabaseRead)dbReads[i];
                            DatabaseHandler.preWriteStorage(read.Name, read.Score);
                        }
                    }
                }
                else if (dbReads.Count < 10) //If there are less than 10 reads it is a guaranteed top 10 high score, currently dont have scores sorted
                {
                    DatabaseHandler.preWriteStorage(Username, currentScore);
                }
            }
            if (dbReads.Count == 0) //Enter the highscore if there are no inputs
            {
                DatabaseHandler.preWriteStorage(Username, currentScore);
            }

            DatabaseHandler.writeToDatabase();
            dbReads.Clear();
        }