Java项目实现五子棋小游戏
本文实例为大家分享了Java实现五子棋小游戏的具体代码,供大家参考,具体内容如下
项目名称
五子棋小游戏
项目描述
可以改变获胜棋子数,率先连成棋数的人获胜
代码实现
测试类
publicclassTest{
publicstaticvoidmain(String[]args){
FiveChessfiveChess=newFiveChess();
fiveChess.start();
}
}
主类:实现主方法
publicclassFiveChess{
privatestaticfinalintCheckerSize=10;
privatestaticfinalintsuccessSize=5;
privateChess[][]chess;
privateintxPos;
privateintyPos;
privatebooleanflag=true;
privateScannerscanner=newScanner(System.in);
publicFiveChess(){
chess=newChess[CheckerSize][CheckerSize];
}
privatevoidinitCheck(){
for(inti=0;i=0&&chess[xPos][yPos].getValue().equals(chess[xPos][yPos-1].getValue())||
yPos+1=0&&chess[xPos][yPos-i].getValue().equals(chess[xPos][yPos].getValue())){
count++;
}else{
break;
}
}
for(inti=1;i=successSize?true:false;
}
//纵向
if(xPos-1>=0&&chess[xPos][yPos].getValue().equals(chess[xPos-1][yPos].getValue())||
xPos+1=0&&chess[xPos-i][yPos].getValue().equals(chess[xPos][yPos].getValue())){
count++;
}else{
break;
}
}
for(inti=1;i=successSize?true:false;
}
//正斜线
if(xPos-1>=0&&yPos-1>=0&&chess[xPos][yPos].getValue().equals(chess[xPos-1][yPos-1].getValue())||
xPos+1=0&&yPos-i>=0&&
chess[xPos-i][yPos-i].getValue().equals(chess[xPos][yPos].getValue())){
count++;
}else{
break;
}
}
for(inti=1;i=successSize?true:false;
}
//反斜线
if(xPos-1>=0&&yPos+1=0&&
chess[xPos][yPos].getValue().equals(chess[xPos+1][yPos-1].getValue())){
intcount=1;
for(inti=1;i=0&&yPos+i=0&&
chess[xPos+i][yPos-i].getValue().equals(chess[xPos][yPos].getValue())){
count++;
}else{
break;
}
}
returncount>=successSize?true:false;
}
returnfalse;
}
privatevoidrunChess(Stringrun){
System.out.println("请输入"+run+"坐标:");
xPos=scanner.nextInt();
yPos=scanner.nextInt();
if(chess[xPos-1][yPos-1].getValue().equals("十")){
if(run.equals("黑棋")){
chess[xPos-1][yPos-1]=newChess("●");
}
elseif(run.equals("白棋")){
chess[xPos-1][yPos-1]=newChess("〇");
}
for(inti=0;i
结点类
publicclassChess{
privateStringvalue;
publicChess(Stringvalue){
this.value=value;
}
publicStringgetValue(){
returnvalue;
}
}
更多有趣的经典小游戏实现专题,分享给大家:
C++经典小游戏汇总
python经典小游戏汇总
python俄罗斯方块游戏集合
JavaScript经典游戏玩不停
javascript经典小游戏汇总
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。