⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bbb.java~211~

📁 一个触摸屏手机游戏,内含源代码和PDA安装文件,本人手机MOTOLOLA E680 测试通过.
💻 JAVA~211~
字号:
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"+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 );
            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 + -