网站首页 > 文章中心 > 其它

java泡泡堂游戏代码

作者:小编 更新时间:2023-10-24 18:39:36 浏览量:389人看过

JAVA可以编写游戏吗

Java可以编写游戏, 但是编写游戏并不是Java最擅长的地方..一般的大中型游戏,可能是汇编,c#,c/c++编写.. 而后端往往使用java. 当然了纯java也可以制作一些简单的游戏的..

一: 手机游戏上面

二: PC游戏上面

①.) awt/swing 等传统的图形界面技术, 也可以编写一些简单的游戏,比如泡泡堂, 超级玛丽等游戏,

三: 网页游戏方面

java泡泡堂游戏代码-图1

①.) awt/swing 写的Applet 游戏, 曾经可以在浏览器上运行. 但是由于安全隐患, 很多浏览器已经默认不支持了.

拓展: 如果想用java制作RPG游戏或者比较复杂的游戏 , 也可以使用一些开源的游戏框架.?

求用java编写的泡泡堂小游戏的源代码

矮油,这个真是只有高手来帮助你了.最好你去百度提问,提问分类选则

电脑/网络-----程序设计-----JAVA相关(不选也行).

不过搜搜也行啦,

个人认为百度大神多一点,嘿嘿

网络游戏泡泡堂是由什么开发工具开发的 c++?c# java?

又及,SQL一定是要的,维护数据库神马的最讨厌了......

java泡泡堂游戏代码-图2

泡泡堂源代码是什么?

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

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

先给你看看主要的类吧

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[][] 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();

sleep();

loadMap(stage);

loadPlayer();

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

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

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

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

this.cursorManager.append(cursor);

this.numberManager.append(number);

this.loadPercent = 100;

isPlaying = true;

public void run() {

while (!isEnd) {

long beginTime = System.currentTimeMillis();

this.drawScreen();

long endTime = System.currentTimeMillis();

if (endTime - beginTime this.delay) {

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

} catch (InterruptedException e) {

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;

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

this.bornPlace = Global.MAP_FOREST_BORNPLACE;

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

this.bornPlace = Global.MAP_PIRATE_BORNPLACE;

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

this.bornPlace = Global.MAP_FAUBOURG_BORNPLACE;

public void loadPlayer() {

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

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

this.gameLayerManager.append(player);

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

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

this.gameLayerManager.append(playerGhost);

// TODO Auto-generated catch block

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

this.drawPauseFrame();

this.drawLoadingFrame();

this.flushGraphics();

public void drawFailScreen() {

public void drawState() {

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

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

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

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

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

protected void drawPauseFrame() {

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

Graphics.HCENTER | Graphics.VCENTER);

protected void drawLoadingFrame() {

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

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);

if ((keyStates UP_PRESSED) != 0) {

this.player.walk(Global.NORTH);

if ((keyStates RIGHT_PRESSED) != 0) {

this.player.walk(Global.EAST);

if ((keyStates LEFT_PRESSED) != 0) {

this.player.walk(Global.WEST);

protected void keyPressed(int key) {

if (!this.isPlaying)

return;

this.chooseIndex = 0;

this.pauseGame();

this.nextStage();

this.preStage();

if (this.isPause) {

switch (key) {

case -1:

java泡泡堂游戏代码-图3

if (this.chooseIndex == 0)

switch (chooseIndex) {

this.continueGame();

this.restart();

this.endGame();

default:

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

public void restart() {

public void continueGame() {

this.player.play();

public void pauseGame() {

this.isPause = true;

this.player.stop();

public void endGame() {

this.isEnd = true;

this.mainThread = null;

System.gc();

this.dreamBubbleMidlet.menu.showMe();

public void nextStage() {

this.stageIndex++;

public void preStage() {

if (this.stageIndex 0) {

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();

isLoading = true;

loadPercent = 0;

loadStage(stageIndex);

isLoading = false;

public void sleep() {

Thread.sleep(100);

这个是游戏主体类

下面是游戏的人物类

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++;

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;

if (this.status == Global.BORN

this.characterClock Global.BORN_TIME) {

this.status = Global.SOUTH;

this.isCanOperate = true;

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

this.isCanOperate = false;

this.deadTime++;

this.deadTime = 100;

this.setVisible(false);

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

this.setVisible(true);

public void walk(int direction) {

if (!isAlive)

if (!isCanOperate)

this.collisionCheck(direction);

if (this.status == direction) {

this.status = direction;

this.setPosition(xCoodinate, yCoodinate);

public void stop() {

public void play() {

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

public void increaseBomb() {

if (this.bombNums Global.MAX_BOMB_NUMBER)

this.bombNums++;

public int getRow() {

public int getCol() {

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;

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

以上就是土嘎嘎小编为大家整理的java泡泡堂游戏代码相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!

版权声明:倡导尊重与保护知识产权。未经许可,任何人不得复制、转载、或以其他方式使用本站《原创》内容,违者将追究其法律责任。本站文章内容,部分图片来源于网络,如有侵权,请联系我们修改或者删除处理。

编辑推荐

热门文章