示例#1
0
        public void TestAddHighScoreAndGetHighScore()
        {
            var scoreForAdd = new HighScore();

            scoreForAdd.Add("angel", 50);

            Assert.AreEqual(1, scoreForAdd.GetHighScore().Count);
        }
示例#2
0
        private void load_highscore()
        {
            FileStream      fs = new FileStream(@"c:\temp\highscore.csv", FileMode.OpenOrCreate, FileAccess.Read);
            BinaryFormatter bf = new BinaryFormatter();

            using (var z = new GZipStream(fs, CompressionMode.Decompress))
            {
                var x = (HighScore)bf.Deserialize(z);



                foreach (Gamer o in x)
                {
                    _highScore.Add(o);
                }
            }

            fs.Close();
        }
示例#3
0
        static void Main(string[] args)
        {
            HighScore hs = new HighScore(4, true);

            hs.Load();
            hs.Print();

            hs.Add("Johan", 928);

            hs.Save();

            while (true)
            {
                ;
            }

            hs.Add("JamesTKirk", 132);
            hs.Add("AgentMulder", 120);
            hs.Add("CaptainPicard", 40);
            hs.Add("BobbaFett", 180);
            hs.Add("NewName");

            /* Print list */
            hs.Print();

            hs.Add("RickDeckard", 403);
            hs.Add("DonaldDuck", 45);

            hs.Print();

            hs.Add("RickDeckard", 394);
            hs.Add("DonaldDuck", 47);

            hs.Print();

            hs.Save();

            Console.ReadLine();
        }
    public void Die()
    {
        GoPlayScene.last         = 0;
        GoPrePlayScene.lastScene = 1;
        Destroy(gameObject);
        life = 5;
        HighScore h = HighScore.LoadHighScore();

        h.Add(UIController.score, GetName.getName(), h);
        HighScore.SaveHighScore(h);
        UIController.score = 0;
        Instantiate(GOUI);
    }
        public static State NewHighScoreUpdate(GameTime gameTime, ContentManager content, GameWindow window)
        {
            hs.Update(gameTime);             // Execute update method in hs object

            KeyboardState keyboardState = Keyboard.GetState();

            if (keyboardState.IsKeyDown(Keys.Enter))   // If enter is pressed
            {
                hs.Add(player.Points);                 // Add name + score to highscorelist
                Reset(window, content);                // Reset the game and go to main menu
                // Set a cooldown on the menu so that game doesn't automatically start again
                menu.lastChange = gameTime.TotalGameTime.TotalMilliseconds;
                return(State.Menu);
            }
            return(State.NewHighscore);            // Keep newhighscore running as default
        }
示例#6
0
    public static void GameOver()
    {
        Console.BackgroundColor = ConsoleColor.Black;
        Console.ForegroundColor = ConsoleColor.Yellow;
        Console.Clear();

        Engine.GameIsOn    = false;
        Level.levelCounter = 1;

        Random rnd = new Random();

        for (int i = 0; i < 60; i++)
        {
            Console.SetCursorPosition(rnd.Next(2, 100), rnd.Next(2, 28));
            Console.WriteLine("GAME OVER");
            Thread.Sleep(100);
        }

        Thread.Sleep(3000);
        Console.Clear();

        HighScore.Add(scoreCount, null);
    }
