示例#1
0
 /// <summary>
 /// Opens a load level dialog.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void LoadLevelToolStripMenuItem_Click(object sender, EventArgs e)
 {
     model.Pause(true);
     if (openFileDialog.ShowDialog() == DialogResult.OK)
     {
         try {
             model.LoadLevel(openFileDialog.FileName);
         } catch (DataException) {
             MessageBox.Show("An error occured while loading the level", "Snake", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
示例#2
0
        /// <summary>
        /// Opens a dialog box to load a level.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ViewModel_LoadLevel(object sender, EventArgs e)
        {
            model.Pause(true);

            if (openFileDialog == null)
            {
                openFileDialog        = new OpenFileDialog();
                openFileDialog.Title  = "Snake - Level Loading";
                openFileDialog.Filter = "Text files|*.txt";
            }

            if (openFileDialog.ShowDialog() == true)
            {
                try {
                    model.LoadLevel(openFileDialog.FileName);
                } catch (DataException) {
                    MessageBox.Show("An error occured while loading the level", "Snake", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
示例#3
0
 public void SnakeLoadLevelTest()
 {
     //load the level
     model.LoadLevel(string.Empty);
     //check the map size
     Assert.AreEqual(model.MapSize, 7);
     //check if there is a wall in the correct place
     Assert.AreEqual(model[0, 0], TileType.Wall);
     //check if the snake is in place
     for (int i = 1; i <= 5; i++)
     {
         Assert.AreEqual(model[3, i], TileType.Snake);
     }
     //check if the snake is oriented right
     Assert.AreEqual(model.Direction, Direction.Right);
     //check if the timer is running
     Assert.AreEqual(model.Paused, false);
     //check if the score is right
     Assert.AreEqual(model.Score, 0);
     //check if load was called
     mock.Verify(mock => mock.LoadLevel(string.Empty), Times.Once());
 }