Exemplo n.º 1
0
        // play the game step by step...
        public void playBTB(Cell c)
        {
            try
            {
                //revealBlankCell(colInt, rowInt); // reveal the cell, and any relevant neighbors
                bool lost = checkForLose(); // check if the cell is a bomb
                bool won  = checkForWin();  // check if that's the last inactive cell

                if (lost == true)           // if it was a bomb...
                {
                    s.Stop();
                    revealGrid();
                    MessageBox.Show("We're sorry. You failed.\nTime elapsed: " + s.ElapsedMilliseconds / 1000 + " seconds.");

                    HighScoreForm hsf = new HighScoreForm(GridSize, null);
                    hsf.Show();
                }
                else if (won == true) // if all inactives are visited...
                {
                    s.Stop();
                    revealGrid();
                    MessageBox.Show("Congratulations! You won!\nTime elapsed: " + s.ElapsedMilliseconds / 1000 + " seconds.");

                    PlayerScores ps = new PlayerScores();
                    ps.setPlayerName(playerName);

                    if (GridSize == 5)
                    {
                        ps.setDifficultyPlayed("Easy");
                    }
                    else if (GridSize == 10)
                    {
                        ps.setDifficultyPlayed("Medium");
                    }
                    else
                    {
                        ps.setDifficultyPlayed("Hard");
                    }

                    ps.setTimeElapsed((int)s.ElapsedMilliseconds / 1000);

                    MessageBox.Show(ps.getPlayerName() + "\n" + ps.getDifficultyPlayed() + "\n" + ps.getTimeElapsed());


                    HighScoreForm hsf = new HighScoreForm(GridSize, ps);


                    hsf.Show();
                }
                else // if the game hasn't ended yet, update the grid and ask again.
                {
                    showPlayerGrid();
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
Exemplo n.º 2
0
        // load data when called -- path PlayerScores.txt
        public void  loadData()
        {
            if (File.Exists("PlayerScores.txt"))
            {
                StreamReader sr = new StreamReader("PlayerScores.txt");


                PlayerScores ps = new PlayerScores();

                string str;
                while (!sr.EndOfStream)
                {
                    try
                    {
                        str = sr.ReadLine();
                        ps.setPlayerName(str);

                        str = sr.ReadLine();
                        ps.setDifficultyPlayed(str);

                        str = sr.ReadLine();
                        int time = int.Parse(str);
                        ps.setTimeElapsed(time);

                        Scores.Add(ps);

                        ps = new PlayerScores();
                    }
                    catch
                    {
                        MessageBox.Show("We have a problem with loadData.");
                    }
                }
                sr.Close();
            }
            else
            {
                //just create the file
                using (StreamWriter sw = new StreamWriter(@"PlayerScores.txt", true))
                {
                }
            }
        }