/*
* @(#)PushPuzzleCanvas.java 1.5 04/05/20
*
* Copyright (c) 1999-2004 Sun Microsystems, Inc. All rights reserved.
* PROPRIETARY/CONFIDENTIAL
* Use is subject to license terms
*/
package example.pushpuzzle;
import java.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
import javax.microedition.midlet.*;
import javax.microedition.media.*;
import javax.microedition.media.control.ToneControl;
/**
* PushPuzzleCanvas displays the game board and handles key events.
* The PushPuzzle game logic and algorithms are separated into Board.java.
* PushPuzzleCanvas does not setup or use any Commands. Commands for each
* screen and listeners should be setup outside this class.
* PushPuzzleCanvas generates a SELECT_COMMAND when the current level
* is solved. Sequencing through screens is done in the PushPuzzle MIDlet.
* <p>
* PushPuzzleCanvas handles the reading, initialization, and sequencing
* of individual puzzle screens.
* <p>
* PushPuzzleCanvas uses the Score class to restore and save game levels
* and scores for each level. To display the scores use getScoreScreen.
* It will be initialized with the current scores.
* To select a new level use the getLevelScreen and gotoLevel
* methods.
* <p>
* PushPuzzleCanvas handled key events for LEFT, RIGHT, UP, and DOWN to
* move the pusher in the game board. Pointer pressed events
* are used to move the pusher to the target location (if possible).
* <p>
*/
class PushPuzzleCanvas extends GameCanvas implements Runnable {
/** The current level */
private int level = 1;
/** The current theme index */
private int theme;
/** True if the level has been solved */
private boolean solved;
/** number of pixels per cell (updated by readscreen) */
private int cell = 1;
/** The width of the canvas */
private int width;
/** The height of the canvas */
private int height;
/** The width of the board */
private int bwidth;
/** The height of the board */
private int bheight;
/** The board containing the location of each packet, ground, walls, etc */
private Board board;
/** The score object */
private Score score;
/** The main MIDlet */
private PushPuzzle pushpuzzle;
/** The Display of this MIDlet */
private Display display;
/** The listener used to report solved events */
private CommandListener listener;
/** The form for score display */
private Form scoreForm; // form for scores
/** The TextBox to input new level numbers */
private TextBox levelText; // for input of new level
/** Background color */
private static int groundColor = 0xff8080;
/** The index in the image of the Ground */
public final int TILE_GROUND = 1;
/** The index in the image of the Packet */
public final int TILE_PACKET = 2;
/** The index in the image of the Store */
public final int TILE_STORE = 3;
/** The index in the image of the Wall */
public final int TILE_WALL = 4;
/** The index in the image of the Pusher */
public final int TILE_PUSHER = 5;
/** Background image */
private Image themeImage;
/** Tiles forming the background */
private TiledLayer tiles;
/** The Sprite that is the pusher */
private Sprite sprite;
/** Layer manager */
private LayerManager layers;
/** Thread used for key handling and animation */
private Thread thread;
/** The target cell for runTo */
private int targetx;
/** The target cell for runTo */
private int targety;
/** Pan Rate; number of milliseconds between screen updates */
private static final int PanRate = 50;
/** The Tone player */
private Player tonePlayer;
/** The ToneController */
private ToneControl toneControl;
/** Tune to play when puzzle level is solved. */
private byte[] solvedTune = {
ToneControl.VERSION, 1,
74, 8, // 1/8 note
75, 8,
73, 8
};
/** Tune to play when a packet enters a store */
private byte[] storedTune = {
ToneControl.VERSION, 1,
50, 8, // 1/8 note
60, 8,
70, 8
};
/**
* Construct a new canvas
* @param pushpuzzle the main MIDlet
* @param s the score object
*/
public PushPuzzleCanvas(PushPuzzle pushpuzzle, Score s) {
super(false); // Don't suppress key events
this.pushpuzzle = pushpuzzle;
display = Display.getDisplay(pushpuzzle);
score = s;
board = new Board();
layers = new LayerManager();
setupTheme();
targetx = targety = -1;
height = getHeight();
width = getWidth();
}
/**
* Read the previous level number from the score file.
* Read in the level data.
*/
public void init() {
// Read the last level; if it can't be found, revert to level 0
theme = score.getTheme();
setupTheme();
level = score.getLevel();
if (!readScreen(level)) {
level = 0;
readScreen(level);
}
}
/**
* Cleanup and destroy.
*/
public void destroy() {
hideNotify();
}
/**
* Figure out which set of icons to use based on the colors
*/
private void initColors() {
boolean isColor = display.isColor();
int numColors = display.numColors();
if (isColor) {
} else {
if (numColors > 2) {
} else {
}
}
}
/**
* Change themes.
* Cycle to the next index and try it
*/
public void changeTheme() {
theme++;
setupTheme();
score.setLevel(level, theme); // save the level and theme
setupTiles();
updateSprite(0);
}
/**
* Undo the last move if possible. Redraw the cell
* the pusher occupies after the undone move and the cells
* in the direction of the original move.
* Here so undo can be triggered by a command.
*/
public void undoMove() {
int pos = board.getPusherLocation();
int dir = board.undoMove();
if (dir >= 0) {
updateTilesNear(pos, dir);
updateSprite(dir);
}
solved = board.solved();
}
/**
* Restart the current level.
*/
public void restartLevel() {
readScreen(level);
solved = false;
}
/**
* Start the next level.
* @param offset of the next level
* @return true if the new level was loaded
*/
public boolean nextLevel(int offset) {
updateScores(); // save best scores
if (level + offset >= 0 && readScreen(level+offset)) {
level += offset;
score.setLevel(level, theme);
solved = false;
return true;
}
return false;
}
/**
* Get the current level.
* @return the current level.
*/
public int getLevel() {
return level;
}
/**
* Get a screen to let the user change the level.
* A simple numeric TextBox will do.
* @return the textbox used to change the level number
*/
public Screen getLevelScreen() {
if (levelText == null) {
levelText = new TextBox("Enter Level",
Integer.toString(level), // default
4, TextField.NUMERIC);
} else {
levelText.setString(Integer.toString(level));
}
return levelText;
}
/**
* Go to the chosen Level.
* @return true if the new level was loaded.
*/
public boolean gotoLevel() {
if (levelText != null) {
String s = levelText.getString();
int l;
try {
l = Integer.parseInt(s);
} catch (java.lang.NumberFormatException e) {
return false;
}
updateScores();
if (l >= 0 && readScreen(l)) {
level = l;
score.setLevel(level, theme);
solved = false;
return true;
}
}
return false;
}
/**
* Read and setup the next level.
* Opens the resource file with the name "/Screen.<lev>"
* and tells the board to read from the stream.
* <STRONG>Must be called only with the board locked.</STRONG>
* @param lev the level number to read.
* @return true if the reading of the level worked, false otherwise.
*/
private boolean readScreen(int lev) {
if (l
没有合适的资源?快使用搜索试试~ 我知道了~
j2me游戏.rar
共83个文件
class:34个
java:15个
png:9个
4星 · 超过85%的资源 需积分: 3 12 下载量 130 浏览量
2008-11-12
09:04:48
上传
评论
收藏 163KB RAR 举报
温馨提示
j2me游戏.rarj2me游戏.rar
资源推荐
资源详情
资源评论
收起资源包目录
.rar (83个子文件)
游戏
Games
classes
example
pushpuzzle
Score.class 4KB
PushPuzzle.class 5KB
PushPuzzleCanvas.class 15KB
Board.class 7KB
wormgame
WormFood.class 1KB
WormLink.class 3KB
WormMain.class 4KB
WormScore.class 3KB
WormException.class 365B
Worm.class 5KB
WormPit.class 9KB
About.class 2KB
tilepuzzle
Options.class 2KB
TilePuzzle.class 909B
Board$Piece.class 2KB
Board$BoardCommand.class 687B
Board.class 10KB
res
icons
TilePuzzle.png 103B
PushPuzzle.png 158B
JavaPowered-2.png 3KB
JavaPowered-8.png 3KB
App.png 190B
example
pushpuzzle
images
Theme-bad.png 335B
Theme-3.png 788B
Theme-1.png 327B
Theme-2.png 255B
data
screen.15 229B
screen.14 284B
screen.4 154B
screen.5 174B
screen.1 139B
screen.2 148B
screen.6 142B
screen.3 144B
screen.12 226B
screen.7 153B
screen.16 185B
screen.8 226B
screen.19 258B
screen.11 223B
screen.9 240B
screen.18 249B
screen.10 320B
screen.13 236B
screen.17 213B
src
example
pushpuzzle
Board.java 13KB
PushPuzzle.java 5KB
PushPuzzleCanvas.java 20KB
Score.java 6KB
wormgame
WormMain.java 5KB
WormScore.java 6KB
WormLink.java 4KB
WormPit.java 16KB
Worm.java 7KB
WormFood.java 3KB
WormException.java 545B
About.java 2KB
tilepuzzle
Options.java 2KB
Board.java 10KB
TilePuzzle.java 544B
bin
Games.jad 497B
MANIFEST.MF 432B
build.bat 2KB
run.bat 637B
Games.jar 44KB
project.properties 64B
tmpclasses
example
pushpuzzle
Score.class 4KB
PushPuzzle.class 5KB
PushPuzzleCanvas.class 13KB
Board.class 6KB
wormgame
WormFood.class 1KB
WormLink.class 2KB
WormMain.class 3KB
WormScore.class 3KB
WormException.class 365B
Worm.class 4KB
WormPit.class 8KB
About.class 2KB
tilepuzzle
Options.class 2KB
TilePuzzle.class 909B
Board$Piece.class 2KB
Board$BoardCommand.class 687B
Board.class 9KB
lib
tmplib
共 83 条
- 1
资源评论
- djjiujiu2014-06-15有点小问题,看看还是可以的!
ztshi
- 粉丝: 0
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功