Previous Topic Tutorial Home Page Next Topic
High Level Structure for Interactivity and Logic


Contains the logic for doing the puzzle.
class PuzzleLogic extends Statics {

Take a unit image and chop it up into the pieces of the puzzle.
public PuzzleLogic(ImageBvr unitSourceIm,
Viewer viewedOn,
URL importBase) {

_viewedOn = viewedOn;
for synchronization
_squares = 3;
_inc = 1.0 / _squares;

_unitSourceIm = unitSourceIm;

The image is a switcher to facilitate the resetting of the image; see the resetImage method below.
ImageBvr initialImage = createImage();
_imageSwitcher = new ModifiableBehavior(initialImage);
_image = (ImageBvr)_imageSwitcher.getBvr();

will switch to these sounds as appropriate.
_successSound = importSound(buildURL(importBase,
"sound/butin.wav"), null);
_failureSound = importSound(buildURL(importBase,
"sound/deflate.mp2"), null);

the puzzle sound is a switcher used in setHitSound below.
_soundSwitcher = new ModifiableBehavior(silence);
_sound = (SoundBvr)_soundSwitcher.getBvr();
}

Just recreate the image and switch to it. Synchronize with the viewer so the code doesn't vie for the processor with it.
public void resetImage() {
synchronized (_viewedOn) {
_imageSwitcher.switchTo( createImage() );
}
}

straightforward hit or fail sounds are generated.
public void setHitSound(boolean success) {
_soundSwitcher.switchTo(success ? _successSound : _failureSound);
}

public ImageBvr getImage() { return _image; }
public SoundBvr getSound() { return _sound; }

int _squares;
int _emptyRow;
int _emptyCol;
double _inc;
SoundBvr _successSound;
SoundBvr _failureSound;
ModifiableBehavior _soundSwitcher;

ImageBvr _unitSourceIm;
ImageBvr _image;
ModifiableBehavior _imageSwitcher;
SoundBvr _sound;
Viewer _viewedOn;
}


© 1998 Microsoft Corporation. All rights reserved. Terms of Use.

Previous Topic Tutorial Home Page Next Topic