public void YogiBearModelStepsTest() { model.Map = data.LoadFirstLevel(level1); Assert.AreEqual(model.PlayerPos.X, 0); Assert.AreEqual(model.PlayerPos.Y, 0); model.Down(); Assert.AreEqual(model.PlayerPos.X, 1); model.Up(); Assert.AreEqual(model.PlayerPos.X, 0); model.Right(); Assert.AreEqual(model.PlayerPos.Y, 1); model.Left(); Assert.AreEqual(model.PlayerPos.X, 0); }
//Billentyű lenyomás eseménykezelője private void GameForm_KeyDown(object sender, KeyEventArgs e) { //ha nincs szünet, és tart a játék... if (!paused && !gameover) { switch (e.KeyCode) // megkapjuk a billentyűt { case Keys.W: //fel if (model.IsFloor(model.PlayerPos.X - 1, model.PlayerPos.Y)) { label_grid[model.PlayerPos.X, model.PlayerPos.Y].Image = imgs[0]; label_grid[model.PlayerPos.X - 1, model.PlayerPos.Y].Image = imgs[3]; model.Up(); } break; case Keys.A: //balra if (model.IsFloor(model.PlayerPos.X, model.PlayerPos.Y - 1)) { label_grid[model.PlayerPos.X, model.PlayerPos.Y].Image = imgs[0]; label_grid[model.PlayerPos.X, model.PlayerPos.Y - 1].Image = imgs[3]; model.Left(); } break; case Keys.S: //le if (model.IsFloor(model.PlayerPos.X + 1, model.PlayerPos.Y)) { label_grid[model.PlayerPos.X, model.PlayerPos.Y].Image = imgs[0]; label_grid[model.PlayerPos.X + 1, model.PlayerPos.Y].Image = imgs[3]; model.Down(); } break; case Keys.D: //jobbra if (model.IsFloor(model.PlayerPos.X, model.PlayerPos.Y + 1)) { label_grid[model.PlayerPos.X, model.PlayerPos.Y].Image = imgs[0]; label_grid[model.PlayerPos.X, model.PlayerPos.Y + 1].Image = imgs[3]; model.Right(); } break; default: break; } } }
private void MoveBear(Int32 direction) { if (!paused) { switch (direction) { case 1: if (model.IsFloor(model.PlayerPos.X - 1, model.PlayerPos.Y)) { model.Up(); } break; case 3: if (model.IsFloor(model.PlayerPos.X + 1, model.PlayerPos.Y)) { model.Down(); } break; case 4: if (model.IsFloor(model.PlayerPos.X, model.PlayerPos.Y + 1)) { model.Right(); } break; case 2: if (model.IsFloor(model.PlayerPos.X, model.PlayerPos.Y - 1)) { model.Left(); } break; default: break; } } RefreshGameFields(); OnPropertyChanged("Fields"); }