public void OnKeyDownHandler(object sender, KeyEventArgs e) { if (e.Key == Key.R) { World.Reset(); return; } if (e.Key == Key.Space && World.GameLost == false) { if (World.GamePaused == false) { World.GamePaused = true; World.Timer.Stop(); MESSAGE.Text = "Game paused\n Press space to continue"; MESSAGE.FontSize = 20; MESSAGE.Visibility = Visibility.Visible; } else { World.GamePaused = false; World.Timer.Start(); MESSAGE.Visibility = Visibility.Hidden; } return; } if (World.ActiveObject == null) { return; } if (World.GamePaused == false && World.GameLost == false) { if (e.Key == Key.Left) { World.ActiveObject.MoveLeft(); } else if (e.Key == Key.Right) { World.ActiveObject.MoveRight(); } else if (e.Key == Key.Down) { bool GameLost; World.ActiveObject.MoveDown(out GameLost); } else if (e.Key == Key.Up) { World.ActiveObject.Rotate(); } World.Visualize(); } }
public MainWindow() { InitializeComponent(); World.nCols = 14; World.nRows = 30; this.Height = World.nRows * World.CELL_SIZE; this.Width = World.nCols * World.CELL_SIZE; World.Init(this); World.InitWindowGrid(); World.Visualize(); }