| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 688 人关注过本帖
标题:各位兄弟姐妹 谁能帮我看看程序出错在哪
只看楼主 加入收藏
一根草
Rank: 1
等 级:新手上路
帖 子:2
专家分:1
注 册:2009-8-12
收藏
 问题点数:0 回复次数:0 
各位兄弟姐妹 谁能帮我看看程序出错在哪
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Demo;

import
import javax.microedition.lcdui.Display;
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;
import javax.microedition.lcdui.game.TiledLayer;
import javax.microedition.media.Manager;
import javax.microedition.media.control.ToneControl;

/**
 *
 * @author Administrator
 */
public class FCanvas extends GameCanvas implements Runnable {
    private Display display;
    private LayerManager layers;
    private TiledLayer backgroundLayer;
    private TiledLayer barrierLayer;
    private Sprite personSprite;
    private int xView;
    private int yView;
    private boolean sleeping;
    private long frameDelay;
    private int inputDelay;


    public FCanvas(Display d){
        super(true);
        display=d;
        frameDelay=33;
        inputDelay=0;
    }
    public void start(){
        //set the canvas as current screen
        display.setCurrent(this);

        // Create the background and barrier tiled layers
      
            //fightmap=new Fightmap();
            //backgroundLayer = new TiledLayer();
           // backgroundLayer=fightmap.gethkcback();
            //barrierLayer=fightmap.getbarrier();
        try{

        backgroundLayer = new TiledLayer(16, 10, Image.createImage("/action.png"), 30, 30);
        //16*10块30*30像素每块
        barrierLayer = new TiledLayer(16, 10, Image.createImage("/barrier.png"), 30, 30);
            //16*10块30*30像素每块
            }

        catch (IOException e) {
                System.err.println("Failed loading images!");
            }
        int backgroundMap[][]  = {
                {1,2,3,4,5,6,7,8,3,4,5,6,7,8,9,10},
                {16,17,18,19,20,21,22,23,18,19,20,21,22,23,24,25},
                {11,12,13,14,12,13,11,14,11,12,13,14,11,12,13,14},
                {26,27,28,27,28,27,28,27,28,27,28,27,28,27,28,29},
                {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                {15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15},
                {30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30},
            };
          for (int  row = 0; row < backgroundMap.length; row++) {
                for(int column=0;column<backgroundMap[row].length;column++){
               /* 下面这里为什么编译不能通过那??? 上面的这个二维数组只能执行到第二列就不行了 */            
                /* */backgroundLayer.setCell(column, row,backgroundMap[row][column]);//向地图中添加每一块贴砖
                }
           }
          int[][] barrierMap = {
                {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
                {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
            };
           for (int row = 0; row < barrierMap.length; row++){
               for(int column=0;column<barrierMap[row].length;column++){
                barrierLayer.setCell(column, row, barrierMap[row][column]);//向地图中添加每一块贴砖
                }
           }
           try {
                    personSprite = new Sprite(Image.createImage("/Person.png"), 20, 24);
                }
           catch (IOException e) {
                    System.err.println("Failed loading images!");
                }
                //创建图层
           layers=new LayerManager();
           layers.append(personSprite);
           layers.append(barrierLayer);
           layers.append(backgroundLayer);
           xView = (backgroundLayer.getWidth() - getWidth()) / 2; //将可视窗口的X坐标设定为中央
           yView = (backgroundLayer.getHeight() - getHeight()) / 2; //将可视窗口的Y坐标设定为中央
           layers.setViewWindow(xView, yView, getWidth(), getHeight()); //设定可视窗口的位置和大小
           personSprite.setPosition(xView + (getWidth() - personSprite.getWidth()) / 2,
           yView + (getHeight() - personSprite.getHeight()) / 2);
           sleeping = false;
           Thread t = new Thread(this);
           t.start();

    }
    public void stop(){
        sleeping=true;
    }


    public void run() {
        Graphics g = getGraphics();

    // The main game loop
    while (!sleeping) {
      update();
      draw(g);
      try {
        Thread.sleep(frameDelay);
      }
      catch (InterruptedException ie) {}
    }
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    private void draw(Graphics g) {
        layers.paint(g, 0, 0);

    // Flush the offscreen graphics buffer
    flushGraphics();

       // throw new UnsupportedOperationException("Not yet implemented");
       // throw new UnsupportedOperationException("Not yet implemented");
    }

    private void update() {
        // Process user input to move the background layer and animate the person
        if (++inputDelay > 2) {
          int keyState = getKeyStates();
          int xMove = 0, yMove = 0;
          if ((keyState & LEFT_PRESSED) != 0)
            xMove = -12;
          else if ((keyState & RIGHT_PRESSED) != 0)
            xMove = 12;
          if ((keyState & UP_PRESSED) != 0)
            yMove = -12;
          else if ((keyState & DOWN_PRESSED) != 0)
            yMove = 12;
          if (xMove != 0 || yMove != 0) {
            layers.setViewWindow(xView + xMove, yView + yMove, getWidth(), getHeight());
            personSprite.move(xMove, yMove);
            personSprite.nextFrame();
          }
          if(personSprite.collidesWith(barrierLayer, true)){
              // Play a collision sound
            try {
            Manager.playTone(ToneControl.C4 + 12, 100, 100);

            }
            catch (Exception e) {
            }
        }
          else {
            // If there is no collision, commit the changes to the view window position
            xView += xMove;
            yView += yMove;
        }
        //throw new UnsupportedOperationException("Not yet implemented");

   
        
      // Reset the input delay
      inputDelay = 0;
    }
}
}



这里是MIDlet类
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Demo;

import javax.microedition.
import javax.microedition.
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.midlet.*;

/**
 * @author Administrator
 */
public class FightMidlet extends MIDlet implements CommandListener {
    private FCanvas canvas;
    private Display display;
    public void startApp() {
        //if(canvas==null){
        display=Display.getDisplay(this);

        canvas = new FCanvas(Display.getDisplay(this));
        canvas.start();
        display.setCurrent(canvas);
            //Display.getDisplay(this).setCurrent(canvas);
        Command exitCommand = new Command("退出", Command.EXIT, 0);
        canvas.addCommand(exitCommand);
        canvas.setCommandListener(this);
       // }
        
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
        canvas.stop();
    }

    public void commandAction(Command c, Displayable d) {
        if (c.getCommandType() == Command.EXIT) {
          destroyApp(true);
          notifyDestroyed();

        //throw new UnsupportedOperationException("Not supported yet.");
        }
    }
}
搜索更多相关主题的帖子: 谢谢各位了 
2009-08-12 11:38
快速回复:各位兄弟姐妹 谁能帮我看看程序出错在哪
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.033615 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved