More coding today.
I'm working on getting the whole system up and running in some form so I can test and refine it.
The tick method of the Simulation class is the main driver, calling methods in both Seats and DataUser.
So here's today's code:
public void tick()
{
simTick++;
foreach (DataUser a in computerQueue) {
a.tick(simTick);
}
foreach (Seat b in seats) {
b.tick();
}
foreach (Seat c in seats) {
if (c.Free) {
c.currentUser = computerQueue[0];
computerQueue.RemoveAt(0);
}
}
}
I added the last foreach loop today.
I had to change the field currentUser to public, since it was being called from outside. Actually, maybe I should set up a Property for it – but that can wait.
When I ran the tests, it gave me an error:
Exception calling "tick" with "0" argument(s): "Index was out of range. Must be non-negative and less than the size of the collection.
Oh, that test didn't load up the computerQueue with users. The code tried to access the empty list. This needs to be addressed anyway – there could well be situations where there are no users in the queue and the seat needs to go unfilled.
So, next time, I will add a check to the method. I can just use the List Count property.
No comments:
Post a Comment