Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6150835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:40:41+00:00 2026-05-23T19:40:41+00:00

I have a maze game. After you press Enter, you can enter a cheat

  • 0

I have a maze game. After you press Enter, you can enter a cheat code, also, the timer will pause. But after entering the code, my timer resumes but it decrements 3x each second. Here’s the condition for pressing Enter:

// gt.setTimer() is called at the moment the maze started
// I'm using getch to trap inputs

else if (move == 13) //Reads if Enter is pressed
            {
                pause = 1; //A Flag saying that the timer must be paused
                gt.setTimer(pause); //Calls my setTimer() method
                Console.Write("Enter Cheat: "); 
                cheat = Console.ReadLine();
                pause = 0; //A Flag saying that the timer should resume
                gt.setTimer(lives, pause); //Calls again the Timer
            }

Here’s my setTimer() code:

static System.Timers.Timer t = new System.Timers.Timer();
static int gTime = 300;

public void setTimer(int pause)
    {
        t.Interval = 1000; // Writes the time after every 1 sec
        if (pause == 1)
            t.Stop(); // Stop the timer if you press Enter
        else 
            t.Start(); // Starts the timer if not
        t.Elapsed += new ElapsedEventHandler(showTimer);                       
    }

    public static void showTimer(object source, ElapsedEventArgs e)
    {
        Console.Write("Time   " + gTime); //Writes time
        gTime--; //Decrements the time
    }

Is there something wrong? Am i missing something?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T19:40:42+00:00Added an answer on May 23, 2026 at 7:40 pm

    Every time when you do:
    t.Elapsed += new ElapsedEventHandler(showTimer);
    you add one more event handler to this event

    This strind runing only once, in par code where you initialise timer

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What I am doing is very simple. I have a simple 2d Maze game
I have a maze game and I'm trying to create two Timers at a
Have an app that can use tts to read text messages. It can also
How would you write this code? This particular question is about a maze game
I have the following code in C, Its basically a maze where S=starting point
i have to implement a small and simple game in c++ (a maze) and
Have you guys had any experiences (positive or negative) by placing your source code/solution
Have a n-tire web application and search often times out after 30 secs. How
I'm trying to write a simple maze game, without using any deprecated OpenGL API
A have a maze and character that's controlled by the player and a drone

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.