import java.applet.Applet; import java.awt.*; import com.genuts.gameui.*; /** * Displays simple sprite as tiles on the board.
* The order of tiles is taken from the class Tiles. */ public class SimpleBoard extends Applet { private PlayField playfield = null; public void init() { setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0)); // Loading images Image tileImage = getImage(getClass().getResource("tile.gif")); Image backgroundImage = getImage(getClass().getResource("background.jpg")); MediaTracker tracker = new MediaTracker(this); tracker.addImage(tileImage, 0); tracker.addImage(backgroundImage, 0); try { tracker.waitForID(0); } catch (InterruptedException e) { System.out.println("Loading interrupted"); } // Gets the size of a tile int tileSize = tileImage.getWidth(null); // Creates the playfield playfield = new PlayField(Tiles.tiles[0].length*tileSize, Tiles.tiles.length*tileSize); playfield.setBackground(Color.white); playfield.setBackgroundImage(backgroundImage); // Display tiles from class Tiles. // If the current position in the Tiles array is set to true, // a new sprite is created. for (int y = 0; y < Tiles.tiles.length; y++) { for (int x = 0; x < Tiles.tiles[y].length; x++) { if (Tiles.tiles[y][x]) { Sprite tile = new Sprite(tileImage); tile.setPosition(x*tileSize, y*tileSize); playfield.addSprite(tile); } } } // Displays the playfield add(playfield); } public void start() { // Activate the playfield playfield.setPause(false); } public void stop() { if (playfield != null) { playfield.stop(); } } }