Click here to Skip to main content
15,893,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i was task to make a game then my problem is that i have to make a time limitation for it but the code i used didn't works...please somebody help me
tnx
Posted
Comments
Per Söderlund 6-Sep-10 5:29am    
Sure, we can help you.But you have to post your code.
Solving your problem like this is impossible, we don't know what game or what the timer is trying to do.
Sandeep Mewara 6-Sep-10 5:50am    
Use 'Improve Question' link and update the question with code.
Toli Cuturicu 6-Sep-10 6:09am    
So, you was a task? And now you are a human. Nice.

Make sure you have enabled the timer after setting the interval correctly.
 
Share this answer
 
Like stated above it's hard to figure out what you need...

A very simple timer demo would look something like this:

class Program
    {
        static void Main(string[] args)
        {
            Demo demo = new Demo();
            demo.Run();
        }
    }

    class Demo
    {
        private Timer _timer;
        private int _iteration;
        private bool _gameOver;

        public void Run()
        {
            _gameOver = false;
            _iteration = 1;
            //init Timer (System.Timers.Timer)
            _timer = new Timer();
            _timer.Interval = 10000;
            _timer.Elapsed += new ElapsedEventHandler(_timer_Elapsed);
            _timer.Start();
            
            while (!_gameOver)
            {
                //game logic
                Console.WriteLine("Game Loop No." + _iteration.ToString());

                System.Threading.Thread.Sleep(500);
                _iteration++;
            }

            Console.WriteLine("Game over (timeout hit)");
            Console.ReadKey();
        }

        void _timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            //timout hit
            _gameOver = true;
        }
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900