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 8963545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:22:55+00:00 2026-06-15T16:22:55+00:00

I have a Game in which there is a timer involved. For each two

  • 0

I have a Game in which there is a timer involved. For each two minutes that passes a new round between different players begins. So, I have a text box starting from 00:00 and changes each second until it is equal to 02:00.

Now, I want to save the state of the game in the middle of a round if the user closes the form. What I need to do is that upon loading, the textbox starts at the time that the user left the game the last time and continue up till 02:00 normally.

How can I do this?

This is what I have until now where Tournament is the Form

public Tournament()
{
     _timer = new System.Windows.Forms.Timer();
     _timer.Interval = 1000;
     _timer.Tick += Timer_Tick;
     _myDateTime = DateTime.Now;
     newDate = new DateTime();
     newDate = newDate.AddMinutes(2.00);
     _timer.Start();
     InitializeComponent();
}

void Timer_Tick(object sender, EventArgs e)
{
     var diff = DateTime.Now.Subtract(_myDateTime);
     this.textBox1.Text = diff.ToString(@"mm\:ss");

     DateTime dt = Convert.ToDateTime(diff.ToString());

     if (newDate.Minute == dt.Minute)
     {
         _timer.Stop();
         _myDateTime = DateTime.Now;

         displayPointsOrResults();

         this.textBox1.Text = diff.ToString(@"mm\:ss");  
     }
   }

In my LoadGame method: where timePassed is what I have written in the text box

  string[] splitted6 = timePassed.Split(':');

  if (splitted6[0] == "00")
  {
      int remainingTime = 120 - Convert.ToInt32(splitted6[1]);

      DateTime time = DateTime.Now.Date; 
      time = time.AddMinutes(remainingTime);

      _myDateTime = time;
  }
  else
  {
      int leftTime = Convert.ToInt32(splitted[0].Trim('0') + splitted[1]);
      int remainingTime = 120 - leftTime;

      DateTime time = DateTime.Now.Date; 
      time = time.AddMinutes(remainingTime);

      _myDateTime = time;
  } 
  • 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-06-15T16:22:56+00:00Added an answer on June 15, 2026 at 4:22 pm

    Use TimeSpan instead of DateTime to save and load current timeout:

    int _roundDuration = 2 * 60; // 2 minutes
    
    void Timer_Tick(object sender, EventArgs e)
    {
         TimeSpan diff = DateTime.Now - _myDateTime;
         textBox1.Text = diff.ToString(@"mm\:ss");
         if (diff.TotalSeconds >= _roundDuration)
         {
              _timer.Stop();    
              _myDateTime = DateTime.Now;
              displayPointsOrResults();
         }
    }
    

    When loading game (parsing textBox1.Text):

    TimeSpan diff = TimeSpan.ParseExact(textBox1.Text, @"mm\:ss", null);
    _myDateTime = DateTime.Now.Substract(diff);
    

    Whenever you load game, start time will be calculated as it was started displayed timeout ago.

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

Sidebar

Related Questions

I have a database that has two tables, one of which contains a foreign
I have a lighting system in my xna game that loops through each light,
I have a type game in which you have to type the words that
I have made a game which is nearly identical to Popcap's Atomica. ( http://www.popcap.com/gamepopup.php?theGame=atomica
I have an animated game which is generally achieving 25-30 frames per second, though
I have an game app which occasionally plays sounds. When the phone goes into
I have a game app which is mostly working fine. If a phone call
I have an iPhone game which I am porting to PC. The game uses
Imagine you have a PlayN game which uses Guice bindings in its core project:
I have a Game Window to which I am trying to put W ,

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.