Esempio n. 1
0
    int NewEmptyThing()
    {
        int thingId = nextThingId++;

        theThings[thingId] = new PositionedThing();
        return(thingId);
    } // Take the return value, remember the Id, and assign Thing & PosFace to theThings[thingId]
Esempio n. 2
0
    protected virtual void OnThingMoved(PositionedThing posThing)
    {
        var handler = ThingMoved;

        if (handler != null)
        {
            var args = new BoardEventArgs // make a copy of the values
            {
                ThingId    = posThing.Thing.IdOnBoard,
                NewPosFace = new PosFace(posThing.PosFace)
            };
            handler(null, args);
            //handler(this, args); // don't need to pass this ?
        }
    }
Esempio n. 3
0
    private bool TryMoveThing(Pos pos, Pos moveVector, out PositionedThing posThing) //?optional arg for Square
    {
        posThing = null;
        var square0 = SquareAt(pos);
        var pos1    = pos + moveVector;
        var square1 = SquareAt(pos1);

        //Note: we're ignoring the possibility of having squares in between square0 and square1
        if (square0 == null || square1 == null || !square1.CanMoveOnToMe())
        {
            return(false);
        }
        if (square0.ThingOnMe == null)
        {
            return(true); // there was nothing to move; call that success
        }
        posThing          = GetPositionedThing(square0.ThingOnMe);
        square0.ThingOnMe = null;
        square1.ThingOnMe = posThing.Thing;
        posThing.PosFace.SetPos(pos1);
        return(true);
    }