示例#7
0
    public int GetWinner()
    {
        int winner = 0;

        if (_player1Score > _player2Score)
        {
            winner = 1;
            HighScore.Add(Mathf.RoundToInt(_player1Score), winner);
        }
        else if (_player1Score < _player2Score)
        {
            winner = 2;
            HighScore.Add(Mathf.RoundToInt(_player2Score), winner);
        }
        else
        {
            winner = 0;
            HighScore.Add(Mathf.RoundToInt(_player1Score), winner);
        }


        return(winner);
    }
    public void checkLetter(int value)
    {
        int c = 0;

        for (int i = 0; i < ab.Length; i++)
        {
            if (ab[i].ans == value)
            {
                if (ab[i].isFill == false)
                {
                    put(i);
                    count++;
                    ab[i].isFill = true;
                }
                c = 1;
                UIController.increaseScore(100);
                if (count == ab.Length)
                {
                    UIController.increaseScore((int)UIController.getRemainingTime() * 10);
                    new GameObject().AddComponent <GoPrePlayScene>();
                }
                if (count == ab.Length && GoPlayScene.last == 5)
                {
                    UIController.increaseScore((int)UIController.getRemainingTime() * 10);
                    HighScore h = HighScore.LoadHighScore();
                    h.Add(UIController.score, GetName.getName(), h);
                    HighScore.SaveHighScore(h);
                    new GameObject().AddComponent <GoPrePlayScene>();
                }
            }
        }
        if (c == 0)
        {
            UIController.decreaseTime();
        }
    }
示例#9
0
        static void Main(string[] args)
        {
            Random slumpat = new Random();

            /* New highscore with 10 max items and sorted by
             * lowest first */
            HighScore highscore = new HighScore(10, false);

            /* Load highscore file, if available */
            highscore.Load();

            /* Error:
             * Random.Next() without passed parameters
             * randomizes any number up to max integer size
             *
             * Solution:
             * Pass parameters to randomize between 1 and 20  */
            int speltal = slumpat.Next(1, 21);

            int  guessCount = 0; // Count guesses
            bool spela      = true;

            /* Error:
             * Program doesn't enter while-loop
             *
             * Solution:
             * Changed !spela -> spela, ! before a bool
             * variable means NOT (inverts) */
            while (spela)
            {
                int tal;
                guessCount++;

                /*
                 * Runtime error:
                 * "Input string was not in a correct format."
                 * if user enters non-integer
                 *
                 * Solution:
                 * Use int.TryParse() instead of Convert.ToInt32(),
                 * TryParse returns a truth value
                 * depending on conversion success -
                 * repeat user input until
                 * conversion succeeds.
                 *
                 * "int tal" is passed as a reference to
                 * the method with the "out" keyword. Passing
                 * variables as a reference, instead of a copy,
                 * allows the method to change their
                 * values.
                 */
                do
                {
                    Console.Write(
                        "\n\tGissa på ett tal mellan 1 och 20: ");
                } while (!int.TryParse( //while conversion is NOT successful
                             Console.ReadLine(), out tal));


                if (tal < speltal)
                {
                    Console.WriteLine("\tDet inmatade talet "
                                      + tal + " är för litet, försök igen.");
                }

                if (tal > speltal)
                {
                    /* Error:
                     * Syntax error, ',' expected
                     *
                     * Solution:
                     * Added + for string concatenation
                     */
                    Console.WriteLine("\tDet inmatade talet "
                                      + tal + " är för stort, försök igen.");
                }

                /* Error:
                 * Cannot implicitly convert type 'int' to 'bool'
                 *
                 * Solution:
                 * Changed = -> == (assignment operator to relational operator)
                 */
                if (tal == speltal)
                {
                    Console.WriteLine(
                        "\n\tGrattis, du gissade rätt! ({0} antal försök)",
                        guessCount);

                    Console.Write("\tAnge ditt namn för highscore: ");
                    highscore.Add(Console.ReadLine(), guessCount);

                    highscore.Print();

                    Console.WriteLine("\n\tTryck på \"J\" för att spela igen!");
                    if (char.ToLower(Console.ReadKey(true).KeyChar) != 'j')
                    {
                        /* Error:
                         * Program quit after first guess
                         *
                         * Solution:
                         * Added curly braces to if-statement, as code block
                         * was intended to include "spela = false;
                         */
                        spela = false;
                    }

                    /* Randomize new number and reset count */
                    speltal    = slumpat.Next(1, 21);
                    guessCount = 0;
                }
            }

            /* Save highscores to file */
            highscore.Save();
        }