?? gameframe.java
字號:
this.showMsg(stemp, "你贏了");
isFinish=true;
}
if (this.selectPlayer==1 && !isFinish){
// do with computer get x,y
func.run();
x = func.getResultX();
y = func.getResultY();
if ( x== -1) {
this.showMsg("合棋,再來一盤!","比賽結束");
isFinish=true;
}else {
func.setXY(x, y, m_turn);
m_step++;
this.writeStep(x, y, m_turn);
this.showAllStep();
draw(x, y, m_turn);
jLabel4.setText("Step: " + m_step + " : " + x + " " + y);
System.out.println("Com: " + m_turn + "X=" + x + ",Y=" + y);
changePlayer();
if (func.isOK()) {
this.showMsg("很抱歉,你輸了", "你輸了");
isFinish=true;
}
}
}
}
}
public synchronized void lBoard_mouseClicked(MouseEvent e) {
int n=0; //幾行
int m=0; //幾列
int y=e.getX(); //getX的值為列值
int x=e.getY(); //getY的值為行值
int x0=3; int y0=3; //畫棋層的初始X0,Y0
int k;
if (!isFinish) {
//計算點擊了哪行
for (n = 0; n <= xn; n++) {
if (x > n * linespace + x0 && x < (n + 1) * linespace + x0) {
x = n;
break;
}
}
//計算點擊了哪列
for (m = 0; m <= 16; m++) {
if (y > m * linespace + y0 && y < (m + 1) * linespace + y0) {
y = m;
break;
}
}
//選擇單機版
if (selectPlayer!=0 && selectPlayer!=3){
this.desktop(x,y);
}
//選擇網絡
if (selectPlayer==3 && isWebStart ){
k=this.netgame.getSelectNet();
System.out.println("k=" + k);
String str=new String("");
// 先下,再監聽
if (func.isDrawNow(x, y)) {
func.setXY(x,y,m_turn);
m_step++;
this.writeStep(x, y, m_turn);
this.showAllStep();
draw(x, y, m_turn);
jLabel4.setText("Step: " + m_step + " : " + x + " " + y);
str=m_turn + ":" + x + ":" + y;
netDialog.startWriteThread(str);
changePlayer();
if (func.isOK()) {
//public static void showMessageDialog(Component parentComponent,Object message,String title,int messageType,Icon icon)
this.showMsg("恭喜你贏了!", "你贏了");
isFinish=true;
}else{
this.showMsg("等待對方回音!", "耐心等待");
}
// Receive
if (!isFinish){
jLabel4.setText("Waiting for Response...");
System.out.println("Waiting for Response...");
netDialog.setStr("");
netDialog.startReadThread();
str=netDialog.getStr();
System.out.println("NEW str=" + str);
/*
while ((str=netDialog.getStr())==""){
try{
System.out.println("Thread is sleeping...");
wait(3000);
System.out.println("Thread is waking...");
}catch( Exception ie){
System.out.println("Wrong....from sleep");
}
}
*/
System.out.println("Receive Finish!");
jLabel4.setText("Oppsite:" + str);
int a[] = new int[20];
a = analys(str);
m_turn = a[0];
x = a[1];
y = a[2];
func.setXY(x, y, m_turn);
m_step++;
this.writeStep(x, y, m_turn);
this.showAllStep();
draw(x, y, m_turn);
jLabel4.setText("Step: " + m_step + " : " + x + " " +
y);
System.out.println("Clent:" + m_turn + " X=" + x +
",Y=" + y);
changePlayer();
if (func.isOK()) {
this.showMsg("很抱歉,你輸了", "你輸了");
isFinish = true;
}
}
}
}
if (selectPlayer==3 && !isWebStart ){
this.showMsg("請選擇New Game,開始!","游戲未開始");
}
}else{ //no isfinish
this.showMsg("游戲已經結束了,請重新開始!","游戲結束");
}
}
// 悔棋
public void cmd_undo_actionPerformed(ActionEvent e) {
int x,y;
x=theStep[m_step][0];
y=theStep[m_step][1];
func.setXY(x,y,2);
this.jChess[m_step].setVisible(false);
this.jPanelChess.remove(m_step-1);
this.changePlayer();
m_step-=1;
if (this.selectPlayer==1){
x=theStep[m_step][0];
y=theStep[m_step][1];
func.setXY(x,y,2);
this.jChess[m_step].setVisible(false);
this.jPanelChess.remove(m_step-1);
this.changePlayer();
m_step-=1;
}
isFinish=false;
m_undo++;
}
public void jCheckBoxMenuItem1_mouseReleased(MouseEvent e) {
System.out.println("*1" + this.jCheckBoxMenuItem1.isSelected());
System.out.println("*2=" + this.jCheckBoxMenuItem2.isSelected());
}
//選擇菜單的“單人”模式
public void jCheckBoxMenuItem1_actionPerformed(ActionEvent e) {
this.selectPlayer=1;
this.jCheckBoxMenuItem2.setSelected(false);
jPlayer2.setText("Computer");
}
//選擇菜單的“雙人”模式
public void jCheckBoxMenuItem2_actionPerformed(ActionEvent e) {
this.selectPlayer=2;
this.jCheckBoxMenuItem1.setSelected(false);
}
//選擇菜單的“New Game”
public void jMenuItem2_actionPerformed(ActionEvent e) {
if (this.selectPlayer==0){
this.showMsg("請先選擇對手", "提示");
}
int x,y;
while (m_step!=0)
{
x = theStep[m_step][0];
y = theStep[m_step][1];
func.setXY(x, y, 2);
this.jChess[m_step].setVisible(false);
this.jPanelChess.remove(m_step - 1);
m_step -= 1;
}
if (this.selectPlayer==1) {
jPlayerA.setIcon(image_playing);
jWaitPlayer1.setText("Playing...");
jPlayerB.setIcon(image_waiting);
jWaitPlayer2.setText("Waiting...");
}
if (this.selectPlayer==2) {
jPlayerA.setIcon(image_playing);
jWaitPlayer1.setText("Playing...");
jPlayerB.setIcon(image_waiting);
jWaitPlayer2.setText("Waiting...");
}
m_turn=0;
isFinish=false;
cmd_undo.setEnabled(true);
if (selectPlayer==3){
cmd_undo.setEnabled(false);
isWebStart=true;
role=netDialog.getRole();
if (role==0) {
this.setTitle("五子棋—網絡客戶端");
jPlayer1.setText("I'm Client");
jPlayerA.setIcon(image_playing);
jWaitPlayer1.setText("Playing...");
jPlayerB.setIcon(image_waiting);
jWaitPlayer2.setText("Waiting...");
}
if (role==1) {
this.setTitle("五子棋—網絡服務器");
jPlayer2.setText("I'm Server");
jPlayerA.setIcon(image_playing);
jWaitPlayer1.setText("Playing...");
jPlayerB.setIcon(image_waiting);
jWaitPlayer2.setText("Waiting...");
String str=new String("");
jLabel4.setText("Waiting for Response...");
System.out.println("Waiting for Response...");
this.showMsg("等待對方回音!", "耐心等待");
netDialog.setStr("");
netDialog.startReadThread();
str=netDialog.getStr();
System.out.println("NEW str=" + str);
System.out.println("Receive Finish!");
jLabel4.setText("Oppsite:" + str);
int a[]=new int[20];
a=analys(str);
m_turn=a[0]; x=a[1]; y=a[2];
func.setXY(x,y,m_turn);
m_step++;
this.writeStep(x, y, m_turn);
this.showAllStep();
draw(x, y, m_turn);
jLabel4.setText("Step: " + m_step + " : " + x + " " + y);
System.out.println("Clent:" + m_turn + " X=" + x + ",Y=" + y);
changePlayer();
}
}
}
//選擇“network”
public void jMenuItem1_actionPerformed(ActionEvent e) {
// net.serverRun();
netgame=new NetGame();
netDialog = new NetDialog(this,"Network",true,netgame);
netDialog.setVisible(true);
this.selectPlayer=3;
jPlayer1.setText("Client");
jPlayer2.setText("Server");
}
public void cmd_New_actionPerformed(ActionEvent e) {
jMenuItem2_actionPerformed(e);
}
}
class GameFrame_cmd_New_actionAdapter implements ActionListener {
private GameFrame adaptee;
GameFrame_cmd_New_actionAdapter(GameFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.cmd_New_actionPerformed(e);
}
}
class GameFrame_jMenuItem1_actionAdapter implements ActionListener {
private GameFrame adaptee;
GameFrame_jMenuItem1_actionAdapter(GameFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jMenuItem1_actionPerformed(e);
}
}
class GameFrame_jCheckBoxMenuItem2_actionAdapter implements ActionListener {
private GameFrame adaptee;
GameFrame_jCheckBoxMenuItem2_actionAdapter(GameFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jCheckBoxMenuItem2_actionPerformed(e);
}
}
class GameFrame_jMenuItem2_actionAdapter implements ActionListener {
private GameFrame adaptee;
GameFrame_jMenuItem2_actionAdapter(GameFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jMenuItem2_actionPerformed(e);
}
}
class GameFrame_jCheckBoxMenuItem1_actionAdapter implements ActionListener {
private GameFrame adaptee;
GameFrame_jCheckBoxMenuItem1_actionAdapter(GameFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jCheckBoxMenuItem1_actionPerformed(e);
}
}
class GameFrame_cmd_undo_actionAdapter implements ActionListener {
private GameFrame adaptee;
GameFrame_cmd_undo_actionAdapter(GameFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.cmd_undo_actionPerformed(e);
}
}
class GameFrame_lBoard_mouseAdapter extends MouseAdapter {
private GameFrame adaptee;
GameFrame_lBoard_mouseAdapter(GameFrame adaptee) {
this.adaptee = adaptee;
}
public void mouseClicked(MouseEvent e) {
adaptee.lBoard_mouseClicked(e);
}
}
class GameFrame_jMenuFileExit_ActionAdapter implements ActionListener {
GameFrame adaptee;
GameFrame_jMenuFileExit_ActionAdapter(GameFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent actionEvent) {
adaptee.jMenuFileExit_actionPerformed(actionEvent);
}
}
class GameFrame_jMenuHelpAbout_ActionAdapter implements ActionListener {
GameFrame adaptee;
GameFrame_jMenuHelpAbout_ActionAdapter(GameFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent actionEvent) {
adaptee.jMenuHelpAbout_actionPerformed(actionEvent);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -