The Notification Object upon Puzzle Events

This object accepts a user event, and if it's a legal move (cell that is adjacent to the empty location), then the cell is transitioned and success sound is emitted, else illegal move sound is emitted.

class ImagePicker extends Statics implements UntilNotifier {
public ImagePicker(int row,
int col,
DXMEvent ev,
PuzzleLogic puzz) {
_row = row;
_col = col;
_ev = ev;
_puzz = puzz;
}

invoked through the untilNotify construct

public Behavior notify(Object eventData,
Behavior currentRunningBvr,
BvrsToRun lst) {
Behavior xf = currentRunningBvr;
int r = _puzz._emptyRow;
int c = _puzz._emptyCol;

check to see if this is a legal move

if (((Math.abs(_row - r) == 1) && _col == c) ||
((Math.abs(_col - c) == 1) && _row == r)) {

find cell positions before and after the move

Point2Bvr start = point2(toBvr(_col * _puzz._inc),
toBvr(_row * _puzz._inc));
Point2Bvr finish = point2(toBvr(c * _puzz._inc),
toBvr(r * _puzz._inc));

Build up a transform to move from orig to final in 0.5 second

double transitionTime = 0.5;

the vector from start to finish

Vector2Bvr delta = sub(finish, start);

pos begins at start and transitions to finish in transitionTime seconds

Point2Bvr pos = add(start, delta.mul(div(localTime, toBvr(transitionTime))));

extract a translation from moving position

Transform2Bvr movingXf = translate(sub(pos, origin2));

Use this transform, and after the elapsed time freeze in place using a snapshot event.

xf = untilEx(movingXf,
timer(toBvr(transitionTime)).snapshotEvent(movingXf));

an alternative is: ,translate(finish.getX(), finish.getY()));

Set the new location of the empty cell

_puzz._emptyCol = _col;
_puzz._emptyRow = _row;

Set what position this cell is at now

_col = c;
_row = r;

emit success sound

_puzz.setHitSound(true);
} else {

emit illegal move sound

_puzz.setHitSound(false);
}

Return this new transform, waiting again for the pick event.

return untilNotify(xf, _ev, this);
}
int _row;
int _col;
DXMEvent _ev;
PuzzleLogic _puzz;
}
© 1997 Microsoft Corporation. All rights reserved. Terms of Use.