資源簡介
給大家學習用,為人機版,電腦比較簡單,給大家學習用,為人機版,電腦比較簡單,給大家學習用,為人機版,電腦比較簡單,

代碼片段和文件信息
package?com;
import?javax.swing.*;
import?java.awt.*;
import?java.awt.event.*;
public?class?Main?extends?Jframe?implements?MouseListener?ActionListener
Runnable?{
/**
?*?@author?小柒
?*/
private?static?final?long?serialVersionUID?=?1L;
private?int?width;//?屏幕寬度
private?int?height;//?屏幕
private?int?color?=?0;//?旗子的顏色標識?0:黑子?1:白子
private?int?Array[][]?=?new?int[18][18];//?0無子?1黑(人)2白(電腦)
JButton?btn1?=?new?JButton(“重置“);
JButton?btn2?=?new?JButton(“取消“);
//?JLabel?jl?=?new?JLabel(“玩家先手“);
private?int?xx?=?215?yy?=?53;//?原點
private?int?w?=?340?h?=?340?panelx?=?600?panely?=?490;//?畫布
//?電腦坐標
private?int?cx?cy;
private?int?grade[][]?=?new?int[18][18];
private?int?side?=?0;
public?Main()?{
Thread?thread?=?new?Thread(this);
thread.start();
this.settitle(“五子棋“);
this.setLayout(null);
width?=?Toolkit.getDefaultToolkit().getScreenSize().width;
height?=?Toolkit.getDefaultToolkit().getScreenSize().height;
this.setBounds((width?-?400)?/?2?(height?-?300)?/?2?panelx?panely);
this.setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
this.addMouseListener(this);//?加入鼠標監聽
//?btn1.addActionListener(this);
//?btn2.addActionListener(this);
//?btn1.setBounds(90?400?80?30);
//?btn2.setBounds(190?400?80?30);
//?jl.setBounds(20?380?80?20);
//?this.add(btn1);
//?this.add(btn2);
//?this.add(jl);
this.setResizable(false);
this.setVisible(true);
gameStart();
}
@Override
public?void?actionPerformed(ActionEvent?e)?{
//?TODO?Auto-generated?method?stub
/*
?*?if?(e.getSource()?==?btn1)?{?gameStart();?}?if?(e.getSource()?==
?*?btn2)?{?System.exit(0);?}
?*/
}
@Override
public?void?mouseClicked(MouseEvent?e)?{
//?TODO?Auto-generated?method?stub
}
@Override
public?void?mouseEntered(MouseEvent?e)?{
//?TODO?Auto-generated?method?stub
}
@Override
public?void?mouseExited(MouseEvent?e)?{
//?TODO?Auto-generated?method?stub
}
@Override
public?void?mousePressed(MouseEvent?e)?{//?監聽
//?TODO?Auto-generated?method?stub
/*
?*?Random?random?=?new?Random();?int?x1?=?Math.abs(random.nextInt())?%
?*?350?+?15;?int?y1?=?Math.abs(random.nextInt())?%?350?+?45;
?*/
int?x?y;
x?=?e.getX();
y?=?e.getY();
System.out.println(“x=“?+?e.getX()?+?“y=“?+?e.getY());
if?(x?>?42?&&?x?137?&&?y?376?&&?y?>?349)?{
System.out.print(“end!“);
System.exit(0);
}
if?((x?>?42)?&&?(x?137)?&&?(y?329)?&&?(y?>?306))?{
this.gameStart();
System.out.print(“restart!“);
}
if?(e.getX()??w?+?xx?+?5?||?e.getY()? ||?e.getY()?>?h?+?yy?+?5)?{
return;
}
if?(setDown(x?y?0)?==?0)?{//?人
//?setDown(x1?y1?1);//?電腦
//?電腦判斷最佳坐標
bestway();
try?{
Thread.sleep(500);
}?catch?(InterruptedException?e1)?{
//?TODO?Auto-generated?catch?block
e1.printStackTrace();
}
//?電腦落子
setDown(cx?cy?1);
}
}
void
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????301??2011-04-25?17:32??五子棋智能版\fivechess\fivechess\.classpath
?????文件????????385??2011-04-25?17:32??五子棋智能版\fivechess\fivechess\.project
?????文件????????629??2011-04-25?17:32??五子棋智能版\fivechess\fivechess\.settings\org.eclipse.jdt.core.prefs
?????文件??????30661??2011-02-07?22:25??五子棋智能版\fivechess\fivechess\bin\chess.jpg
?????文件??????30661??2011-02-07?22:25??五子棋智能版\fivechess\fivechess\bin\com\chess.jpg
?????文件???????8437??2011-04-28?21:57??五子棋智能版\fivechess\fivechess\bin\com\Main.class
?????文件??????47844??2011-04-28?21:03??五子棋智能版\fivechess\fivechess\chess.jpg
?????文件??????30661??2011-02-07?22:25??五子棋智能版\fivechess\fivechess\src\chess.jpg
?????文件??????30661??2011-02-07?22:25??五子棋智能版\fivechess\fivechess\src\com\chess.jpg
?????文件???????9895??2011-04-28?21:56??五子棋智能版\fivechess\fivechess\src\com\Main.java
?????目錄??????????0??2011-04-28?15:39??五子棋智能版\fivechess\fivechess\bin\com
?????目錄??????????0??2011-04-28?15:38??五子棋智能版\fivechess\fivechess\src\com
?????目錄??????????0??2011-04-28?15:38??五子棋智能版\fivechess\fivechess\.settings
?????目錄??????????0??2011-04-28?15:39??五子棋智能版\fivechess\fivechess\bin
?????目錄??????????0??2011-04-28?15:38??五子棋智能版\fivechess\fivechess\src
?????目錄??????????0??2011-04-28?21:03??五子棋智能版\fivechess\fivechess
?????目錄??????????0??2011-04-28?15:38??五子棋智能版\fivechess
?????目錄??????????0??2011-04-28?15:38??五子棋智能版
-----------?---------??----------?-----??----
???????????????190135????????????????????18
評論
共有 條評論