I am creating my own game - packman. I am using C# console. I have got all function expect ghost moving. Now they change position when I press button. I would like to change their position after 0.5 sec. I try some functions like this: How to implement setInterval(js) in C# but it doesn t work. Have you got any idea to move ghost after 0.5 secs? Thanks a lot.
Asked
Active
Viewed 66 times
1 Answers
1
Timer timer = new Timer();
timer.Tick += new EventHandler(MoveGhost);
timer.Interval = 500; // 0.5 sec
timer.Start();
Place it in the main function. This should do it.

P_Andre
- 730
- 6
- 17
-
Ok that's great idea. But how can I refresh console? My map is printing when I press any button. Do you have an idea to resolve that problem? – Oct 23 '17 at 12:52
-
Just create a function that calls Console.Clear() and then draws the gaming board. Then you can just throw this function into a new timer. Otherwise if you have a while loop, you can just call Console.Clear() and DrawGame every single iteration of the loop – P_Andre Oct 23 '17 at 12:57