samedi 24 octobre 2015

Cyclic transfer of Object

I'm trying to model blood flow. As simple as it gets I am trying to have an event (TimerTick) trigger the transfer of a resource object from unit A to unit B, B's to C, C's to A. I can't seem to have reproducible transfer of the resources from one iteration to another, and I've tried a lot more of different ways than what's pasted below. The units are connected as a triangle after construction. I'm aware that this leaves the first unit to be erroneous, and have tried numerous ways to deal with it (and I'm not sure if that is the only problem) but since none have worked I won't post them. An idea of event set-up where any one unit doesn't need to know about any others would be totally appreciated. But just a way to make this work would also be appreciated.

class Unit{    
Resource currentResource;
Resource incomingResource;
Unit preUnit;
Unit postUnit;
public Unit( int resource, Timer t)
    {
        this.currentResource = new Resource(resource);
        t.TimerTick += T_TimerTick;
    }
 private void T_TimerTick(object sender, TimerTickEventArgs e)
    {
        postUnit.receiveResource(currentResource);
        currentResource = incomingResource;
}
void receiveResource(Resource resource)
    {
        incomingResource = resource;
    }
//pre and post units connected appropriately to Cycle ...-A-B-C-A-...
// with one cycle per TimerTick
}

Aucun commentaire:

Enregistrer un commentaire