华容道java代码解释 华容道程序( 六 )


man.setLocation(man.left_x, man.left_y);
man.rect.setLocation(man.left_x, man.left_y);
// 判断是否和其它人物或上边界出现重叠,如果出现重叠就退回50个单位距离 。
for (int i = 0; i10; i++) {
if ((man.rect.intersects(people[i].rect))(man.number != i)) {
man.left_y = man.left_y + 50;
man.setLocation(man.left_x, man.left_y);
man.rect.setLocation(man.left_x, man.left_y);
}
}
if (man.rect.intersects(above)) {
man.left_y = man.left_y + 50;
man.setLocation(man.left_x, man.left_y);
man.rect.setLocation(man.left_x, man.left_y);
}
}
if (e.getKeyCode() == KeyEvent.VK_LEFT) {
man.left_x = man.left_x - 50; // 向左前进50个单位 。
man.setLocation(man.left_x, man.left_y);
man.rect.setLocation(man.left_x, man.left_y);
// 判断是否和其它人物或左边界出现重叠,如果出现重叠就退回50个单位距离 。
for (int i = 0; i10; i++) {
if ((man.rect.intersects(people[i].rect))(man.number != i)) {
man.left_x = man.left_x + 50;
man.setLocation(man.left_x, man.left_y);
man.rect.setLocation(man.left_x, man.left_y);
}
}
if (man.rect.intersects(left)) {
man.left_x = man.left_x + 50;
man.setLocation(man.left_x, man.left_y);
man.rect.setLocation(man.left_x, man.left_y);
}
}
if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
man.left_x = man.left_x + 50; // 向右前进50个单位 。
man.setLocation(man.left_x, man.left_y);
man.rect.setLocation(man.left_x, man.left_y);
// 判断是否和其它人物或右边界出现重叠,如果出现重叠就退回50个单位距离 。
for (int i = 0; i10; i++) {
if ((man.rect.intersects(people[i].rect))(man.number != i)) {
man.left_x = man.left_x - 50;
man.setLocation(man.left_x, man.left_y);
man.rect.setLocation(man.left_x, man.left_y);
}
}
if (man.rect.intersects(right)) {
man.left_x = man.left_x - 50;
man.setLocation(man.left_x, man.left_y);
man.rect.setLocation(man.left_x, man.left_y);
}
}
}
public void keyTyped(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
}
public void actionPerformed(ActionEvent e) {
this.removeAll();
this.init();
}
}
求用C语言代吗编写一个华容道的游戏出来 。最好带每步的解释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);//人物华容道java代码解释的颜色背景是黄色
this.number=number;
c=getBackground();
addFocusListener(this);//好像是焦点监听器
}
public void focusGained(FocusEvent e)
{
setBackground(Color.red);//只要单击该按钮则按钮变颜色
}
public void focusLost(FocusEvent e) {
setBackground(c);//上一个按钮回复原先华容道java代码解释的颜色
}
}
//华容道总类
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为可见华容道java代码解释 , 默认为不可见
validate();
addWindowListener(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);

推荐阅读