public MainWindow() { InitializeComponent(); GameController controller = new GameController(); mainWindow.KeyDown += controller.keyDownEvent; mainWindow.KeyUp += controller.keyUpEvent; game = new Game( mainGrid.ColumnDefinitions[1].Width.Value, 761, controller, endGameHandler); game.setScoreLabel(Score_Content_Label); game.setLiveLabel(Live_Content_Label); GameCanvas gameCanvas = game.getGameCanvas(); Grid.SetColumn(gameCanvas, 1); mainGrid.Children.Add(gameCanvas); NewGameButton.Click += StartNewGame; TryAgainButton.Click += StartNewGame; }
public Game(double width, double height, GameController controller, Action <int, bool> endGameCallback) { isRunning = false; liveLabel = null; scoreLabel = null; this.controller = controller; this.endGameCallback = endGameCallback; GameBorder border = new GameBorder(new Point(width, height), new Point(0, 0)); level = new GameLevel(); gameState = new GameState(border); gameCanvas = new GameCanvas(draw); gameCanvas.setSize(width, height); }
private void StartGame() { GameCanvas.Focus(); score = 0; gameOver = false; Canvas.SetTop(Ball, 190); Block obstacle; for (int i = 0; i < 10; i++) { obstacle = new Block(); GameCanvas.Children.Add(obstacle.blockImage); obstacle.SetPos(50 + 50 * i, 10); } for (int i = 0; i < 5; i++) { obstacle = new Block(); GameCanvas.Children.Add(obstacle.blockImage); obstacle.SetPos(75 + 100 * i, 110); } for (int i = 0; i < 10; i++) { obstacle = new Block(); GameCanvas.Children.Add(obstacle.blockImage); obstacle.SetPos(50 + 50 * i, 220); } for (int i = 0; i < 10; i++) { obstacle = new Block(); GameCanvas.Children.Add(obstacle.blockImage); obstacle.SetPos(50 + 50 * i, 330); } gameTimer.Start(); }
public GameController() { _gameCanvasPanel = new GameCanvas(); }