public void StartGame() { // Display our user control with the flashing message. Point point = new Point(); point.X = (gameControl.FormSizeX / 2) - 140; point.Y = (gameControl.FormSizeY / 2) - 100; startGraphics = new StartGraphics() { Location = point }; Controls.Add(startGraphics); // *** Form1_KeyDown will start the game timer. // Get any previous high score. string HSfile = AppDomain.CurrentDomain.BaseDirectory; HSfile = HSfile.Replace(@"Asteroids\bin\Debug", ""); HSfile += "HighScore.txt"; int highScore = 0; try { using (StreamReader reader = new StreamReader(HSfile)) { string highScoreString = reader.ReadLine(); highScore = int.Parse(highScoreString); reader.Close(); } } catch { // No file yet. } form2.highScoreLabel.Text = "High Score: " + highScore; // Some atmospheric sound. soundPlayerStart.Play(); }
private void Form1_KeyDown(object sender, KeyEventArgs e) { // *** Needed to set KeyPreview = true to get keys at forlevel. // MessageBox.Show("Key pressed = " + e.KeyData); if (startGame == false) { // *** Lets start the game. *** startGame = true; // Remove the user control. using (startGraphics) { Controls.Remove(startGraphics); } startGraphics = null; // Start the timer this.gameTimer.Enabled = true; } if (e.Modifiers == Keys.Control) // || e.KeyData == Keys.Z) // Thrust up. { gameControl.ship.Thruster(true); } if (e.KeyData == Keys.X || e.KeyData == Keys.Z) { // Brake gameControl.ship.Thruster(false); } if (e.KeyData == Keys.Space) { gameControl.ship.Shoot(); gameControl.soundPlayerLaseR.Play(); SpaceBarDown = true; } // Refresh(); }