示例#1
0
文件: Game.cs 项目: Agrael11/Snake
 public void Init()
 {
     if (!Directory.Exists("Levels")) Directory.CreateDirectory("Levels");
     if (!Directory.Exists("Saves")) Directory.CreateDirectory("Saves");
     if (!File.Exists("Saves\\Highscores_MP.xml"))
     {
         var scores = new Highscores();
         FileController.Save(scores, "Saves\\Highscores_MP.xml");
     }
     if (!File.Exists("Saves\\Highscores_SP.xml"))
     {
         var scores = new Highscores();
         FileController.Save(scores, "Saves\\Highscores_SP.xml");
     }
     Pause = new PauseScene(this);
     MainMenu = new MainMenuScene(this);
     InGame = new GameScene(this);
     Question = new ExitQuestion(this);
     SaveQuestion = new SaveSelectScene(this);
     LoadQuestion = new LoadSelectScene(this);
     HighscoreScn = new HighscoresScene(this);
 }
示例#2
0
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            OleDbConnection conn = new OleDbConnection();

            //conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=scores.accdb";
            conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=H:\\Documents\\scores.accdb";

            if (string.IsNullOrWhiteSpace(tbName.Text))
            {
                errorProvider1.SetError(tbName, "Can't leave this empty.");
            }
            else
            {
                name = tbName.Text;
            }


            if (dif1 == true)
            {
                mode = "Easy";
            }
            else if (dif2 == true)
            {
                mode = "Medium";
            }
            else if (dif3 == true)
            {
                mode = "Hard";
            }
            else if (dif4 == true)
            {
                mode = "Nightmare";
            }


            OleDbCommand cmd = new OleDbCommand("INSERT into scores (Naam, Highscore, Moeilijkheid) Values(@name, @score, @mode)");

            cmd.Connection = conn;

            conn.Open();

            if (conn.State == ConnectionState.Open)
            {
                cmd.Parameters.Add("@name", OleDbType.VarChar).Value  = name;
                cmd.Parameters.Add("@score", OleDbType.VarChar).Value = score;
                cmd.Parameters.Add("@mode", OleDbType.VarChar).Value  = mode;

                try
                {
                    cmd.ExecuteNonQuery();
                    MessageBox.Show("Data Added");
                    conn.Close();
                }
                catch (OleDbException ex)
                {
                    MessageBox.Show(ex.Source);
                    conn.Close();
                }
            }
            else
            {
                MessageBox.Show("Connection Failed");
            }
            Highscores highscores = new Highscores();

            highscores.Show();
            this.Close();
        }