I want to perform a discrete-event simulation in C#. I want three balls rolling on the screen simultaneously following a random walk pattern. At time 1 ball one should appear and start rolling, at time 5, ball 2 and at time 10, ball 3 should appear. When any two balls come enough closer the color of balls should change (as long as they stay close).
I am very new to discrete event simulation, and i want to understand, how we do it in C# programming? what steps are required in creating the model. I know graphics and other stuff.
Use a Timer (drag one from the Toolbox over to your form in the designer, or instantiate it in code if you prefer). Double click the timer to set a
_Tickevent in your code which will fire every N milliseconds (the.Intervalproperty of the timer governs this). Set the.Intervalto 1000 (1 second), and use objects that keep track of their own position in X and Y coordinates.Use a
Randomobject to generate the direction of the next position change of the ball, and within the_Tickevent of the timer, update the position variables for each of the balls.Using raw threads is a possibility, too, but the Timer gives you some of that power without having to manage everything yourself.