该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
r=new JRadiobuttonMenuItem((String)item);
else if(item instanceof JRdioButtonMenuItem)
r=(JRadioButtonMenuItem)item;
else return null;
if(target instanceof ActionListener)
r.addActionListener((ActionListener)target);
return r;
}
public void MapSize(int w, int h){
setSize(w*20+5,h*20+100);
if(this.checkcomputer)
this.iscomputer=true;
else
this.iscomputer=false;
mp.setModel(cm);
mp.repaint();}
public boolean getiscomputer(){
return this.iscomputer;}
publid void restart(){
int modChess=cm.getModeChess();
if(modeChess<=3 && modChess>=1){
cm=new ChessModel(modeChess);
MapSize(cm.getWidth(),cm.getHeight());}
else{System.out.perintln("\u81EA\u5B9A\u4E49");}
}
public void actionPerformed(ActionEvent e){
String arg=e.getActionCommand();
try{
if(arg.equals("Windows"))
UIManager.setLoolAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
else if(arg.equals("Motif"))
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
SwingUtilities.updateConentTreeUI(this);}
catch(Exception ee){}
if(arg.equals("20*15")){
this.width=20;this.height=15;
cm=new ChessModel(1);
MapSize(this.width,this.height);
SwingUtilities.updateComponentTreeUI(this);}
if(arg.equals("40*30")){
this.width=40;
this.height=30;
cm=new ChessMOdel(3);
MapSize(this.width,this.height);
SwingUtilities.updateComponentTreeUI(this);}
if(arg.equals("人机对弈")){
this.checkcomputer=true;
this.iscomputer=true;
cm=new ChessModel(cm.getModeChess());
MapSize(this.getWidth(),this.getHeight());
SwingUtilities.updateComponentTreeUI(this);}
if(arg.equals("人人对弈")){
this.checkcomputer=false;
this.iscomputer=false;
cm=new ChessModel(cm.getModeChess());
MapSize(cm.getWidth(),cm.getHeight());
SwingUtilities.updateCopinentTreeUI(this);}
if(arg.equals("开局")){
restart();}
if(arg.equals("关于"))
JOptionpane.showMessageDialog(this,"五子棋游戏测试版","关于",0);
if(arg.equals("退出"))
System.exit(0);
}
}
class ChessModel{
private int x=0,y=0;
private int arrMapShow[][];
private boolean isOdd,isExist;
private int height;
private int widthl
ptivate int modeChess;
public ChessModel(){}
public ChessModel(int modeChess){
this.isOdd=true;
if(modechess==1){
PanelInit(20,15,modeChess);}
if(modeChess==2){
PanelInit(30,20,modeChess);}
if(modeChess==3){
PanelInit(40,30,modeChess);}}
private void PanelInit(int width,int height,int modeChess){
this.width=width;
this.height=neight;
this.modeChess=modeChess;
arrMapShow=new int[width+1][height+1];for(int i=0;i
arrMapShow[i][j]=-5;}}}
public boolean getisOdd(){
return this.isOdd;}
public void setisOdd(boolean isOdd){
if(isOdd)
this.isOdd=true;
else
this.isOdd=false;}
public boolean getisExist(){
return this.isExist;}
public int getWidth(){
return this.width;}
public int getHeight(){
return this.height;}
public int getModeChess(){
return this.modeChess;}
public int[][]getarrMapShow(){
return arrMapShow;}
private boolean badxy(int x,int y){
if(x>=width+20||x<0)
return true;
return y>=height+20 || y<0;}
public boolean chessExist(int i, int j){
if(this.arrMapShow[i][j]==1||this.arrMapShow[i][j]==2)
return true;
return false;}
public void readyplay(int x,int y){
if(badxy(x,y))
return;
if(chessExist(x,y)){
this.isExist=true;
return;}
else
this.isExist=false;
if(getisOdd()){
setisOdd(fslse);
this.arrMapShow[x][y]=1;}
else{
setisOdd(true);
this.arrMapShow[x][y]=2;}}