Exemple #1
0
        /// <summary>
        /// CheckGameOver function.
        /// </summary>
        /// <param name="grid">2D array of tiles.</param>
        /// <returns>true or false depends on the game is over or not.</returns>
        public bool CheckGameOver(Tile[,] grid)
        {
            List <Tile> emptyTiles = this.ListOfEmptyTiles(grid);

            if (emptyTiles.Count == 0)
            {
                bool left  = this.MoveLeft(grid);
                bool right = this.MoveRight(grid);
                bool up    = this.MoveUp(grid);
                bool down  = this.MoveDown(grid);
                if (left == false && right == false && up == false && down == false)
                {
                    Application current = Application.Current;
                    foreach (Window win in current.Windows)
                    {
                        if (win.GetType() == typeof(MainWindow))
                        {
                            (win as MainWindow).GameControlElement.Stopwatch.Stop();
                        }
                    }

                    GameOverEventArgs args = new GameOverEventArgs();
                    args.FinalScore = this.model.CurrentScore;
                    args.FinalTime  = new TimeSpan(this.model.Hours, this.model.Minutes, this.model.Seconds);
                    this.OnGameOver(args);
                    return(true);
                }

                return(false);
            }

            return(false);
        }
Exemple #2
0
        /// <summary>
        /// GameLogic_GameOver function.
        /// </summary>
        /// <param name="sender">sender object.</param>
        /// <param name="e">GameOverEventArgs event arguments.</param>
        private void GameLogic_GameOver(object sender, GameOverEventArgs e)
        {
            GameOverWindow window = new GameOverWindow();

            window.Owner = Application.Current.MainWindow;
            if (window.ShowDialog() == true)
            {
                ScoreboardItemLogic logic    = ScoreboardItemLogic.CreateRealLogic();
                scoreboard_items    newScore = new scoreboard_items();
                newScore.sbItem_id         = logic.GetAll().Count() + 1;
                newScore.sbItem_playerName = window.PlayerName.Text;
                newScore.sbItem_score      = e.FinalScore;
                newScore.sbItem_time       = e.FinalTime;
                try
                {
                    logic.Insert(newScore);
                }
                catch (ArgumentNullException)
                {
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// OnGameOver event.
        /// </summary>
        /// <param name="e">GameOverEventArgs event arguments.</param>
        protected virtual void OnGameOver(GameOverEventArgs e)
        {
            EventHandler <GameOverEventArgs> handler = this.GameOver;

            this.GameOver?.Invoke(this, e);
        }