Ejemplo n.º 1
0
        private void mnuFileLoad_Click(object sender, EventArgs e)
        {
            this.gameTimer.IsEnabled = false;
            MessageBoxResult res = MessageBox.Show("You will lose all progress on your current game.\nIs that ok?", "Load previous game", MessageBoxButton.YesNo);

            if (res == MessageBoxResult.Yes)
            {
                fallingPattern = null;
                patterns.Clear();
                initializeBoard();
                myGameCanvas.Children.Clear();
                Stream sr;
                var    folderBrowserDialog = new System.Windows.Forms.OpenFileDialog();
                System.Windows.Forms.DialogResult result = folderBrowserDialog.ShowDialog();
                if (result == System.Windows.Forms.DialogResult.OK)
                {
                    sr = folderBrowserDialog.OpenFile();
                    List <int> board = new List <int>();
                    try
                    {
                        using (StreamReader stream = new StreamReader(sr))
                        {
                            string txt = "";
                            this.playerName = stream.ReadLine();
                            string boolean = stream.ReadLine();
                            if (boolean.Equals("True"))
                            {
                                this.classic = true;
                            }
                            else
                            {
                                this.classic = false;
                            }
                            this.curScore           = Int32.Parse(stream.ReadLine());
                            this.score.Content      = "" + curScore;
                            this.totalCompletedRows = Int32.Parse(stream.ReadLine());
                            while ((txt = stream.ReadLine()) != null)
                            {
                                if (!txt.Equals(""))
                                {
                                    board.Add(Int32.Parse(txt));
                                }
                            }
                        }
                        int    count = 0;
                        string str   = "";
                        for (int x = 0; x < 18; x++)
                        {
                            for (int y = 0; y < 10; y++)
                            {
                                gameBoard[x, y] = board[count];
                                str            += board[count] + " ";
                                count++;
                            }
                            str += "\n";
                        }
                        Pattern patt;
                        Boolean Empty = false;
                        for (int a = 17; a > -1; a--)
                        {
                            if (!Empty)
                            {
                                Empty = true;
                                for (int b = 0; b < 10; b++)
                                {
                                    if (gameBoard[a, b] != 0 && CanCreate(gameBoard[a, b]))
                                    {
                                        Empty = false;
                                        patt  = new Pattern(this, gameBoard[a, b], false);
                                        patterns.Add(patt);
                                    }
                                    if (gameBoard[a, b] != 0)
                                    {
                                        Empty = false;
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception err)
                    {
                        MessageBox.Show("Unable to Load File.");
                    }
                }
                initializeBoard();
                foreach (Pattern item in patterns)
                {
                    item.paintPattern();
                }
                this.gameTimer.IsEnabled = true;
                SpawnFirst();
            }
            else
            {
                this.gameTimer.IsEnabled = true;
            }
        }