91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 5KB
    文件類型: .zip
    金幣: 2
    下載: 0 次
    發布日期: 2021-06-06
  • 語言: Java
  • 標簽: 五子棋??

資源簡介

一個五子棋的代碼實現 啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊

資源截圖

代碼片段和文件信息

package?wuziqi;
import?java.awt.Color;
import?java.awt.FontMetrics;
import?java.awt.Graphics;
import?java.awt.Graphics2D;
import?java.awt.Point;
import?java.awt.event.MouseAdapter;
import?java.awt.event.MouseEvent;
import?java.awt.geom.Rectangle2D;

import?javax.swing.JOptionPane;
import?javax.swing.JPanel;

/*
?*?創建一個棋盤面板。顯示棋局,設置好鼠標事件處理。
?*/
public?class?BoardPanel?extends?JPanel?{
public?static?final?int?WIDTH=600;
public?static?final?int?HEIGHT=600;
private?static?int?MARGIN=20;
private?FiveInARowModel?board;
private?ComputerPlayer?computerPlayer;
public?BoardPanel(FiveInARowModel?board){
this.board=board;
computerPlayer=new?ComputerPlayer(board?FiveInARowModel.BLACK);
this.setBackground(Color.WHITE);
addMouseListener(new?MouseAdapter()?{
public?void?mouseClicked(MouseEvent?e)?{
Point?p=e.getPoint();
int?rowcol;
int?dim=BoardPanel.this.board.getDimension();
int?cellWidth=(getWidth()-2*MARGIN)/dim;
if(p.y>=MARGIN&&p.y p.x>=MARGIN&&p.x row=(p.y-MARGIN)/cellWidth;
col=(p.x-MARGIN)/cellWidth;
if(!BoardPanel.this.board.isEmpty(row?col))
return;
try?{
//user?put?a?chessman
boolean?win=BoardPanel.this.board.setChessman(row?col?FiveInARowModel.WHITE);
BoardPanel.this.drawChessman(row?col);
if(win){//user?wins
JOptionPane.showMessageDialog(BoardPanel.this?“You?win!“);
BoardPanel.this.board.clear();
BoardPanel.this.repaint();
}else?if(BoardPanel.this.board.isFull()){//full
JOptionPane.showMessageDialog(BoardPanel.this?“No?empty?cell!“);
BoardPanel.this.board.clear();
BoardPanel.this.repaint();
}else{
//computer?put?a?chessman
win=computerPlayer.play();
int[]last=BoardPanel.this.board.getLastPut();
row=last[0];
col=last[1];
BoardPanel.this.drawChessman(row?col);
if(win){//computer?wins
JOptionPane.showMessageDialog(BoardPanel.this?“Computer?win!“);
BoardPanel.this.board.clear();
BoardPanel.this.repaint();
}else?if(BoardPanel.this.board.isFull()){
JOptionPane.showMessageDialog(BoardPanel.this?“No?empty?cell!“);
BoardPanel.this.board.clear();
BoardPanel.this.repaint();
}
}
}?catch?(Exception?e1)?{
e1.printStackTrace();
}
}
}
});
}
public?int?getWidth()?{
return?WIDTH;
}
public?int?getHeight()?{
return?HEIGHT;
}
public?void?paint(Graphics?g)?{
Graphics2D?g2d=(Graphics2D)?g;
//fill?white?back?ground
g2d.setColor(Color.CYAN);
g2d.fillRect(0?0?WIDTH?HEIGHT);
//write?tip
g2d.setColor(Color.BLACK);
g2d.drawString(“Computer“?MARGIN?MARGIN*2/3);
FontMetrics?fm=g2d.getFontMetrics();
Rectangle2D?rect=fm.getStringBounds(“Computer“?g2d);
int?r=MARGIN-2;
g2d.drawOval(MARGIN+(int)rect.getWidth()+r?0?r

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2017-09-27?14:30??五子棋\
?????文件????????4555??2017-09-27?14:28??五子棋\BoardPanel.java
?????文件????????3331??2017-09-26?20:49??五子棋\ComputerPlayer.java
?????文件????????3209??2017-09-27?14:29??五子棋\FiveInARowModel.java
?????文件?????????149??2017-09-26?20:25??五子棋\Main.java
?????文件?????????488??2017-09-26?20:47??五子棋\Mainframe.java

評論

共有 條評論