📄 morpion.java
字号:
package GameImplement;
import Framework.IGame;
public class Morpion implements IGame{
int chessBoard[][]; //chessBoard;
int len; //chessBoard length
String gameName="Morpion"; //gameName
public boolean isWon(int role){
int sumR=0;
int sumC=0;
int sumX=0;
int sumN=0;
for(int i=0;i<len;i++){
for(int j=0;j<len;j++){
if(chessBoard[i][j]==role)
sumR++; //judge the same chess in a row
if(chessBoard[j][i]==role)
sumC++; //judge the same chess in a column
}
if(sumR==len||sumC==len){
return true; // a row or column have the same chesses
}
else{ //move to next row or column
sumR=0;
sumC=0;
}
if(chessBoard[i][i]==role) //to judge a hypotenuse have the same chess
sumX++;
if(chessBoard[i][len-i-1]==role) //to judge a hypotenuse have the same chess
sumN++;
}
if(sumX==len||sumN==len)
return true;
else
return false;
}
public void playChess(int role,int x,int y){
chessBoard[x][y]=role;
}
public boolean isValidStep(int x,int y){
if(x<0||x>=len||y<0||y>=len||chessBoard[x][y]!=0)
return false;
return true;
}
public void drawChessBoard(){
for(int i=0;i<len;i++){
System.out.println("---------------");
for(int j=0;j<len;j++)
if(chessBoard[i][j]==0)
System.out.print(" "+" |");
else if(chessBoard[i][j]==1)
System.out.print("0"+" |");
else if(chessBoard[i][j]==2)
System.out.print("X"+" |");
System.out.println();
}
System.out.println("---------------");
}
public boolean isFini(){
for(int i=0;i<len;i++){
for(int j=0;j<len;j++){
if(chessBoard[i][j]==0)//still have valid place that can put chess
return false;
}
}
return true;
}
public void setBoardSize(int size){
this.len=size;
this.chessBoard=new int[len][len];
}
public String getGameName(){
return this.gameName;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -