import java.io.IOException;
import javax.microedition.lcdui.*;
import java.util.*;
// Download by http://www.codesc.net
public class huabu extends Canvas implements Runnable {
public Thread thread;
public boolean game;
public boolean left,right,fire,luobos,zis;
final static int gamelogo = 0;
final static int gametitle = 1;
final static int gamerun = 2;
final static int gameover = 3;
int gametemp;
int runtime;
int menuNUB;
int suijishu;
int anjiancishu;
int tuzi;
int xingxingx;
int luoboy;
int jiy;
int xiongy;
int dajiy;
int daxiongy;
Image imgMenu[];
Image imglogo;
Image imgtitle;
Image imgtub;
Image imgbeijing;
Image ji;
Image xiong;
Image daji;
Image daxiong;
Image luobo;
Image xianglu;
Image yanse1;
Image yanse2;
Image xingxing;
public huabu(){
runtime = 0;
gametemp = gamelogo;
tuzi = this.getWidth()/2;
xingxingx = 0;
anjiancishu = 0;
luoboy = -this.getHeight();
jiy = -this.getHeight();
xiongy = -this.getHeight();
dajiy = -this.getHeight();
daxiongy = -this.getHeight();
Random random = new Random();
suijishu= Math.abs(random.nextInt())%4;
try {
imglogo = Image.createImage("/logo.png");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
luobos = true;
zis = true;
game = true;
thread = new Thread(this);
thread.start();
}
protected void paint(Graphics g) {
// TODO Auto-generated method stub
g.setColor(0XFFFFFF);
g.fillRect(0, 0, getWidth(), getHeight());
if(gametemp == gamelogo){
g.drawImage(imglogo, getWidth()/2,getHeight()/2 , Graphics.HCENTER|Graphics.VCENTER);
}else if(gametemp == gametitle){
g.drawImage(imgtitle, 0, 0, 0);
g.drawImage(imgMenu[menuNUB], getWidth()/2, getHeight()-25, Graphics.HCENTER|Graphics.TOP);
}else if(gametemp == gamerun){
g.drawImage(imgbeijing, 0, 0, 0);
g.drawImage(yanse1, 0, getHeight()-yanse1.getHeight(),Graphics.HCENTER|Graphics.TOP );
g.drawImage(yanse2, getWidth(), getHeight()-yanse1.getHeight(),Graphics.HCENTER|Graphics.TOP);
g.drawImage(imgtub, tuzi,getHeight()/2 , Graphics.HCENTER|Graphics.VCENTER);
g.drawImage(xianglu, getWidth()/2, getHeight()-20, Graphics.HCENTER|Graphics.TOP);
g.drawImage(xingxing, xingxingx, 0, 0);
g.drawImage(luobo, getWidth()/2, luoboy,Graphics.HCENTER|Graphics.TOP );
g.drawImage(ji, getWidth()/2, jiy, Graphics.HCENTER|Graphics.TOP);
g.drawImage(xiong, getWidth()/2, xiongy, Graphics.HCENTER|Graphics.TOP);
g.drawImage(daji, getWidth()/2, dajiy, Graphics.HCENTER|Graphics.TOP);
g.drawImage(daxiong, getWidth()/2, daxiongy, Graphics.HCENTER|Graphics.TOP);
}
}
public void run() {
// TODO Auto-generated method stub
while(game){
try {
thread.sleep(80);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(gametemp == gamelogo){
if(runtime == 40){
gametemp = gametitle;
runtime = 0;
imglogo = null;
menuNUB = 0;
imgMenu = new Image[6];
try {
imgtitle = Image.createImage("/title.png");
for (int i = 0; i < imgMenu.length; i++) {
imgMenu[i] = Image.createImage("/menu_"+i+".png");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}else if(gametemp == gametitle){
if(left){
if(menuNUB > 0){
menuNUB--;
}else {
menuNUB = 5;
}
}else if(right){
if(menuNUB < 5){
menuNUB++;
}else {
menuNUB = 0;
}
}else if(fire){
if(menuNUB == 0 ){
firekey();
}else{
fire = false;
}
}
}else if(gametemp == gamerun){
if(left){
tuzi = getWidth()/2-10;
xingxingx = -15;
anjiancishu++;
}else if(right){
tuzi = getWidth()/2;
xingxingx = 0;
anjiancishu++;
}else if(runtime < 150&&anjiancishu>=15){
if(luoboy == this.getHeight()/2-100 && jiy == this.getHeight()/2-100|| xiongy == this.getHeight()/2- 100
|| dajiy == this.getHeight()/2 -100|| daxiongy == this.getHeight()/2 - 100
&& anjiancishu>=15){
luobos = false;
zis = false;
}else{
luoboy +=15;
if(suijishu == 0){
jiy += 15;
}else if(suijishu == 1){
xiongy += 15;
}else if(suijishu == 2){
dajiy += 15;
}else {
daxiongy += 15;
}
}
}
}
runtime++;
if(runtime>150){
runtime = 0;
}
repaint();
}
}
public void keyPressed(int keyCode){
switch(this.getGameAction(keyCode)){
case LEFT:
left = true;
break;
case RIGHT:
right = true;
break;
case FIRE:
fire = true;
break;
}
}
public void keyReleased(int keyCode){
left = false;
right = false;
}
public void firekey(){
if(gametemp == gametitle){
gametemp = gamerun;
imgtitle = null;
try {
imgbeijing = Image.createImage("/game_bg.png");
yanse1 = Image.createImage("/color0.png");
yanse2 = Image.createImage("/color1.png");
imgtub = Image.createImage("/tub.png");
xianglu = Image.createImage("/icon.png");
xingxing = Image.createImage("/xingxing0.png");
luobo = Image.createImage("/lucky.png");
ji = Image.createImage("/result_0.png");
xiong = Image.createImage("/result_1.png");
daji = Image.createImage("/result_2.png");
daxiong = Image.createImage("/result_3.png");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
Java 算卦游戏 附完整源码.rar
共33个文件
png:20个
class:4个
jad:2个
需积分: 50 29 下载量 121 浏览量
2019-07-10
11:42:23
上传
评论 3
收藏 76KB RAR 举报
温馨提示
Java 算卦游戏 附完整源码,Eclipse写的,算卦游戏,还是头一次见到,游戏代码简单,包括有完整的资源文件。
资源推荐
资源详情
资源评论
收起资源包目录
javaketang12.rar (33个子文件)
codesc.net
ketang12
menu_4.png 371B
result_1.png 910B
menu_1.png 710B
.project 540B
icon.png 224B
.eclipseme.tmp
emulation
ketang12.jad 241B
ketang12.jar 36KB
verified
classes
Text.class 1KB
huabu.class 5KB
libs
.eclipseme 240B
lucky.png 460B
huabu.java 6KB
menu_0.png 382B
menu_5.png 378B
Text.class 1KB
deployed
result_3.png 1KB
menu_3.png 374B
result_0.png 849B
color1.png 3KB
xingxing1.png 376B
xingxing0.png 376B
ketang12.jad 217B
.settings
org.eclipse.jdt.core.prefs 166B
Text.java 1KB
game_bg.png 4KB
logo.png 1KB
tub.png 2KB
.classpath 244B
result_2.png 1KB
color0.png 3KB
menu_2.png 390B
title.png 9KB
huabu.class 5KB
共 33 条
- 1
资源评论
weixin_39840387
- 粉丝: 784
- 资源: 3万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功