Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would I go about implementing a stopwatch with different speeds?

Ideally I would like to have something similar to the Stopwatch class but with an extra property called Speed which would determine how quickly the timer changes minutes. I am not quite sure how I would go about implementing this.

Edit

Since people don't quite seem to understand why I want to do this. Consider playing a soccer game, or any sport game. The halfs are measured in minutes, but the time-frame in which the game is played is significantly lower i.e. a 45 minute half is played in about 2.5 minutes.

like image 342
James Avatar asked Dec 29 '22 16:12

James


2 Answers

Subclass it, call through to the superclass methods to do their usual work, but multiply all the return values by Speed as appropriate.

like image 85
Andrew McGregor Avatar answered Feb 01 '23 23:02

Andrew McGregor


I would use the Stopwatch as it is, then just multiply the result, for example:

var Speed = 1.2; //Time progresses 20% faster in this example
var s = new Stopwatch();
s.Start();
  //do things
s.Stop();
var parallelUniverseMilliseconds = s.ElapsedMilliseconds * Speed;
like image 36
Nick Craver Avatar answered Feb 01 '23 22:02

Nick Craver