Exemplo n.º 1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="playerScore">The score of the player. At least time and moves must be filled.</param>
        public GameOver(HighscoreItem playerScore)
        {
            InitializeComponent();
            
            // Start the fade in animation
            fadeInAnimation.Begin();

            // Show the position textblock and player name textbox only if the
            // score is good enough to make it to the list.
            score = playerScore;
            int position = Highscores.IsNewHighscore(score);
            score.Index = position;
            if (position > 0)
            {
                playerName.Visibility = Visibility.Visible;
                textBlockPlacement.Text = "Your placement is " + position.ToString();
            }
            else
            {
                playerName.Visibility = Visibility.Collapsed;
                ConfirmButton.Content = "Ok";
                textBlockPlacement.Text = "";
            }

            textBlockTime.Text = "Your time was " + score.Time.ToString();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="playerScore">The score of the player. At least time and moves must be filled.</param>
        public GameOver(HighscoreItem playerScore)
        {
            InitializeComponent();

            // Start the fade in animation
            fadeInAnimation.Begin();

            // Show the position textblock and player name textbox only if the
            // score is good enough to make it to the list.
            score = playerScore;
            int position = Highscores.IsNewHighscore(score);

            score.Index = position;
            if (position > 0)
            {
                playerName.Visibility   = Visibility.Visible;
                textBlockPlacement.Text = "Your placement is " + position.ToString();
            }
            else
            {
                playerName.Visibility   = Visibility.Collapsed;
                ConfirmButton.Content   = "Ok";
                textBlockPlacement.Text = "";
            }

            textBlockTime.Text = "Your time was " + score.Time.ToString();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Checks if given score is a new highscore
        /// </summary>
        /// <param name="score">Score to check. The score should contain at least the solving time and moves.</param>
        /// <returns>The position in highscore list, or zero if the score doesn't make it to the list</returns>
        static public int IsNewHighscore(HighscoreItem score)
        {
            foreach (HighscoreItem item in scores)
            {
                // Check the time, and if the times are the same, check the
                // moves needed to solve the puzzle
                if (score.Time < item.Time ||
                    (score.Time == item.Time && score.Moves < item.Moves))
                {
                    return(item.Index);
                }
            }

            return(0);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Add a new score to highscore list
 /// </summary>
 /// <param name="score">Score to add. All members of the score should be filled.</param>
 static public void AddNewHighscore(HighscoreItem score)
 {
     // Insert the score into the list, remove weakest score from the list
     // and save the list.
     if (score.Index <= 0)
     {
         return;
     }
     scores.Insert(score.Index - 1, score);
     scores.RemoveAt(scores.Count - 1);
     for (int t = score.Index; t < scores.Count; t++)
     {
         scores[t].Index++;
     }
     Save();
 }
Exemplo n.º 5
0
        /// <summary>
        /// Ends current game. Called when all the cells are filled.
        /// </summary>
        private void GameEnds()
        {
            gameTimer.Stop();

            // Blink all cells and prevent the player from modifying the cells
            for (int row = 0; row < GameLogic.RowLength; row++)
            {
                for (int col = 0; col < GameLogic.ColumnLength; col++)
                {
                    game.Model.BoardNumbers[row][col].SetByGame = true;                     // to block the user input
                    cells[row][col].Blink();
                }
            }

            // Display the score with GameOver dialog
            HighscoreItem score = new HighscoreItem();

            score.Time = new TimeSpan(gameTimeElapsed.Days, gameTimeElapsed.Hours,
                                      gameTimeElapsed.Minutes, gameTimeElapsed.Seconds, 0);
            score.Moves = game.PlayerMoves;


            //TODO: move this to XAML
            GameOver gameOver = new GameOver(score);

            // Main page is divided into 2x3 grid. Make sure the row and column
            // properties are set properly (position 0,0 with span 2,3) to make
            // the dialog visible anywhere on the page.
            gameOver.SetValue(Grid.RowSpanProperty, 3);
            gameOver.SetValue(Grid.ColumnSpanProperty, 2);
            gameOver.SetValue(Grid.VerticalAlignmentProperty, VerticalAlignment.Center);
            gameOver.SetValue(Grid.HorizontalAlignmentProperty, HorizontalAlignment.Center);
            gameOver.SetValue(MarginProperty, new Thickness(10, 0, 0, 0));

            LayoutRoot.Children.Add(gameOver);
            gameState = GameState.GameOver;

            SoundHelper.PlaySound(SoundHelper.SoundType.GameEndSound);
        }
        /// <summary>
        /// Checks if given score is a new highscore
        /// </summary>
        /// <param name="score">Score to check. The score should contain at least the solving time and moves.</param>
        /// <returns>The position in highscore list, or zero if the score doesn't make it to the list</returns>
        static public int IsNewHighscore(HighscoreItem score)
        {
            foreach (HighscoreItem item in scores)
            {
                // Check the time, and if the times are the same, check the
                // moves needed to solve the puzzle
                if (score.Time < item.Time ||
                    (score.Time == item.Time && score.Moves < item.Moves))
                    return item.Index;
            }

            return 0;
        }
 /// <summary>
 /// Add a new score to highscore list
 /// </summary>
 /// <param name="score">Score to add. All members of the score should be filled.</param>
 static public void AddNewHighscore(HighscoreItem score)
 {
     // Insert the score into the list, remove weakest score from the list
     // and save the list.
     if (score.Index <= 0)
         return;
     scores.Insert(score.Index - 1, score);
     scores.RemoveAt(scores.Count - 1);
     for (int t = score.Index; t < scores.Count; t++)
         scores[t].Index++;
     Save();
 }    
Exemplo n.º 8
0
        /// <summary>
        /// Ends current game. Called when all the cells are filled.
        /// </summary>
        private void GameEnds()
        {
            gameTimer.Stop();

            // Blink all cells and prevent the player from modifying the cells
            for (int row = 0; row < GameLogic.RowLength; row++)
            {
                for (int col = 0; col < GameLogic.ColumnLength; col++)
                {
					game.Model.BoardNumbers[row][col].SetByGame = true; // to block the user input
                    cells[row][col].Blink();
                }
            }

            // Display the score with GameOver dialog
            HighscoreItem score = new HighscoreItem();
            score.Time = new TimeSpan(gameTimeElapsed.Days, gameTimeElapsed.Hours,
                gameTimeElapsed.Minutes, gameTimeElapsed.Seconds, 0);
            score.Moves = game.PlayerMoves;


			//TODO: move this to XAML
            GameOver gameOver = new GameOver(score);
            // Main page is divided into 2x3 grid. Make sure the row and column
            // properties are set properly (position 0,0 with span 2,3) to make
            // the dialog visible anywhere on the page.
            gameOver.SetValue(Grid.RowSpanProperty, 3);
            gameOver.SetValue(Grid.ColumnSpanProperty, 2);
            gameOver.SetValue(Grid.VerticalAlignmentProperty, VerticalAlignment.Center);
            gameOver.SetValue(Grid.HorizontalAlignmentProperty, HorizontalAlignment.Center);
            gameOver.SetValue(MarginProperty, new Thickness(10, 0, 0, 0));

            LayoutRoot.Children.Add(gameOver);
            gameState = GameState.GameOver;

			SoundHelper.PlaySound(SoundHelper.SoundType.GameEndSound);
        }