//event handler for a second elapsing void timer_Tick(object sender, ElapsedEventArgs e) { //if time has run out if (tempTime <= 0) { tempTime = -1; CountdownLbl.Invoke(new Action(() => CountdownLbl.Hide())); timeCounter--; } else { //reduces time tempTime--; CountdownLbl.Invoke(new Action(() => CountdownLbl.Text = Convert.ToString(tempTime))); } if (timeCounter > 0) { // displays the time lable timeLbl.Invoke(new Action(() => timeLbl.Text = "Time: " + Convert.ToString(timeCounter))); } else { // displays time up timeLbl.Invoke(new Action(() => timeLbl.Text = "Times up!")); } //end game if (timeCounter == 0) { // System.Windows.Forms.MessageBox.Show("GAME OVER\nyou scored: " + Convert.ToString(score)); aTimer.Stop(); timeCounter = -1; ticking = false; btnClickTimeTrial(btn[1, 1], e); } //hides label if (timeCounter <= prevTime) { plus2Lbl.Invoke(new Action(() => plus2Lbl.Hide())); } // starts countdown sound if (timeCounter == 10) { System.Media.SoundPlayer player = new System.Media.SoundPlayer(@"timer.wav"); player.Play(); } }
//shows the main menu void showMenu() { ClassicBtn.Invoke(new Action(() => ClassicBtn.Show())); ExitBtn.Invoke(new Action(() => ExitBtn.Show())); HelpBtn.Invoke(new Action(() => HelpBtn.Show())); multiplayerBtn.Invoke(new Action(() => multiplayerBtn.Show())); TimeBtn.Invoke(new Action(() => TimeBtn.Show())); menuBack.Invoke(new Action(() => menuBack.Show())); HomeTLbl.Invoke(new Action(() => HomeTLbl.Show())); boardHomeBtn.Invoke(new Action(() => boardHomeBtn.Hide())); CountdownLbl.Invoke(new Action(() => CountdownLbl.Hide())); TitleLbl.Invoke(new Action(() => TitleLbl.Hide())); if (gameMode == 2) { P1ScoreLbl.Invoke(new Action(() => P1ScoreLbl.Hide())); P2ScoreLbl.Invoke(new Action(() => P2ScoreLbl.Hide())); turnLbl.Invoke(new Action(() => turnLbl.Hide())); } }
//initialises time trial game void timeTrialInit() { // sets up initial timer tempTime = 3; // sets up inital values score = 0; gameMode = 1; multiplier = 1; //sets up menu multiLbl.Invoke(new Action(() => multiLbl.Hide())); done = false; reshuffle(); tempTime = 3; CountdownLbl.Invoke(new Action(() => CountdownLbl.Show())); P1ScoreLbl.Invoke(new Action(() => P1ScoreLbl.Hide())); P2ScoreLbl.Invoke(new Action(() => P2ScoreLbl.Hide())); Console.WriteLine(tempTime); // starts the timer timeCounter = 60; if (ticking) { aTimer.Stop(); } ticking = true; aTimer = new System.Timers.Timer(1000); // Hook up the Elapsed event for the timer. aTimer.Elapsed += timer_Tick; aTimer.AutoReset = true; aTimer.Enabled = true; timeLbl.Invoke(new Action(() => timeLbl.Show())); scoreLabel.Invoke(new Action(() => scoreLabel.Show())); scoreLabel.Text = "Score: " + score; }