package man;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import java.util.*;
import javax.microedition.lcdui.game.GameCanvas;
public class Man extends MIDlet
{
private Game game;
public Display display;
public Man()
{
game = new Game(this);
display = Display.getDisplay(this);
}
public void startApp()
{
game.startGame();
}
public void pauseApp()
{
//
}
public void destroyApp(boolean unconditional)
{
//
}
public void closeman()
{
destroyApp(false);
notifyDestroyed();
}
}
class Game
{
public MainMenu mainmenu;
public ManDown mandown;
private Man G_man;
private Image imgEmpty;
public int man_mov_x = 3;
public int man_mov_y = 3;
public int obj_mov = 4;
public Game(Man man)
{
this.G_man = man;
this.mainmenu = new MainMenu(this);
}
public void startGame()
{
G_man.display.setCurrent(this.mainmenu);
}
public void startmandown()
{
this.mandown = new ManDown(this,G_man);
setgame(man_mov_x,man_mov_y,obj_mov);
G_man.display.setCurrent(this.mandown);
}
public void exitGame()
{
G_man.destroyApp(false);
G_man.notifyDestroyed();
}
public void setgame(int manmovx, int manmovy, int objmov)
{
this.mandown.MAN_MOV_X = manmovx;
this.mandown.MAN_MOV_Y = manmovy;
this.mandown.OBJ_MOV = objmov;
}
public void MydrawRegion(Graphics graphics,Image imgSrc,
int SrcX,int SrcY,
int TargetX, int TargetY,
int TargetWidth,int TargetHeight)
{
graphics.setClip(TargetX, TargetY, TargetWidth, TargetHeight);
graphics.drawImage(imgSrc, TargetX-SrcX, TargetY-SrcY, Graphics.LEFT | Graphics.TOP);
}
}
class MainMenu extends Canvas
{
private int SCREEN_WIDTH = this.getWidth();
private int SCREEN_HEIGHT = this.getHeight();
public int menuindex = 0;
private int setindex= 0;
private Game game;
private String menustr[] = new String[4];
private String setstr[] = new String[4];
public MainMenu(Game game)
{
this.game = game;
try
{
setFullScreenMode(true);
menustr[0] = "开始";
menustr[1] = "设置";
menustr[2] = "退出";
menustr[3] = "关于";
setstr[0] = "简单";
setstr[1] = "普通";
setstr[2] = "困难";
setstr[3] = "返回";
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
protected void keyPressed(int key)
{
if(menuindex < 5)
{
switch (getGameAction(key))
{
case Canvas.UP:
menuindex --;
if(menuindex < 0) menuindex = 3;
break;
case Canvas.DOWN:
menuindex ++;
if(menuindex > 3) menuindex = 0;
break;
case Canvas.FIRE:
switch(menuindex)
{
case 0:
// 开始游戏
this.game.startmandown();
break;
case 1:
// 设置难度
menuindex = 5;
break;
case 2:
// 退出
this.game.exitGame();
break;
case 3:
// 关于
menuindex = 4;
break;
case 4:
//从关于中退出
menuindex = 3;
break;
}
break;
}
}
else
{
switch (getGameAction(key))
{
case Canvas.UP:
setindex --;
if(setindex < 0) setindex = 3;
break;
case Canvas.DOWN:
setindex ++;
if(setindex > 3) setindex = 0;
break;
case Canvas.FIRE:
switch(setindex)
{
case 0:
// 简单
this.game.man_mov_x = 3;
this.game.man_mov_y = 3;
this.game.obj_mov = 2;
this.game.startmandown();
break;
case 1:
// 一般
this.game.man_mov_x = 3;
this.game.man_mov_y = 3;
this.game.obj_mov = 4;
this.game.startmandown();
break;
case 2:
// 困难
this.game.man_mov_x = 4;
this.game.man_mov_y = 4;
this.game.obj_mov = 5;
this.game.startmandown();
break;
case 3:
// 返回
setindex = 0;
menuindex = 1;
break;
}
break;
}
}
this.repaint();
}
protected void sizeChanged(int w, int h)
{
SCREEN_WIDTH = w ;
SCREEN_HEIGHT = h ;
}
public void paint(Graphics graphics)
{
if(menuindex < 4)
{
graphics.setColor(96,57,19);
graphics.fillRect(0,0,SCREEN_WIDTH,SCREEN_HEIGHT);
graphics.clipRect(0,0,SCREEN_WIDTH,SCREEN_HEIGHT);
for(int i =0;i < 4;i++)
{
if(i == menuindex)
{
graphics.setColor(218,218,218);
graphics.drawString(menustr[i],this.getWidth()/2,this.getHeight()/6*(1+i),Graphics.HCENTER|Graphics.TOP);
}
else
{
graphics.setColor(198,156,109);
graphics.drawString(menustr[i],this.getWidth()/2,this.getHeight()/6*(1+i),Graphics.HCENTER|Graphics.TOP);
}
}
}
else if(menuindex == 4)
{
graphics.setColor(96,57,19);
graphics.fillRect(0,0,SCREEN_WIDTH,SCREEN_HEIGHT);
graphics.clipRect(0,0,SCREEN_WIDTH,SCREEN_HEIGHT);
graphics.setColor(198,156,109);
graphics.drawString("雨石工作室",this.getWidth()/2,this.getHeight()/5*1,Graphics.HCENTER|Graphics.TOP);
graphics.drawString("设计开发",this.getWidth()/2,this.getHeight()/5*2,Graphics.HCENTER|Graphics.TOP);
}
else if(menuindex == 5)
{
graphics.setColor(96,57,19);
//graphics.fillRect(0,0,this.getWidth(),this.getHeight());
//graphics.clipRect(0,0,this.getWidth(),this.getHeight());
graphics.fillRect(0,0,SCREEN_WIDTH,SCREEN_HEIGHT);
graphics.clipRect(0,0,SCREEN_WIDTH,SCREEN_HEIGHT);
for(int i =0;i < 4;i++)
{
if(i == setindex)
{
graphics.setColor(218,218,218);
graphics.drawString(setstr[i],this.getWidth()/2,this.getHeight()/6*(1+i),Graphics.HCENTER|Graphics.TOP);
}
else
{
graphics.setColor(198,156,109);
graphics.drawString(setstr[i],this.getWidth()/2,this.getHeight()/6*(1+i),Graphics.HCENTER|Graphics.TOP);
}
}
}
}
}
class ManDown extends GameCanvas implements Runnable
{
private static int MAN_WIDTH = 16;
private static int MAN_HEIGHT = 16;
private static int OBJ_WIDTH = 48;
private static int OBJ_HEIGHT = 8;
private static int SIDE_WIDTH = 8;
private static int SIDE_HEIGHT = 16;
private static int MAX_LIFE = 15;
//private int SCREEN_WIDTH = this.getWidth();
//private int SCREEN_HEIGHT = this.getHeight();
private int SCREEN_WIDTH;
private int SCREEN_HEIGHT;
public int MAN_MOV_X;
public int MAN_MOV_Y;
public int OBJ_MOV;
private Random rnd;
private Game game;
private Man man;
private Image I_man,I_obj1,I_obj2,I_side,I_top;
private Image image_temp;
private Thread thread;
private int man_picIndex = 0;
public int position_obj_x[] = new int[16];
public int position_obj_y[] = new int[16];
public int position_man_x;
public int position_man_y;
public int position_side_y = 0;
public int direction = 0;
public int directionup = 0;
public int directionhit = 0;
public int time_num = 0;
public int life;
public int level = 0;
public int life_change = 0;
public int level_change = 0;
private Image I_tmp[] = new Image[5];
private int Int_tmp[] = new int[16];
public boolean isgameover = false;
public boolean running = true;
public ManDown(Game game, Man man)
{
super(true);
thread = new Thread(this);
rnd = new Random();
this.game = game;
this.man = man;
setFullScreenMode(true);
SCREEN_WIDTH = this.getWidth();
SCREEN_HEIGHT = this.getHeight();
try
{
life = MAX_LIFE;
I_man = Image.createImage("/man.png");
I_obj1 = Image.createImage("/obj1.png");
I_side = Image.createImage("/side.png");
I_top = Image.createImage("/top.png");
initobj(16);
}
catch(Exception ex)
{
man.rar_猛男爱好者
版权申诉
146 浏览量
2022-09-23
08:09:39
上传
评论
收藏 183KB RAR 举报
weixin_42651887
- 粉丝: 76
- 资源: 1万+
最新资源
- pta题库答案c语言之排序4统计工龄.zip
- pta题库答案c语言之树结构7堆中的路径.zip
- pta题库答案c语言之树结构3TreeTraversalsAgain.zip
- pta题库答案c语言之树结构2ListLeaves.zip
- pta题库答案c语言之树结构1树的同构.zip
- 基于C++实现民航飞行与地图简易管理系统可执行程序+说明+详细注释.zip
- pta题库答案c语言之复杂度1最大子列和问题.zip
- 三维装箱问题(Three-Dimensional Bin Packing Problem,3D-BPP)是一个经典的组合优化问题
- 以下是一些关于Linux线程同步的基本概念和方法.txt
- 以下是一个简化的示例,它使用pygame库来模拟烟花动画的框架.txt
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0