public event EventHandler LoadLevel; //Event for loading a new level. #endregion #region Constructors /// <summary> /// SnakeViewModel constructor /// </summary> /// <param name="model"></param> public SnakeViewModel(SnakeModel model) { //Set the model. this.model = model; //Subscribe to the events of the model. model.MapChanged += new EventHandler <MapChangedEventArgs>(Model_MapChanged); model.TileChanged += new EventHandler <TileChangedEventArgs>(Model_TileChanged); //Define the commands. UpCommand = new DelegateCommand(param => model.Direction = Direction.Up); DownCommand = new DelegateCommand(param => model.Direction = Direction.Down); LeftCommand = new DelegateCommand(param => model.Direction = Direction.Left); RightCommand = new DelegateCommand(param => model.Direction = Direction.Right); ExitCommand = new DelegateCommand(param => OnExit()); RestartCommand = new DelegateCommand(param => model.RestartLevel()); PauseCommand = new DelegateCommand(param => OnPause()); LoadCommand = new DelegateCommand(param => OnLoad()); //Initialize the fields collection. Fields = new ObservableCollection <ViewField>(); }
public void SnakeRestartLevelTest() { model.LoadLevel(string.Empty); //restart the level model.RestartLevel(); //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); }
/// <summary> /// Event handler for game over. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Model_GameOver(object sender, GameOverEventArgs e) { MessageBox.Show("Score: " + e.Score, "Game Over", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); model.RestartLevel(); }