java炸弹人源代码

谁能给我一个手机游戏的源代码

这个地址也有,不过直接给你吧,这样比较好

先给你看看主要的类吧

package Game;

import DreamBubbleMidlet;

import java.io.IOException;

import java.util.Enumeration;

import java.util.Hashtable;

import javax.microedition.lcdui.Graphics;

import javax.microedition.lcdui.Image;

import javax.microedition.lcdui.game.GameCanvas;

import javax.microedition.lcdui.game.LayerManager;

import javax.microedition.lcdui.game.Sprite;

public class Game extends GameCanvas implements Runnable {

protected DreamBubbleMidlet dreamBubbleMidlet;

protected Graphics g;

protected Image loadingImage;

protected Image pauseImage;

protected Image cursorImage;

protected Image jackStateImage;

protected Image johnStateImage;

protected Image numberImage;

protected Sprite cursor;

protected Sprite number;

protected LayerManager cursorManager;

protected LayerManager numberManager;

protected Hashtable bombTable;

protected Map map;

protected LayerManager gameLayerManager;

protected Role player;

protected Sprite playerGhost;

protected int screenWidth;

protected int screenHeight;

protected int delay = 50;

protected int[][] bornPlace;

protected int chooseIndex;

protected int stageIndex = 1;

protected int gameClock;

protected int loadPercent;

protected boolean isPause;

protected boolean isEnd;

protected boolean isPlaying;

protected boolean isLoading;

protected Thread mainThread;

public Game(DreamBubbleMidlet dreamBubbleMidlet) {

super(false);

this.setFullScreenMode(true);

this.dreamBubbleMidlet = dreamBubbleMidlet;

this.screenWidth = this.getWidth();

this.screenHeight = this.getHeight();

try {

this.loadingImage = Image.createImage(“/Game/Loading.png”);

this.pauseImage = Image.createImage(“/Game/Pause.png”);

this.cursorImage = Image.createImage(“/Game/Cursor.png”);

this.jackStateImage = Image.createImage(“/State/JackState.png”);

this.johnStateImage = Image.createImage(“/State/JohnState.png”);

this.numberImage = Image.createImage(“/State/Number.png”);

} catch (IOException e) {

e.printStackTrace();

}

this.g = this.getGraphics();

}

public void loadStage(int stage) {

this.isEnd = false;

this.isPause = false;

this.isPlaying = false;

this.gameLayerManager = new LayerManager();

this.cursorManager = new LayerManager();

this.numberManager = new LayerManager();

this.bombTable = new Hashtable();

this.cursor = new Sprite(this.cursorImage, 32, 32);

this.number = new Sprite(this.numberImage, 12, 10);

this.loadPercent = 20;

sleep();

loadMap(stage);

this.loadPercent = 40;

sleep();

loadPlayer();

this.loadPercent = 60;

sleep();

this.gameLayerManager.append(map.getBombLayer());

this.gameLayerManager.append(map.getBuildLayer());

this.gameLayerManager.append(map.getToolLayer());

this.gameLayerManager.append(map.getFloorLayer());

this.gameLayerManager.setViewWindow(0, -5, screenWidth,

Global.MAP_HEIGHT + 5);

this.cursorManager.append(cursor);

this.numberManager.append(number);

this.loadPercent = 80;

sleep();

this.loadPercent = 100;

sleep();

isPlaying = true;

}

public void run() {

while (!isEnd) {

long beginTime = System.currentTimeMillis();

this.drawScreen();

long endTime = System.currentTimeMillis();

if (endTime – beginTime this.delay) {

try {

Thread.sleep(this.delay – (endTime – beginTime));

} catch (InterruptedException e) {

e.printStackTrace();

}

}

}

}

public void loadMap(int stage) {

switch (stage) {

case 0:

this.map = new Map(Global.MAP_BLOCK);

this.bornPlace = Global.MAP_BLOCK_BORNPLACE;

break;

case 1:

this.map = new Map(Global.MAP_FACTORY);

this.bornPlace = Global.MAP_FACTORY_BORNPLACE;

break;

case 2:

this.map = new Map(Global.MAP_FOREST);

this.bornPlace = Global.MAP_FOREST_BORNPLACE;

break;

case 3:

this.map = new Map(Global.MAP_PIRATE);

this.bornPlace = Global.MAP_PIRATE_BORNPLACE;

break;

case 4:

this.map = new Map(Global.MAP_FAUBOURG);

this.bornPlace = Global.MAP_FAUBOURG_BORNPLACE;

break;

}

}

public void loadPlayer() {

this.player = SingleGameRole.createSingleGameRole(this, Global.JACK,

this.bornPlace[0][0], this.bornPlace[0][1]);

this.gameLayerManager.append(player);

try {

this.playerGhost = new Sprite(Image.createImage(“/Character/Jack.png”),

this.player.width, this.player.height);

this.gameLayerManager.append(playerGhost);

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

public void playerUpdate() {

if(!this.player.isAlive)

this.playerGhost.setVisible(false);

this.playerGhost.setFrame(this.player.getFrame());

this.player.updateRole();

}

public void bombUpdate() {

Enumeration enu = this.bombTable.keys();

while (enu.hasMoreElements()) {

String key = (String) enu.nextElement();

Bomb bomb = (Bomb) (bombTable.get(key));

if (bomb.isvisable) {

bomb.update();

} else {

bombTable.remove(key);

bomb = null;

}

}

}

public void mapUpdate() {

this.map.update();

}

public void drawScreen() {

if (gameClock 10000)

gameClock++;

else

gameClock = 0;

if (!this.isLoading) {

if (!isPause) {

this.operate();

this.bombUpdate();

this.playerUpdate();

this.mapUpdate();

g.setColor(0x000000);

g.fillRect(0, 0, getWidth(), getHeight());

this.drawState();

gameLayerManager.paint(g, 0, this.screenHeight

– Global.MAP_HEIGHT – 5);

} else {

this.drawPauseFrame();

}

} else {

this.drawLoadingFrame();

}

this.flushGraphics();

}

public void drawFailScreen() {

}

public void drawState() {

if (this.player.type == Global.JACK) {

g.drawImage(jackStateImage, 60, 5, Graphics.TOP | Graphics.LEFT);

}

if (this.player.type == Global.JOHN) {

g.drawImage(johnStateImage, 60, 5, Graphics.TOP | Graphics.LEFT);

}

this.number.setFrame(this.player.bombNums);

this.numberManager.paint(g, 101, 15);

this.number.setFrame(this.player.speed);

this.numberManager.paint(g, 133, 15);

this.number.setFrame(this.player.power);

this.numberManager.paint(g, 165, 15);

}

protected void drawPauseFrame() {

g.setColor(0x000000);

g.fillRect(0, 0, getWidth(), getHeight());

this.drawState();

if (gameClock % 5 == 0)

this.cursor.setFrame((this.cursor.getFrame() + 1) % 4);

this.gameLayerManager.paint(g, 0, this.screenHeight – Global.MAP_HEIGHT

– 5);

this.cursorManager.paint(g, screenWidth / 2 – pauseImage.getWidth() / 2

– 32, screenHeight / 2 – pauseImage.getHeight() / 2

+ this.chooseIndex * 33 + 24);

g.drawImage(pauseImage, screenWidth / 2, screenHeight / 2,

Graphics.HCENTER | Graphics.VCENTER);

}

protected void drawLoadingFrame() {

g.setColor(66, 70, 246);

g.fillRect(0, 0, screenWidth, screenHeight);

g.drawImage(loadingImage, screenWidth / 2, 2 * screenHeight / 5,

Graphics.HCENTER | Graphics.VCENTER);

g.setColor(0, 255, 0);

g.fillRect((screenWidth – 120) / 2, 2 * screenHeight / 3,

(this.loadPercent * 120) / 100, 10);

g.setColor(255, 0, 0);

g.drawRect((screenWidth – 120) / 2, 2 * screenHeight / 3, 120, 10);

}

public void showMe() {

new Loading(this.stageIndex);

if (this.mainThread == null) {

mainThread = new Thread(this);

mainThread.start();

}

this.dreamBubbleMidlet.show(this);

}

public void operate() {

int keyStates = getKeyStates();

this.playerGhost.setPosition(this.player.xCoodinate, this.player.yCoodinate);

if ((keyStates DOWN_PRESSED) != 0) {

this.player.walk(Global.SOUTH);

} else {

if ((keyStates UP_PRESSED) != 0) {

this.player.walk(Global.NORTH);

} else {

if ((keyStates RIGHT_PRESSED) != 0) {

this.player.walk(Global.EAST);

} else {

if ((keyStates LEFT_PRESSED) != 0) {

this.player.walk(Global.WEST);

}

}

}

}

}

protected void keyPressed(int key) {

if (!this.isPlaying)

return;

if (!this.isPause key == -7) {// 右键

this.chooseIndex = 0;

this.pauseGame();

return;

}

if (key == 35) {// #键

this.nextStage();

return;

}

if (key == 42) {// *键

this.preStage();

return;

}

if (this.isPause) {

switch (key) {

case -1:

case -3:

if (this.chooseIndex == 0)

this.chooseIndex = 2;

else

this.chooseIndex = (this.chooseIndex – 1) % 3;

break;

case -2:

case -4:

this.chooseIndex = (this.chooseIndex + 1) % 3;

break;

case -5:// 确认键

case -6:// 左软键

switch (chooseIndex) {

case 0:

this.continueGame();

break;

case 1:

this.restart();

break;

case 2:

this.endGame();

break;

}

break;

default:

break;

}

} else {

switch (key) {

case 53:

case -5:// 确认键

this.player.setBomb(this.player.getRow(), this.player.getCol());

break;

}

}

}

public void restart() {

new Loading(this.stageIndex);

}

public void continueGame() {

this.isPause = false;

this.player.play();

}

public void pauseGame() {

this.isPause = true;

this.player.stop();

}

public void endGame() {

this.isEnd = true;

this.mainThread = null;

System.gc();

try {

Thread.sleep(500);

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

this.dreamBubbleMidlet.menu.showMe();

}

public void nextStage() {

if (this.stageIndex 4) {

this.stageIndex++;

}

new Loading(this.stageIndex);

}

public void preStage() {

if (this.stageIndex 0) {

this.stageIndex–;

}

new Loading(this.stageIndex);

}

class Loading implements Runnable {

private Thread innerThread;

private int stageIndex;

public Loading(int stageIndex) {

this.stageIndex = stageIndex;

innerThread = new Thread(this);

innerThread.start();

}

public void run() {

isLoading = true;

loadPercent = 0;

System.gc();

loadStage(stageIndex);

isLoading = false;

}

}

public void sleep() {

try {

Thread.sleep(100);

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

这个是游戏主体类

下面是游戏的人物类

package Game;

import javax.microedition.lcdui.Image;

import javax.microedition.lcdui.game.Sprite;

public abstract class Role extends Sprite {

/**

* 人物的基本属性

*/

protected int type;

protected int xCoodinate;

protected int yCoodinate;

protected int row;

protected int col;

protected int width;

protected int height;

protected int speed;

protected int status;

protected boolean isCanOperate = false;

protected boolean isAlive = true;

/**

* 人物放置炸弹的基本属性

*/

protected int power;

protected int bombNums;

protected int characterClock = 0;

protected int deadTime = 0;

protected Game game;

protected Role(Image image, int width, int Height, Game game) {

super(image, width, Height);

this.game = game;

}

/**

* 人物拾起道具

* @param tool

*/

public abstract void pickupTool(int tool);

/**

* 碰撞检测以及坐标的改变,如果对行走条件有特殊需求,既可以在这里写自己的条件

* @param direction

*/

public abstract void collisionCheck(int direction);

public void updateRole() {

if (this.characterClock 10000) {

this.characterClock++;

} else {

this.characterClock = 100;

}

int row = this.getRow();

int col = this.getCol();

if (this.isAlive) {

int tool = this.game.map.getToolLayer().getCell(col, row);

if (tool 0) {

this.pickupTool(tool);

this.game.map.getToolLayer().setCell(col, row, 0);

}

if (this.game.map.hasFeature(row, col, Global.DEADLY)) {

this.isAlive = false;

return;

}

if (this.status == Global.BORN

this.characterClock Global.BORN_TIME) {

this.status = Global.SOUTH;

this.setFrame(Global.SOUTH * 6);

this.isCanOperate = true;

}

if (this.status == Global.BORN) {

if (this.characterClock % 2 == 0)

this.setFrame(Global.BORN * 6 + (this.getFrame() – 1) % 4);

return;

}

} else {

this.isCanOperate = false;

if (this.deadTime = 20) {

this.deadTime++;

} else {

this.deadTime = 100;

this.setVisible(false);

return;

}

if (this.characterClock % 2 == 0) {

if (this.getFrame() Global.DEAD * 6) {

this.setFrame(Global.DEAD * 6);

} else {

if (this.getFrame() 29) {

this.setFrame(this.getFrame() + 1);

} else {

if (this.characterClock % 4 == 0) {

this.setFrame(29);

this.setVisible(true);

} else {

this.setVisible(false);

}

}

}

}

}

}

public void walk(int direction) {

if (!isAlive)

return;

if (!isCanOperate)

return;

if(direction==9) return;

this.collisionCheck(direction);

if (this.characterClock % 2 == 0) {

if (this.status == direction) {

this.setFrame(this.status * 6 + (this.getFrame() + 1) % 6);

} else {

this.status = direction;

this.setFrame(this.status * 6);

}

}

this.setPosition(xCoodinate, yCoodinate);

}

public void stop() {

this.isCanOperate = false;

}

public void play() {

this.isCanOperate = true;

}

public abstract void setBomb(int row, int col);

public void increaseBomb() {

if (this.bombNums Global.MAX_BOMB_NUMBER)

this.bombNums++;

}

public int getRow() {

return getRow(getBottomY(yCoodinate) – Global.MAP_CELL / 2);

}

public int getCol() {

return getCol(xCoodinate + Global.MAP_CELL / 2);

}

protected int getBottomY(int y) {

return y + this.height – 1;

}

protected int getRightX(int x) {

return x + Global.MAP_CELL – 1;

}

protected int getPreY(int y) {

return getBottomY(y) + 1 – Global.MAP_CELL;

}

protected int getRow(int x) {

return x / Global.MAP_CELL;

}

protected int getCol(int y) {

return y / Global.MAP_CELL;

}

}

我的QQ是609419340

看不明白的可以随时来问我哦,还可以当时传给你撒

java炸弹人源代码

之前java上有个游戏

俄罗斯方块(Tetris)是经典的益智游戏,几乎是世界上最有影响力的益智游戏之一,游戏本身也很简单,只要不断消减掉落的方块就可以了。这个游戏被模仿了很多个版本,我这里的是EA出的疯狂俄罗斯方块(TetrisMania)。超级泡泡龙(SuperBubbleBobble)是Taito公司开发的游戏,主角是两只绿色和蓝色的小恐龙,通过吐出泡泡来消减屏幕上的彩球,游戏本身简单易学、妙趣横生,女孩子玩起来会上瘾的。超级马里奥(SuperMarioBros)是任天堂公司开发的著名横版过关游戏,是电子游戏历史上销量最大的系列游戏之一,早在任天堂的红白机时代就名声在外了,这个游戏几乎移植到了所有的任天堂游戏机,也包括电脑和手机。吃豆(Pac-Man)是Namco公司开发的一个经典游戏,玩家控制游戏的主人公黄色小精灵吃掉藏在迷宫内所有的豆子,并且不能被“幽灵”抓到。贪吃蛇(RetroSnaker)是诺基亚手机上的一个元老级游戏,这个游戏短小精悍,很具可玩性,特别适合在手机上玩。据称,已经有超过十亿人玩过这个游戏。钻石情迷(Bejeweled)是一个很好玩的益智游戏,有点像“对对碰”,游戏规则很简单,移动相邻的两个钻石,使任一排产生有三个或以上的相同钻石,即消去,上面的钻石靠重力落下。祖玛(Zuma)是一款休闲益智游戏,玩法很像 龙珠,将中间吐出来的珠子向着周围连环滚出的同色珠子射打,够三个就能炸裂消除,简单有趣。炸弹人(Bomberman)是Hudson公司开发的一款基于迷宫的游戏,游戏主角炸弹人是一个机器人,基本操作是放置炸弹,以十字型的方式爆炸,来炸死敌人,也可以炸死自己,还有些增强威力与技能道具增加了游戏的可玩性。波斯王子(PrinceofPersia)是上世纪九十年代的一个经典游戏,我以前在DOS上玩过的最早的游戏之一,可惜游戏续集一代不如一代,Gameloft将波斯王子一代进行了重新开发制作,命名为PrinceofPersiaClassic,并支持手机,其在手机上的效果很不错。模拟人生(TheSims)是ElectronicArts开发的一款以模拟普通人生活为主题的游戏,玩家可以操控模拟人物进行日常生活、社区交流以及建造房屋。在一个模拟的世界中,仿造真实的情境,控制生理和精神的需求。手机版的模拟人生简化了原始电脑游戏的一些因素,使得其可以在手机上方便的操作。

java中模拟一个定时炸弹线程,接收控制台输入错误。

第一次运行时如果什么都不输入,直接Enter键,line会为空字符串。调用可能会出错。

if(line.equals(“quit”)){

改为

if(line!=null line.equals(“quit”)){

本文来自投稿,不代表【】观点,发布者:【

本文地址: ,如若转载,请注明出处!

举报投诉邮箱:253000106@qq.com

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2024年3月25日 17:49:23
下一篇 2024年3月25日 17:58:36

相关推荐

  • 深入java虚拟机pdf,深入java虚拟机 中村成洋 pdf

    在linux环境下,java怎么实现从word格式转换为pdf格式 //设置当前使用的打印机,我的Adobe Distiller打印机名字为 Adobe PDF wordCom.setProperty( ActivePrinter , new Variant( Adobe PDF ));//设置printout的参数,将word文档打印为postscript…

    2024年5月23日
    4600
  • java截取指定长度字符串,java截取指定字符串之后的

    java中如何截取字符串中的指定一部分 第一个参数是开始截取的字符位置。(从0开始)第二个参数是结束字符的位置+1。(从0开始)indexof函数的作用是查找该字符串中的某个字的位置,并且返回。 int end);截取s中从begin开始至end结束时的字符串,并将其赋值给s;split讲解:java.lang.string.split split 方法 将…

    2024年5月23日
    4400
  • java绑定一个端口,java使用端口

    java如何多个service共用一个端口 你如果有多个项目的话,你可以把多个项目放到一个tomcat里面,这样端口相同使用项目名称来进行区分项目。你如果非要使用同一个,你也可以配置不同的域名导向不同的项目。就是访问的域名不同转接到的项目不同。 如果需要同时启动多个程序,要么修改tomcat的配置文件中的监听端口。要么修改jar包程序的监听端口。不能在一台服…

    2024年5月23日
    3600
  • java多线程并发编程基础,Java多线程并发执行返回

    电脑培训分享Java并发编程:核心理论 电脑培训发现本系列会从线程间协调的方式(wait、notify、notifyAll)、Synchronized及Volatile的本质入手,详细解释JDK为我们提供的每种并发工具和底层实现机制。 人们开始意识到了继承的众多缺点,开始努力用聚合代替继承。软件工程解决扩展性的重要原则就是抽象描述,直接使用的工具就是接口。接…

    2024年5月23日
    4800
  • 自学java找工作,自学java找工作需要包装简历吗

    自学java学多久可以找到工作 1、自学Java至少需要一年以上的时间才能达到找工作的水平。报班培训四到六个月的时间就可以找到一份不错的工作。 2、自学Java至少需要一年以上的时间才能达到找工作的水平。 3、如果要想找到一份Java相关的工作,需要至少学习5-6个月时间才能就业。Java开发需要掌握一些基础的编程语言知识,比如掌握面向对象的编程思想、基本的…

    2024年5月23日
    4400
  • java左移右移,java 左移

    java位移问题 1、思路:直接用Integer类的bit运算操作。 2、移位操作:左移:向左移位,符号后面的数字是移了多少位,移的位用0补齐,例如2进制数01111111左移一位后变为11111110,移位是字节操作。 3、Java 位运算 Java 位运算[转]一,Java 位运算表示方法: 在Java语言中,二进制数使用补码表示,最高位为符号位,正数的…

    2024年5月23日
    4300
  • java技术规范,java规范性要求

    现在主流的JAVA技术是什么? java最流行开发技术程序员必看 1 、Git Git一直是世界上最受欢迎的Java工具之一,也是Java开发人员最杰出的工具之一。Git是一个开源工具,是-种出色的分布式版本控制解决方案。 (1).Java基础语法、数组、类与对象、继承与多态、异常、范型、集合、流与文件、反射、枚举、自动装箱和注解。(2).Java面向对象编…

    2024年5月23日
    4100
  • javasocket编程,Java socket编程中,禁用nagle算法的参数

    Java进行并发多连接socket编程 1、Java可利用ServerSocket类对外部客户端提供多个socket接口。基本的做法是先创建一个ServerSocket实例,并绑定一个指定的端口,然后在这个实例上调用accept()方法等待客户端的连接请求。 2、Socket socket=server.accept(0;Thread handleThrea…

    2024年5月23日
    4700
  • java死亡,java死代码是什么意思

    我的世界传送回死亡点指令是什么? 1、下面就让我们一起来了解一下吧:我的世界回到死的地方的指令是输入/back,就可以回到死亡地点了,当然也可以看信标,因为死亡后会有一道光集中在死亡点,只要循着光就可以找到目的地了。 2、在服务器中的指令 首先打开指令台,在指令行输入“/back”就可以回到自己的死亡地点了。在单人游戏中的指令 在单人游戏中,您无法直接返回到…

    2024年5月23日
    4900
  • myeclipse能部署java工程么,myeclipse支持jdk18

    myeclipse如何建java文件 1、点击【File】—【New】–【Class】在如下界面,输入Class的名字,如Test,点击【Finish】。Test.java文件创建成功。 2、点击【File】—【New】–【Class】 在如下界面,输入Class的名字,如Test,点击【Finish】。 Te…

    2024年5月23日
    4100

发表回复

登录后才能评论



关注微信