Beispiel #1
0
    void addToStretchCount()
    {
        GameObject      go_clock    = GameObject.Find("stretch_count");
        stretch_counter clock_class = (stretch_counter)go_clock.GetComponent(typeof(stretch_counter));

        clock_class.incrementStretchCount();

        GameObject go_hs    = GameObject.Find("high_score");
        high_score hs_class = (high_score)go_hs.GetComponent(typeof(high_score));

        hs_class.incrementStretchCountForHS();
    }
Beispiel #2
0
            /* Checks whether all flags have been used and all tiles have been opened. */
            private void CheckForWin()
            {
                if (this.flags != 0 || this.Controls.OfType <Tile>().Count(tile => tile.Opened || tile.Flagged) != this.gridSize.Width * this.gridSize.Height)
                {
                    return;
                }
                /* Stop the stopwatch. */
                sw.Stop();
                /* Check if the high_scores list contains the current difficulty. */
                int difficulty_found = 0;

                for (int i = 0; i < high_scores.Count; i++)
                {
                    if (high_scores[i].Score_difficulty == difficulty)
                    {
                        difficulty_found++;
                    }
                }
                /* Flags whether a new highscore has been achieved. */
                int highscore_flag = 0;

                /* First entry for difficulty. */
                if (difficulty_found == 0)
                {
                    /* New high score. */
                    var score = new high_score()
                    {
                        Time = sw.Elapsed.ToString(), Score_difficulty = difficulty
                    };
                    high_scores.Add(score);
                    /* Show the highscore image. */
                    Form__.pbHS.Show();
                    highscore_flag++;
                }
                /* Difficulty already exists. */
                else
                {
                    /* Get the current high score for this difficulty. */
                    for (int i = 0; i < high_scores.Count; i++)
                    {
                        if (high_scores[i].Score_difficulty == difficulty)
                        {
                            /* If the time eclapsed is less than the current highscore for the difficulty. */
                            if (sw.Elapsed < TimeSpan.Parse(high_scores[i].Time))
                            {
                                /* New high score. */
                                high_scores[i].Time = sw.Elapsed.ToString();
                                Form__.pbHS.Show();
                                highscore_flag++;
                            }
                        }
                    }
                }
                /* Write highscores to XML */
                var serializer = new XmlSerializer(high_scores.GetType(), "HighScores.Scores");

                using (var writer = new StreamWriter("highscores.xml", false))
                {
                    serializer.Serialize(writer.BaseStream, high_scores);
                }
                /* If the user did not get a highscore, display the trophy game picture. */
                if (highscore_flag == 0)
                {
                    Form__.pbWin.Show();
                }

                /* Disable all tiles without setting the gameLost flag. */
                this.DisableTiles(false);
            }