晨曦kry 2016-11-24 13:15 采纳率: 0%
浏览 835

为什么运行不出来,但是不报错

package Game;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;

public class XianjianFrame extends JFrame implements Runnable{

private static final Graphics g = null;
BufferedImage mapImage;
int mapData[][];
BufferedImage lxyUpImage[]= new BufferedImage[8];
BufferedImage lxyDownImage[]= new BufferedImage[8];
BufferedImage lxyLeftImage[]= new BufferedImage[8];
BufferedImage lxyRightImage[]= new BufferedImage[8];

BufferedImage lxyImage;


int wcsIndex =0;
int tsIndex1 =0;
int lxyIndex;

int mapX = -300;
int mapY = -300;
int awsmapX = 450;
int awsmapY = 500;


   BufferedImage awsImage[]=new BufferedImage[17];
   BufferedImage dsImage[]=new BufferedImage[44];
   BufferedImage azImage[]=new BufferedImage[6];
   BufferedImage mjImage[]=new BufferedImage[6];
   BufferedImage tsImage[]=new BufferedImage[4];
   BufferedImage wcImage[]=new BufferedImage[14];
   BufferedImage xjImage[]=new BufferedImage[2];
   int awsIndex1=0;
   int dsIndex=0;
   int azIndex=0;
   int mjIndex=0;
   int tsIndex=0;
   int wcIndex=0;
   int xjIndex=0;

int awsIndex = 0;
private int lxyX;
private int lxyY;
public XianjianFrame() {
    try {
        mapImage=ImageIO.read(new File("E:/仙剑/李家村/map.png"));
        mapData= new int[mapImage.getWidth()][mapImage.getHeight()];
        BufferedImage image =ImageIO.read(new File("E:/仙剑/李家村/mapData.png"));
        for (int i = 0; i <awsImage.length; i++) {
        awsImage[i]=ImageIO.read(new File("E:/仙剑/阿旺婶/"+i+".png"));
        }
        for (int i = 0; i < dsImage.length; i++) {
        dsImage[i]  =ImageIO.read(new File("E:/仙剑/茅山道士/"+i+".png"));
        }
        for (int i = 0; i <azImage.length; i++) {
        azImage[i]=ImageIO.read(new File("E:/仙剑/阿朱喂鸡/"+i+".png"));
        }
        for (int i = 0; i <mjImage.length; i++) {
        mjImage[i]=ImageIO.read(new File("E:/仙剑/母鸡/"+i+".png"));
        }
        for (int i = 0; i <tsImage.length; i++) {
        tsImage[i]=ImageIO.read(new File("E:/仙剑/跳绳/"+i+".png"));
        }
        for (int i = 0; i <wcImage.length; i++) {
        wcImage[i]=ImageIO.read(new File("E:/仙剑/旺财嫂/"+i+".png"));
        }
        for (int i = 0; i <xjImage.length; i++) {
        xjImage[i]=ImageIO.read(new File("E:/仙剑/小鸡/"+i+".png"));
        }






        for (int  x=0;x<mapImage .getWidth() ;x++){
        for (int  y=0;y<mapImage .getHeight();y++){
        int color = image. getRGB(x, y);
        if(color == - 16777216)
        mapData[x][y]=1;
        }
        }
        for(int i=0;i<lxyDownImage.length;i++){
        lxyUpImage[i]=ImageIO.read(new File("E:/仙剑/李逍遥/李逍遥上/"+ i +".png"));
        lxyDownImage[i]=ImageIO.read(new File("E:/仙剑/李逍遥/李逍遥下/"+ i +".png"));
        lxyLeftImage[i]=ImageIO.read(new File("E:/仙剑/李逍遥/李逍遥左/"+ i +".png"));
        lxyRightImage[i]=ImageIO.read(new File("E:/仙剑/李逍遥/李逍遥右/"+ i +".png"));

}

        } catch (Exception e) {
        e.printStackTrace();
        }

}
public void paint(Graphics frameG){
        BufferedImage bufferImage =new BufferedImage(getWidth(), getHeight(), 1);
        Graphics bufferG = bufferImage. getGraphics();

        mapX=(this.getWidth()-lxyImage.getWidth())/2-lxyX;
           mapY=(this.getHeight()-lxyImage.getHeight())/2-lxyY;
           bufferG.drawImage(mapImage, mapX,mapY,null);
           bufferG.drawImage(awsImage[awsIndex],682+mapX,592+mapY,null);
           bufferG.drawImage(dsImage[dsIndex],700+mapX,375+mapY,null);

           bufferG.drawImage(azImage[azIndex],500+mapX,500+mapY,null);
           bufferG.drawImage(mjImage[mjIndex],540+mapX,555+mapY,null);
           bufferG.drawImage(tsImage[tsIndex],900+mapX,600+mapY,null);
           bufferG.drawImage(wcImage[wcIndex],800+mapX,570+mapY,null);
           bufferG.drawImage(xjImage[xjIndex],510+mapX,590+mapY,null);

           bufferG.drawImage(lxyImage, lxyX+mapX,lxyY+mapY,null);
        frameG.drawImage( bufferImage,0,0,null);//双缓冲
        } 

        @Override

        protected void processKeyEvent(KeyEvent e) {
            if (e.getID()==401) {
                   lxyIndex ++;
                   if(lxyIndex== lxyUpImage .length){
                  lxyIndex =0;
                   }
                   int code =e.getKeyCode();
                   if(code== 37){
                   lxyX=lxyX-4;

                   for(int y= lxyY+85;y<lxyY + 85+21;y++){
                   if(mapData[lxyX+20][y]==1){
                   lxyX=lxyX+4;
                   break;
                   }

                   }
                   lxyImage = lxyLeftImage[lxyIndex];
                   }else if(code==38){
                   lxyY=lxyY-4;
                   for(int x= lxyX+20;x<lxyX + 20+28;x++){
                   if(mapData[x][lxyY+85]==1){
                   lxyY=lxyY+4;
                   break;
                   }

                   }


                   lxyImage = lxyUpImage[lxyIndex];
                   }else if(code==39){
                   lxyX=lxyX+4;
                   for(int y= lxyY+85;y<lxyY +85+21;y++){
                   if(mapData[lxyX+20+28][y]==1){
                   lxyX=lxyX-4;
                   break;
                   }

                   }

                   lxyImage = lxyRightImage[lxyIndex];
                   }else if (code==40){
                   lxyY=lxyY+4;
                   for(int x= lxyX+20;x<lxyX + 20+28;x++){
                   if(mapData[x][lxyY+85+21]==1){
                   lxyY=lxyY-4;
                   break;
                   }

                   }


                   lxyImage = lxyDownImage[lxyIndex];


                }
                repaint();
                }
        }



@Override
public void run() {

    while(true){
         awsIndex ++;
         if( awsIndex == awsImage.length ){
         awsIndex =0;
         }
         dsIndex ++;
         if( dsIndex == dsImage.length){
         dsIndex=0;
         }
         azIndex ++;
         if( azIndex == azImage.length ){
         azIndex =0;
         }
         mjIndex ++;
         if( mjIndex == mjImage.length ){
         mjIndex =0;
         }
         tsIndex ++;
         if( tsIndex == tsImage.length ){
         tsIndex =0;
         }
         wcIndex ++;
         if( wcIndex == wcImage.length ){
         wcIndex =0;
         }
         xjIndex ++;
         if( xjIndex == xjImage.length ){
         xjIndex =0;
         }

         repaint();

        }

}}
  • 写回答

1条回答 默认 最新

  • zqbnqsdsmd 2016-11-26 15:41
    关注
    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站