?? bbb.java~212~
字號:
package moming;
import javax.microedition.lcdui.*;
import java.util.Random;
/**
*/
public class bbb extends Canvas implements CommandListener {
int x;
int y;
part[] sb = new part[100];
boolean opcl=true;//
boolean run=true;
int lose = 0 ;
int wound = 0;
int none =0;
int windw=0;
int windh=0;
public bbb() {
// do{
ram();
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
// }while(opcl);
}
private void setPlane(){
int co = 0;
int plane[] = new int[120];
int count[] = new int[3];
Plane plane1,plane2,plane3;
Random rand = new Random(System.currentTimeMillis());
do{
for (int m = 0;m<120 ;m++ )//將數組的各個位清0
{
plane[m] = m;
}
count[0] = (Math.abs(rand.nextInt())%120);
plane1 = new Plane(plane[count[0]]);
for (int m = 0;m<120 ;m++ )
{
if(plane1.isTrue(m))
{
plane[co] = m;//將可放置的飛機的號放在數組內;
co++;
}
}
count[1] = (Math.abs(rand.nextInt())%co);
plane2 = new Plane(plane[count[1]]);
co = 0;
for (int m = 0;m<120 ;m++ )
{
if(plane1.isTrue(m)&&plane2.isTrue(m))
{
plane[co] = m;//將可放置的飛機的號放在數組內;
co++;
}
}
}
while(co==0);
count[2] = (Math.abs(rand.nextInt())%co);
plane3 = new Plane(plane[count[2]]);
sb[plane1.getX(0)].notes=1;//Label("2");
sb[plane2.getX(0)].notes=1;//Label("2");
sb[plane3.getX(0)].notes=1;//Label("2");
for (int m = 1;m<10 ;m++ )
{
sb[plane1.getX(m)].notes=2;//Label("3");
sb[plane2.getX(m)].notes=2;//Label("3");
sb[plane3.getX(m)].notes=2;//Label("3");
}
}
private void ram(){//初始化屏幕
String sbstring="ABCDEFGHIJ";
for(int i=0;i<100;i++){
sb[i] = new part(); ;
sb[i].notes=0;//
}
for( int i=0 ; i<100 ; i++ ) {
if(i<10){
sb[i].word = Integer.toString(i).charAt(0);
sb[i].notes =4;
}
else{
if (i % 10 == 0){
sb[i].word = sbstring.charAt(i / 10 - 1);
sb[i].notes =4;
}
else
sb[i].word = ' ';
}
sb[i].inv =false;//標識是否按下鼠標
sb[i].iup =false;//標識鼠標彈起
sb[i].dis =false;
}
sb[0].word =' ';
setPlane();
}
private int getState(int ix,int iy){//用來計算鼠標點在哪個方格之上的方法
int i,j;
i=getI(ix);
j=getI(iy);
if(i>=10||j>=10)
return 150;
return i+j*10;
}
private int getI(int im){
int canvash = getWidth();
canvash = (canvash - 12) / 10; //現在是小格子的邊長
for (int i = 0; i < 10; i++) {
if ((im >= ((canvash + 1) * i + 5)) &&
(im <= (((canvash + 1) * i + 5)) + canvash)) {
canvash = i;
return canvash;
}
}
return 10;
}
public void pointerPressed (int x, int y) {//按下
this.x = x;
this.y = y;
//計算出方格位置修改PART.NORES屬性
if(opcl)
return;
int m=getState(x,y);
if(m==150)
return;
if(sb[m].notes ==3)
return;
if(sb[m].notes ==4)
return;
sb[m].inv=true;
repaint ();
}
public void pointerReleased (int x, int y) {//釋放
this.x = x;
this.y = y;
//計算出方格位置修改PART.NORES屬性
if(opcl){
if((x>5&&x<(windw/2-1))&&y>((windh*8+13))&&y<(windh*10+15)){
opcl=false;
ram();
repaint();
}
else
if(x>(windw/2+1)&&x<windw&&y>(windh*8+13)&&y<(windh*10+15)){
//;//out
opcl=false;
aaa.quitApp();
}
return;
}
int m=getState(x,y);
if(m==150)
return;
if(sb[m].notes ==3)
return;
if(sb[m].notes ==4)
return;
// sb[m].iup =true;
sb[m].dis =true;
repaint ();
}
public void pointerDragged (int x, int y) {//牽引的
this.x = x;
this.y = y;
//計算出方格位置修改PART.NORES屬性
if(opcl)
return;
int m=getState(x,y);
if(m==150)
return;
if(sb[m].notes ==3)
return;
if(sb[m].notes ==4)
return;
sb[m].inv=true;
repaint ();
}
private void jbInit() throws Exception {
// Set up this Displayable to listen to command events
setCommandListener(this);
// add the Exit command
addCommand(new Command("Exit", Command.EXIT, 1));
}
public void commandAction(Command command, Displayable displayable) {
/** @todo Add command handling code */
if (command.getCommandType() == Command.EXIT) {
// stop the MIDlet
aaa.quitApp();
}
}
protected void paint(Graphics g){
/**@todo Add paint codes */
//String sbstring="RATEYOURMINDPAL";
//background
g.setColor(0xb4ffff);
int canvasw=getWidth();
windw=canvasw;//????????????????????????????????
int canvash=getHeight();
g.fillRect(0,0,canvasw,canvash);//填充背景
//計算文字的寬度、高度
Font ft=Font.getFont(Font.FACE_MONOSPACE,Font.STYLE_PLAIN ,Font.SIZE_MEDIUM );
int wordw=ft.charWidth('M');
int wordh=ft.getHeight() ;//字符的大小
g.setColor(0);
g.drawRect(1,1,canvasw-3,canvasw-3);//畫外框
canvash=(canvasw-12)/10;//現在是小格子的邊長
windh=canvash;
int xi,yi,dx,dy,wordc=0xffffff;
xi =(canvash-wordw)/2;
yi =(canvash-wordh)/2;
if(opcl&run){//開始時要顯示的東西
run=false;
g.setColor(0xffffff);//8c96a0);//背景顏色
g.fillRect(0,canvash+5,canvasw,(canvash+1)*9) ;
g.setColor(0xff0000);
g.drawString("軟件版本:1.3",10,canvash+28,Graphics.TOP | Graphics.LEFT );
g.drawString("作者:想飛",10,(canvash+1)*2+28,Graphics.TOP | Graphics.LEFT );
lose=lose+wound+none;
g.drawString("QQ:646217792"+lose,10,(canvash+1)*3+28,Graphics.TOP | Graphics.LEFT );
g.drawString("郵箱:kgsn007@163.com",10,(canvash+1)*4+28,Graphics.TOP | Graphics.LEFT );
g.drawString("如果建議請與我聯系",10,(canvash+1)*5+28,Graphics.TOP | Graphics.LEFT );
g.setColor(0);//按鈕顏色
g.fillRect(5,(canvash+1)*8+5,canvasw/2-6,(canvash+1)*2) ;
g.fillRect(canvasw/2+1,(canvash+1)*8+5,canvasw/2-6,(canvash+1)*2) ;
g.setColor(0xffffff);//字體顏色
g.drawString("開始",canvasw/8+10,(canvash+1)*8+18,Graphics.TOP | Graphics.LEFT );
g.drawString("結束",5*canvasw/8+20,(canvash+1)*8+18,Graphics.TOP | Graphics.LEFT );
return;
}
for(int i=0;i<100;i++){
//x=sb[i].x;y=sb[i].y;
//計算各個邊框的左上角坐標
dx=i%10;
dy=i/10;
dx=(canvash+1)*dx+5;
dy=(canvash+1)*dy+5;
if(sb[i].notes ==4){
g.setColor(0) ;
}
else
if(sb[i].inv){//按下變色以區分
g.setColor(0xff0000);
sb[i].inv =false;
}
else
if(sb[i].dis){
if(sb[i].notes ==2){
if(sb[i].word !='●')
wound++;
sb[i].word = '●'; //傷
wordc=0xff0000;
}
if(sb[i].notes ==0){
if(sb[i].word !='○')
none++;
sb[i].word = '○'; //空
}
if(sb[i].notes ==1){
if(sb[i].word !='★')
lose++;
sb[i].word = '★'; //落
wordc=0xff0000;
if(lose==3){
opcl=true;
g.setColor(0xffffff);//8c96a0);//背景顏色
g.fillRect(0,canvash+5,canvasw,(canvash+1)*9) ;
g.setColor(0xff0000);
g.drawString("游戲結束",10,canvash+28,Graphics.TOP | Graphics.LEFT );
g.drawString("您的成績是:",10,(canvash+1)*2+28,Graphics.TOP | Graphics.LEFT );
lose=lose+wound+none;
g.drawString("開槍總數:"+lose,10,(canvash+1)*3+28,Graphics.TOP | Graphics.LEFT );
g.drawString("傷:"+wound,10,(canvash+1)*4+28,Graphics.TOP | Graphics.LEFT );
g.drawString("空:"+none,10,(canvash+1)*5+28,Graphics.TOP | Graphics.LEFT );
g.setColor(0);//按鈕顏色
g.fillRect(5,(canvash+1)*8+5,canvasw/2-6,(canvash+1)*2) ;
g.fillRect(canvasw/2+1,(canvash+1)*8+5,canvasw/2-6,(canvash+1)*2) ;
g.setColor(0xffffff);//字體顏色
g.drawString("開始",canvasw/8+10,(canvash+1)*8+18,Graphics.TOP | Graphics.LEFT );
g.drawString("結束",5*canvasw/8+20,(canvash+1)*8+18,Graphics.TOP | Graphics.LEFT );
lose=0;
wound=0;
none=0;
return;
}
}
g.setColor(0xb4ffff);
}
else
g.setColor(0x8c96a0);
//邊框
g.fillRect(dx,dy,canvash,canvash) ;
dx +=xi;
dy +=yi;
//字母
g.setColor(wordc);
g.drawChar(sb[i].word,dx,dy,Graphics.TOP | Graphics.LEFT );
wordc=0xffffff;
}
//g.fillRect(5,5,canvash,canvash) ;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -