JAVA迷宫小游戏源代码
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
public mMaze(){addKeyListener(new KeyAdapter(){ public void keyPressed(KeyEvent e){ if(e.getKeyCode()== KeyEvent.VK_UP){ System.out.println("\n Go Up"); if(map[(yl-1)*29+xl]!=1) yl-=1; } else if(e.getKeyCode()== KeyEvent.VK_DOWN){ System.out.println("\n Go Down"); if(map[(yl+1)*29+xl]!=1) yl+=1; } else if(e.getKeyCode()== KeyEvent.VK_LEFT){ System.out.println("\n Go Left"); if(map[yl*29+(xl-1)]!=1) xl-=1; } else if(e.getKeyCode()== KeyEvent.VK_RIGHT){ System.out.println("\n Go Right"); if(map[yl*29+(xl+1)]!=1) xl+=1; } else System.out.println(e.getKeyChar()); if(y==27&&x==28) System.out.println("\n You Win~!"); repaint(); } } ); setSize(890,910); setVisible(true); setLocation(400,200); addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ dispose(); System.exit(0); } } ); }
1,0,0,0,1,0,0,0,1,0,1,0,0,0,0,0,1,0,1,0,1,0,0,0,1,0,1,0,1, 1,1,1,0,1,0,1,1,1,0,1,1,1,1,1,0,1,0,1,0,1,1,1,1,1,0,1,0,1, 1,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,1,0,1, 1,0,1,1,1,1,1,0,1,0,1,1,1,0,1,1,1,1,1,1,1,1,1,0,1,0,1,0,1, 1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,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,
};
int[] map1 ={ 1,1,1,1,1,1,1,1,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();
MapArray MapArray=new MapArray();
int[] map = MapArray.getMapArray(mapI); static ImageIcon wall= new ImageIcon("wall.jpg"); final ImageIcon tortoise= new ImageIcon("tortoise.gif"); int xl=0,yl=1,speed=30; int x=0,y=1;
} }
public class Maze{ public static void main(String[] args){ new mMaze(); }}
回复
2楼 2013-05-16 10:34
删除 |
LaoCooon
class MapArray{
public int[] ห้องสมุดไป่ตู้etMapArray(int i){
public void paint(Graphics g){ g.drawImage(tortoise.getImage(), xl*speed+8, yl*speed+30, null); int i=0,j=0; for ( i = 0; i < 29; i++) for(j=0;j<29;j++) if(map[i*29+j]==1) g.drawImage(wall.getImage(), j*30+8, i*30+30, null);
帮朋友写的迷宫小游戏程序 java
//作者:LaoCooon
import java.awt.Graphics; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import java.awt.event.*; import javax.swing.*; import java.awt.*; class mMaze extends Frame { Color redColor; Random Random=new Random();
1,0,0,0,1,0,0,0,1,0,1,0,0,0,0,0,1,0,1,0,1,0,0,0,1,0,1,0,1, 1,1,1,0,1,0,1,1,1,0,1,1,1,1,1,0,1,0,1,0,1,1,1,1,1,0,1,0,1, 1,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,1,0,1, 1,0,1,1,1,1,1,0,1,0,1,1,1,0,1,1,1,1,1,1,1,1,1,0,1,0,1,0,1, 1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,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,
};
int[] map1 ={ 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, 0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1, 1,0,1,1,1,0,1,1,1,0,1,0,1,0,1,1,1,0,1,0,1,1,1,0,1,0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1,1,0,1,0,1,1,1,1,1,1,1,0,1,0,1, 1,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,1,0,1, 1,0,1,0,1,1,1,0,1,0,1,1,1,0,1,0,1,1,1,0,1,0,1,0,1,1,1,1,1, 1,0,1,0,0,0,0,0,1,0,1,0,1,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,1, 1,0,1,1,1,1,1,1,1,0,1,0,1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,0,1, 1,0,1,0,0,0,1,0,0,0,1,0,1,0,1,0,1,0,0,0,0,0,1,0,0,0,0,0,1, 1,0,1,1,1,0,1,0,1,1,1,0,1,0,1,1,1,0,1,1,1,0,1,0,1,1,1,0,1, 1,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,1,0,1,0,1,0,1,0,1,0,0,0,1, 1,0,1,0,1,1,1,1,1,1,1,0,1,1,1,0,1,0,1,0,1,0,1,0,1,1,1,1,1, 1,0,1,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,1,0,1,0,0,0,1, 1,0,1,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,1,1,0,1,0,1,0,1,0,1, 1,0,0,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,0,0,0,0,1,0,0,0,1,0,1, 1,1,1,1,1,1,1,0,1,0,1,1,1,0,1,1,1,1,1,1,1,0,1,1,1,1,1,0,1, 1,0,0,0,0,0,1,0,1,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,1,0,1, 1,0,1,1,1,1,1,0,1,0,1,0,1,1,1,1,1,1,1,1,1,0,1,0,1,0,1,0,1,
int mapI=Random.getRandom();
MapArray MapArray=new MapArray();
int[] map = MapArray.getMapArray(mapI); static ImageIcon wall= new ImageIcon("wall.jpg"); final ImageIcon tortoise= new ImageIcon("tortoise.gif"); int xl=0,yl=1,speed=30; int x=0,y=1;
} }
public class Maze{ public static void main(String[] args){ new mMaze(); }}
回复
2楼 2013-05-16 10:34
删除 |
LaoCooon
class MapArray{
public int[] ห้องสมุดไป่ตู้etMapArray(int i){
public void paint(Graphics g){ g.drawImage(tortoise.getImage(), xl*speed+8, yl*speed+30, null); int i=0,j=0; for ( i = 0; i < 29; i++) for(j=0;j<29;j++) if(map[i*29+j]==1) g.drawImage(wall.getImage(), j*30+8, i*30+30, null);
帮朋友写的迷宫小游戏程序 java
//作者:LaoCooon
import java.awt.Graphics; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import java.awt.event.*; import javax.swing.*; import java.awt.*; class mMaze extends Frame { Color redColor; Random Random=new Random();