/*
* Copyright (c) 2002, 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* - Redistribution of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistribution in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of Sun Microsystems, Inc., 'Java', 'Java'-based
* names, or the names of contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
* MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
* ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
* DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
* DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
* SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* You acknowledge that this software is not designed, licensed or
* intended for use in the design, construction, operation or maintenance
* of any nuclear facility. $Id: Engine.java,v 1.4 2003/06/03 22:20:35 ro89390 Exp $
*/
package com.sun.j2me.blueprints.jbricks;
import javax.microedition.lcdui.*;
/**
* This class drives the games (hence the name
* engine :). It has all the level data, animates
* the objects, keeps track of state, and triggers
* screen redraws.
*/
public class Engine implements Runnable {
public static final int PATTERN_WIDTH = 11;
public final static int TITLE = 0;
public final static int PLAY = 1;
public final static int OVER = 2;
public final static int DEMO = 3;
private Ball ball;
private Brick paddle;
private BrickList bricks;
private Screen screen;
private int score;
private int hi_score;
private int level;
private int lives;
private int state;
private int key;
private int calibration;
private boolean paused;
private long last_key_press;
private boolean level_started;
private boolean done;
private static final int LAST_KEY_DELTA = 7000;
private static final int STD = Brick.STANDARD;
private static final int FIX = Brick.FIXED;
private static final int SLI = Brick.SLIDE;
private static final int ZOM = Brick.ZOMBIE;
// Note that the width of each pattern
// has to be equal to the PATTERN_WIDTH
// variable above
private int[] title_pattern = {
STD, STD, STD, STD, STD, STD, STD, STD, STD, STD, STD, STD, STD, STD,
FIX, FIX, FIX, FIX, FIX, STD, STD, STD, STD, STD, STD, STD, STD, STD,
STD, FIX, STD, STD, STD, STD, STD, STD, STD, STD, STD, STD, FIX, STD,
STD, STD, STD, STD, STD, STD, STD, STD, STD, FIX, STD, STD, STD, STD,
STD, STD, FIX, STD, STD, STD, FIX, STD, STD, STD, STD, STD, STD, STD,
FIX, FIX, FIX, STD, STD, STD, STD, STD, STD, STD, STD, STD, STD, STD,
STD, STD, STD, STD,
};
private int[][] pattern_list = {
{
STD, STD, STD, STD, STD, STD, STD, STD, STD, STD, STD, STD, STD,
STD, STD, STD, STD, STD, STD, STD, STD, STD, STD, STD, STD, STD,
STD, STD, STD, STD, STD, STD, STD, STD, STD, STD, STD, STD, STD,
STD, STD, STD, STD, STD, STD, STD, STD, STD, STD, STD, STD, STD,
STD, STD, STD, STD, STD, STD, STD, STD, STD, STD, STD, STD, STD,
STD, STD, STD, STD, STD, STD, STD, STD, STD, STD, STD, STD, STD,
STD, STD, STD, STD, STD, STD, STD, STD, STD, STD,
}, {
STD, STD, STD, STD, STD, STD, STD, STD, STD, STD, STD, ZOM, SLI,
ZOM, ZOM, SLI, ZOM, ZOM, SLI, ZOM, ZOM, SLI, ZOM, ZOM, ZOM, ZOM,
ZOM, ZOM, ZOM, ZOM, ZOM, ZOM, ZOM, SLI, ZOM, ZOM, SLI, ZOM, ZOM,
SLI, ZOM, ZOM, SLI, ZOM, ZOM, ZOM, ZOM, ZOM, ZOM, ZOM, ZOM, ZOM,
ZOM, ZOM, ZOM, ZOM, SLI, ZOM, ZOM, SLI, ZOM, ZOM, SLI, ZOM, ZOM,
SLI, ZOM, ZOM, ZOM, ZOM, ZOM, ZOM, ZOM, ZOM, ZOM, ZOM, ZOM, SLI,
ZOM, ZOM, SLI, ZOM, ZOM, SLI, ZOM, ZOM, SLI, ZOM,
}, {
ZOM, ZOM, ZOM, ZOM, ZOM, ZOM, ZOM, ZOM, ZOM, ZOM, ZOM, ZOM, FIX,
SLI, FIX, FIX, FIX, FIX, FIX, SLI, FIX, ZOM, ZOM, FIX, ZOM, ZOM,
ZOM, ZOM, ZOM, ZOM, ZOM, FIX, ZOM, ZOM, FIX, ZOM, STD, STD, STD,
STD, STD, ZOM, FIX, ZOM, ZOM, FIX, ZOM, ZOM, ZOM, ZOM, ZOM, ZOM,
ZOM, FIX, ZOM, ZOM, FIX, FIX, FIX, FIX, FIX, FIX, FIX, FIX, FIX,
ZOM, ZOM, ZOM, ZOM, ZOM, ZOM, ZOM, ZOM, ZOM, ZOM, ZOM, ZOM, STD,
STD, STD, STD, STD, STD, STD, STD, STD, STD, STD,
}, {
STD, STD, STD, STD, STD, STD, STD, STD, STD, STD, STD, STD, FIX,
FIX, FIX, FIX, FIX, FIX, FIX, FIX, FIX, STD, STD, FIX, STD, STD,
STD, STD, STD, STD, STD, FIX, STD, STD, STD, STD, STD, STD, STD,
STD, STD, STD, STD, STD, STD, STD, STD, STD, STD, STD, STD, STD,
STD, STD, STD, STD, FIX, STD, STD, STD, STD, STD, STD, STD, FIX,
STD, STD, FIX, FIX, FIX, FIX, FIX, FIX, FIX, FIX, FIX, STD, STD,
STD, STD, STD, STD, STD, STD, STD, STD, STD, STD
}
};
public Engine(Screen screen) {
int i, n;
long then;
this.screen = screen;
screen.setEngine(this);
paddle = new Brick(null, Screen.width / 2 - Brick.WIDTH / 2,
Screen.VDIVIDER - Brick.HEIGHT - 4, -1, 2);
paddle.setColor(ThreeDColor.lightGray);
paddle.width = Screen.width / 8;
paddle.height = Brick.HEIGHT;
ball = new Ball(Screen.width / 2 - Brick.WIDTH / 4,
paddle.y - 2 * Ball.RADIUS,
2 * Math.max(1, Screen.width / 80),
2 * -Math.max(1, Screen.width / 80));
level = 0;
state = TITLE;
done = false;
bricks = new BrickList(title_pattern, PATTERN_WIDTH, -1);
last_key_press = System.currentTimeMillis();
then = System.currentTimeMillis();
n = 0;
for (i = 0; i < 30000; i++) {
n++;
}
if (n > 0) {
calibration = (int) (System.currentTimeMillis() - then);
}
Thread runner = new Thread(this);
runner.start();
}
private void reset() {
level = 0;
lives = 2;
score = 0;
startLevel();
}
private void restartLevel() {
if (state == PLAY) {
paused = true;
}
synchronized (this) {
level_started = true;
}
paddle.moveTo(Screen.width / 2 - Brick.WIDTH / 2,
Screen.VDIVIDER - Brick.HEIGHT - 4);
ball.moveTo(Screen.width / 2 - Brick.WIDTH / 4,
paddle.y - 2 * Ball.RADIUS);
ball.setSteps(Math.max(1, Screen.width / 80),
-Math.max(1, Screen.width / 80));
screen.repaint();
screen.serviceRepaints();
}
private void startLevel() {
bricks = new BrickList(pattern_list[level], PATTERN_WIDTH, level);
restartLevel();
}
private void nextLevel() {
level++;
if (level == pattern_list.length) {
level = 0;
}
startLevel();
tq.rar_The Project_j2me
版权申诉
192 浏览量
2022-09-23
23:30:07
上传
评论
收藏 76KB RAR 举报
林当时
- 粉丝: 101
- 资源: 1万+
最新资源
- 49065784447654二&驴(推荐).apk
- 探索微软新VLM Phi-3 Vision模型:详细分析与代码示例
- 前端开发美信射频前端开发板开发资料美信射频前端开发板开发资料
- 【mysql开发】使用ssm框架+mysql开发,这是一个J2ee项目
- 图像处理MATLAB图像处理,matlab图像处理的基本程序
- 专题讲解:信噪比和噪声系数
- 【matlab仿真】MATLAB入门仿真材料 MATLAB入门仿真材料
- Buffer of Thoughts: Thought-Augmented Reasoning with Large Langu
- 易语言抢购源码,京东抢购助手源码+模块打包
- feeds_tab_manager_simpleTabListCache
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