// Specify what you want to happen when the event is raised. private void FlipDisplay(object source, System.Timers.ElapsedEventArgs e) { // Draw the next screen screenCanvas.Clear(); switch (gameStatus) { case Modes.TITLE: TitleScreen(currTitle); break; case Modes.GAME: if (!PlayGame(currGame)) { currTitle = new TitleScreen(); currTitle.InitTitleScreen(); } break; } // Flip the screen to show the updated image bLastDrawn = false; frames[iShowFrame].BringToFront(); frames[iShowFrame].Visible = true; iShowFrame = 1 - iShowFrame; frames[iShowFrame].Visible = false; // Set another timer... if (gameStatus != Modes.EXIT) { SetFlipTimer(); } }
// Specify what you want to happen when the event is raised. private void FlipDisplay(object source, ElapsedEventArgs e) { // Draw the next screen screenCanvas.Clear(); switch (gameStatus) { case Modes.TITLE: TitleScreen(currTitle); break; case Modes.GAME: if (!PlayGame(currGame)) { currTitle = new TitleScreen(); currTitle.InitTitleScreen(); } break; } // Flip the screen to show the updated image bLastDrawn = false; PictureBox frame = this.frames[iShowFrame]; if (frame.InvokeRequired) { frame.Invoke(new MethodInvoker(delegate { frame.BringToFront(); frame.Visible = true; iShowFrame = 1 - iShowFrame; frames[iShowFrame].Visible = false; })); } else { frame.BringToFront(); frame.Visible = true; iShowFrame = 1 - iShowFrame; frames[iShowFrame].Visible = false; } // Set another timer... if (gameStatus != Modes.EXIT) { SetFlipTimer(); } }
private void frmAsteroids_Activated(object sender, EventArgs e) { if (gameStatus == Modes.PREP) { screenCanvas = new ScreenCanvas(); score = new Score(); gameStatus = Modes.TITLE; currTitle = new TitleScreen(); currTitle.InitTitleScreen(); // Timers for flipping display and playing sounds SetFlipTimer(); SetSoundsTimer(); // Handle the game do { Application.DoEvents(); Thread.Sleep(0); } while (gameStatus != Modes.EXIT); } }