华容道 小游戏 源代码

时间:2014-01-22 08:36:53
【文件属性】:

文件名称:华容道 小游戏 源代码

文件大小:25KB

文件格式:ZIP

更新时间:2014-01-22 08:36:53

华容道

package 华容道; import java.awt.*; import java.awt.event.*; //主函数 public class Main { public static void main(String[] args) { new Hua_Rong_Road(); } } //人物按钮颜色 class Person extends Button implements FocusListener{ int number; Color c=new Color(255,245,170); Person(int number,String s) { super(s); setBackground(c);//人物的颜色背景是黄色 this.number=number; c=getBackground(); addFocusListener(this);//好像是焦点监听器 } public void focusGained(FocusEvent e) { setBackground(Color.red);//只要单击该按钮则按钮变颜色 } public void focusLost(FocusEvent e) { setBackground(c);//上一个按钮回复原先的颜色 } } //华容道总类 class Hua_Rong_Road extends Frame implements MouseListener,KeyListener,ActionListener{ Person person[] = new Person[10]; Button left,right,above,below; Button restart = new Button("Start");//重新开始按钮 public Hua_Rong_Road() { init(); setBounds(100,100,320,360); setVisible(true);//设置Frame为可见,默认为不可见 validate(); addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } } ); } public void init() { setLayout(null); add(restart); restart.setBounds(100, 320, 120, 25); restart.addActionListener(this); String name[]={"我","陆逊","姜维","陈宫","许攸","邓艾","周瑜","庞统","诸葛亮","贾诩"}; for(int k=0;kh/2) { go(man,below); } if(yw/2) { go(man,right); } } public void mouseReleased(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public void mouseClicked(MouseEvent e){} public void go(Person man,Button direction) { boolean move=true; Rectangle manRect=man.getBounds(); int x=man.getBounds().x; int y=man.getBounds().y; if(direction==below) y=y+50; else if(direction==above) y=y-50; else if(direction==left) x=x-50; else if(direction==right) x=x+50; manRect.setLocation(x,y); Rectangle directionRect=direction.getBounds(); for(int k=0;k<10;k++) { Rectangle personRect=person[k].getBounds(); if((manRect.intersects(personRect))&&(man.number!=k)) { move=false; } } if(manRect.intersects(directionRect)) { move=false; } if(move==true) { man.setLocation(x,y); } } public void actionPerformed(ActionEvent e) { dispose(); new Hua_Rong_Road(); } }


【文件预览】:
小游戏
----使用说明书.txt(69B)
----华容道()
--------test()
--------dist()
--------manifest.mf(85B)
--------src()
--------build()
--------build.xml(4KB)
--------nbproject()
----快捷方式 到 华容道.jar.lnk(657B)

网友评论

  • 很不错的源码,布局什么的可以学习
  • 不错 ,很好的案例
  • 还不错,对我有一定的帮助!