Java项目实现五子棋小游戏

网友投稿 588 2023-06-01

java项目实现五子棋小游戏

本文实例为大家分享了java实现五子棋小游戏的具体代码,供大家参考,具体内容如下

项目名称

五子棋小游戏

项目描述

可以改变获胜棋子数,率先连成棋数的人获胜

代码实现

测试类

public class Test {

public static void main(String[] args) {

FiveChess fiveChess = new FiveChess();

fiveChess.start();

}

}

主类:实现主方法

public class FiveChess {

private static final int CheckerSize = 10;

private static final int successSize = 5;

private Chess[][] chess;

private int xPos;

private int yPos;

private boolean flag = true;

private Scanner scanner = new Scanner(System.in);

public FiveChess(){

chess = new ChessqwLcjUOcvB[CheckerSize][CheckerSize];

}

private void initCheck(){

for(int i=0;i

for(int j=0;j

chess[i][j] = new Chess("十");

}

}

}

private boolean judge(int xPos,int yPos){

//横向

if(yPos-1>=0 && chess[xPos][yPos].getValue().equals(chess[xPos][yPos-1].getValue()) ||

yPos+1

int count = 1;

for (int i = 1; i < successSize; i++) {

if (yPos - i >= 0 && chess[xPos][yPos - i].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

for (int i = 1; i < successSize; i++) {

if (yPos + i < CheckerSize &&

chess[xPos][yPos + i].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

return count >= successSize ? true : false;

}

//纵向

if (xPos-1>=0 && chess[xPos][yPos].getValue().equals(chess[xPos-1][yPos].getValue()) ||

xPos+1

int count = 1;

for (int i = 1; i < successSize; i++) {

if (xPos- i &qwLcjUOcvBgt;= 0 && chess[xPos-i][yPos].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

for (int i = 1; i < successSize; i++) {

if (xPos + i < CheckerSize &&

chess[xPos+i][yPos].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

return count >= successSize ? true : false;

}

//正斜线

if (xPos-1>=0 && yPos-1>=0 && chess[xPos][yPos].getValue().equals(chess[xPos-1][yPos-1].getValue()) ||

xPos+1

chess[xPos][yPos].getValue().equals(chess[xPos+1][yPos+1].getValue())){

int count = 1;

for (int i = 1; i < successSize; i++) {

if (xPos - i >= 0 && yPos - i >= 0 &&

chess[xPos-i][yPos-i].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

for (int i = 1; i < successSize; i++) {

if (xPos + i < CheckerSize && yPos + i < CheckerSize &&

chess[xPos+i][yPos+i].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

return count >= successSize ? true : false;

}

//反斜线

if (xPos-1>=0 && yPos+1

chess[xPos][yPos].getValue().equals(chess[xPos-1][yPos+1].getValue()) ||

xPos+1=0 &&

chess[xPos][yPos].getValue().equals(chess[xPos+1][yPos-1].getValue())){

int count = 1;

for (int i = 1; i < successSize; i++) {

if (xPos - i >= 0 && yPos + i

chess[xPos-i][yPos+i].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

for (int i = 1; i < successSize; i++) {

if (xPos + i < CheckerSize && yPos - i >= 0 &&

chess[xPos+i][yPos-i].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

return count >= successSize ? true : false;

}

return false;

}

private void runChess(String run){

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] = new Chess("●");

}

else if(run.equals("白棋")){

chess[xPos-1][yPos-1] = new Chess("〇");

}

for(int i=0;i

for (int j=0;j

System.out.print(chess[i][j].getValue());

}

System.out.println();

}

if(judge(xPos-1,yPos-1)){

flag = false;

System.out.println(run+"获胜");

System.out.println("游戏结束,是否重玩");

String finish = scanner.next();

if (finish.equals("是")){

flag = true;

start();

}

else if (finish.equals("否")){

System.exit(0);

}

}

}else {

System.out.println("该处已存在棋子,请重新选择");

runChess(run);

}

}

public void start(){

initCheck();

System.out.println("请选择先走方:黑棋or白棋");

String run = scanner.next();

for(int i=0;i

for (int j=0;j

System.out.print(chess[i][j].getValue());

}

System.out.println();

}

while (flag) {

switch (run) {

case "黑棋":

runChess("黑棋");

run = "白棋";

break;

case "白棋":

runChess("白棋");

run = "黑棋";

break;

default:

}

}

}

}

结点类

public class Chess {

private String value;

public Chess(String value){

this.value = value;

}

public String getValue() {

return value;

}

}

更多有趣的经典小游戏实现专题,分享给大家:

C++经典小游戏汇总

python经典小游戏汇总

python俄罗斯方块游戏集合

javascript经典游戏 玩不停

javascript经典小游戏汇总

for(int j=0;j

chess[i][j] = new Chess("十");

}

}

}

private boolean judge(int xPos,int yPos){

//横向

if(yPos-1>=0 && chess[xPos][yPos].getValue().equals(chess[xPos][yPos-1].getValue()) ||

yPos+1

int count = 1;

for (int i = 1; i < successSize; i++) {

if (yPos - i >= 0 && chess[xPos][yPos - i].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

for (int i = 1; i < successSize; i++) {

if (yPos + i < CheckerSize &&

chess[xPos][yPos + i].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

return count >= successSize ? true : false;

}

//纵向

if (xPos-1>=0 && chess[xPos][yPos].getValue().equals(chess[xPos-1][yPos].getValue()) ||

xPos+1

int count = 1;

for (int i = 1; i < successSize; i++) {

if (xPos- i &qwLcjUOcvBgt;= 0 && chess[xPos-i][yPos].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

for (int i = 1; i < successSize; i++) {

if (xPos + i < CheckerSize &&

chess[xPos+i][yPos].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

return count >= successSize ? true : false;

}

//正斜线

if (xPos-1>=0 && yPos-1>=0 && chess[xPos][yPos].getValue().equals(chess[xPos-1][yPos-1].getValue()) ||

xPos+1

chess[xPos][yPos].getValue().equals(chess[xPos+1][yPos+1].getValue())){

int count = 1;

for (int i = 1; i < successSize; i++) {

if (xPos - i >= 0 && yPos - i >= 0 &&

chess[xPos-i][yPos-i].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

for (int i = 1; i < successSize; i++) {

if (xPos + i < CheckerSize && yPos + i < CheckerSize &&

chess[xPos+i][yPos+i].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

return count >= successSize ? true : false;

}

//反斜线

if (xPos-1>=0 && yPos+1

chess[xPos][yPos].getValue().equals(chess[xPos-1][yPos+1].getValue()) ||

xPos+1=0 &&

chess[xPos][yPos].getValue().equals(chess[xPos+1][yPos-1].getValue())){

int count = 1;

for (int i = 1; i < successSize; i++) {

if (xPos - i >= 0 && yPos + i

chess[xPos-i][yPos+i].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

for (int i = 1; i < successSize; i++) {

if (xPos + i < CheckerSize && yPos - i >= 0 &&

chess[xPos+i][yPos-i].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

return count >= successSize ? true : false;

}

return false;

}

private void runChess(String run){

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] = new Chess("●");

}

else if(run.equals("白棋")){

chess[xPos-1][yPos-1] = new Chess("〇");

}

for(int i=0;i

for (int j=0;j

System.out.print(chess[i][j].getValue());

}

System.out.println();

}

if(judge(xPos-1,yPos-1)){

flag = false;

System.out.println(run+"获胜");

System.out.println("游戏结束,是否重玩");

String finish = scanner.next();

if (finish.equals("是")){

flag = true;

start();

}

else if (finish.equals("否")){

System.exit(0);

}

}

}else {

System.out.println("该处已存在棋子,请重新选择");

runChess(run);

}

}

public void start(){

initCheck();

System.out.println("请选择先走方:黑棋or白棋");

String run = scanner.next();

for(int i=0;i

for (int j=0;j

System.out.print(chess[i][j].getValue());

}

System.out.println();

}

while (flag) {

switch (run) {

case "黑棋":

runChess("黑棋");

run = "白棋";

break;

case "白棋":

runChess("白棋");

run = "黑棋";

break;

default:

}

}

}

}

结点类

public class Chess {

private String value;

public Chess(String value){

this.value = value;

}

public String getValue() {

return value;

}

}

更多有趣的经典小游戏实现专题,分享给大家:

C++经典小游戏汇总

python经典小游戏汇总

python俄罗斯方块游戏集合

javascript经典游戏 玩不停

javascript经典小游戏汇总

chess[i][j] = new Chess("十");

}

}

}

private boolean judge(int xPos,int yPos){

//横向

if(yPos-1>=0 && chess[xPos][yPos].getValue().equals(chess[xPos][yPos-1].getValue()) ||

yPos+1

int count = 1;

for (int i = 1; i < successSize; i++) {

if (yPos - i >= 0 && chess[xPos][yPos - i].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

for (int i = 1; i < successSize; i++) {

if (yPos + i < CheckerSize &&

chess[xPos][yPos + i].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

return count >= successSize ? true : false;

}

//纵向

if (xPos-1>=0 && chess[xPos][yPos].getValue().equals(chess[xPos-1][yPos].getValue()) ||

xPos+1

int count = 1;

for (int i = 1; i < successSize; i++) {

if (xPos- i &qwLcjUOcvBgt;= 0 && chess[xPos-i][yPos].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

for (int i = 1; i < successSize; i++) {

if (xPos + i < CheckerSize &&

chess[xPos+i][yPos].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

return count >= successSize ? true : false;

}

//正斜线

if (xPos-1>=0 && yPos-1>=0 && chess[xPos][yPos].getValue().equals(chess[xPos-1][yPos-1].getValue()) ||

xPos+1

chess[xPos][yPos].getValue().equals(chess[xPos+1][yPos+1].getValue())){

int count = 1;

for (int i = 1; i < successSize; i++) {

if (xPos - i >= 0 && yPos - i >= 0 &&

chess[xPos-i][yPos-i].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

for (int i = 1; i < successSize; i++) {

if (xPos + i < CheckerSize && yPos + i < CheckerSize &&

chess[xPos+i][yPos+i].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

return count >= successSize ? true : false;

}

//反斜线

if (xPos-1>=0 && yPos+1

chess[xPos][yPos].getValue().equals(chess[xPos-1][yPos+1].getValue()) ||

xPos+1=0 &&

chess[xPos][yPos].getValue().equals(chess[xPos+1][yPos-1].getValue())){

int count = 1;

for (int i = 1; i < successSize; i++) {

if (xPos - i >= 0 && yPos + i

chess[xPos-i][yPos+i].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

for (int i = 1; i < successSize; i++) {

if (xPos + i < CheckerSize && yPos - i >= 0 &&

chess[xPos+i][yPos-i].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

return count >= successSize ? true : false;

}

return false;

}

private void runChess(String run){

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] = new Chess("●");

}

else if(run.equals("白棋")){

chess[xPos-1][yPos-1] = new Chess("〇");

}

for(int i=0;i

for (int j=0;j

System.out.print(chess[i][j].getValue());

}

System.out.println();

}

if(judge(xPos-1,yPos-1)){

flag = false;

System.out.println(run+"获胜");

System.out.println("游戏结束,是否重玩");

String finish = scanner.next();

if (finish.equals("是")){

flag = true;

start();

}

else if (finish.equals("否")){

System.exit(0);

}

}

}else {

System.out.println("该处已存在棋子,请重新选择");

runChess(run);

}

}

public void start(){

initCheck();

System.out.println("请选择先走方:黑棋or白棋");

String run = scanner.next();

for(int i=0;i

for (int j=0;j

System.out.print(chess[i][j].getValue());

}

System.out.println();

}

while (flag) {

switch (run) {

case "黑棋":

runChess("黑棋");

run = "白棋";

break;

case "白棋":

runChess("白棋");

run = "黑棋";

break;

default:

}

}

}

}

结点类

public class Chess {

private String value;

public Chess(String value){

this.value = value;

}

public String getValue() {

return value;

}

}

更多有趣的经典小游戏实现专题,分享给大家:

C++经典小游戏汇总

python经典小游戏汇总

python俄罗斯方块游戏集合

javascript经典游戏 玩不停

javascript经典小游戏汇总

int count = 1;

for (int i = 1; i < successSize; i++) {

if (yPos - i >= 0 && chess[xPos][yPos - i].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

for (int i = 1; i < successSize; i++) {

if (yPos + i < CheckerSize &&

chess[xPos][yPos + i].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

return count >= successSize ? true : false;

}

//纵向

if (xPos-1>=0 && chess[xPos][yPos].getValue().equals(chess[xPos-1][yPos].getValue()) ||

xPos+1

int count = 1;

for (int i = 1; i < successSize; i++) {

if (xPos- i &qwLcjUOcvBgt;= 0 && chess[xPos-i][yPos].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

for (int i = 1; i < successSize; i++) {

if (xPos + i < CheckerSize &&

chess[xPos+i][yPos].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

return count >= successSize ? true : false;

}

//正斜线

if (xPos-1>=0 && yPos-1>=0 && chess[xPos][yPos].getValue().equals(chess[xPos-1][yPos-1].getValue()) ||

xPos+1

chess[xPos][yPos].getValue().equals(chess[xPos+1][yPos+1].getValue())){

int count = 1;

for (int i = 1; i < successSize; i++) {

if (xPos - i >= 0 && yPos - i >= 0 &&

chess[xPos-i][yPos-i].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

for (int i = 1; i < successSize; i++) {

if (xPos + i < CheckerSize && yPos + i < CheckerSize &&

chess[xPos+i][yPos+i].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

return count >= successSize ? true : false;

}

//反斜线

if (xPos-1>=0 && yPos+1

chess[xPos][yPos].getValue().equals(chess[xPos-1][yPos+1].getValue()) ||

xPos+1=0 &&

chess[xPos][yPos].getValue().equals(chess[xPos+1][yPos-1].getValue())){

int count = 1;

for (int i = 1; i < successSize; i++) {

if (xPos - i >= 0 && yPos + i

chess[xPos-i][yPos+i].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

for (int i = 1; i < successSize; i++) {

if (xPos + i < CheckerSize && yPos - i >= 0 &&

chess[xPos+i][yPos-i].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

return count >= successSize ? true : false;

}

return false;

}

private void runChess(String run){

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] = new Chess("●");

}

else if(run.equals("白棋")){

chess[xPos-1][yPos-1] = new Chess("〇");

}

for(int i=0;i

for (int j=0;j

System.out.print(chess[i][j].getValue());

}

System.out.println();

}

if(judge(xPos-1,yPos-1)){

flag = false;

System.out.println(run+"获胜");

System.out.println("游戏结束,是否重玩");

String finish = scanner.next();

if (finish.equals("是")){

flag = true;

start();

}

else if (finish.equals("否")){

System.exit(0);

}

}

}else {

System.out.println("该处已存在棋子,请重新选择");

runChess(run);

}

}

public void start(){

initCheck();

System.out.println("请选择先走方:黑棋or白棋");

String run = scanner.next();

for(int i=0;i

for (int j=0;j

System.out.print(chess[i][j].getValue());

}

System.out.println();

}

while (flag) {

switch (run) {

case "黑棋":

runChess("黑棋");

run = "白棋";

break;

case "白棋":

runChess("白棋");

run = "黑棋";

break;

default:

}

}

}

}

结点类

public class Chess {

private String value;

public Chess(String value){

this.value = value;

}

public String getValue() {

return value;

}

}

更多有趣的经典小游戏实现专题,分享给大家:

C++经典小游戏汇总

python经典小游戏汇总

python俄罗斯方块游戏集合

javascript经典游戏 玩不停

javascript经典小游戏汇总

int count = 1;

for (int i = 1; i < successSize; i++) {

if (xPos- i &qwLcjUOcvBgt;= 0 && chess[xPos-i][yPos].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

for (int i = 1; i < successSize; i++) {

if (xPos + i < CheckerSize &&

chess[xPos+i][yPos].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

return count >= successSize ? true : false;

}

//正斜线

if (xPos-1>=0 && yPos-1>=0 && chess[xPos][yPos].getValue().equals(chess[xPos-1][yPos-1].getValue()) ||

xPos+1

chess[xPos][yPos].getValue().equals(chess[xPos+1][yPos+1].getValue())){

int count = 1;

for (int i = 1; i < successSize; i++) {

if (xPos - i >= 0 && yPos - i >= 0 &&

chess[xPos-i][yPos-i].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

for (int i = 1; i < successSize; i++) {

if (xPos + i < CheckerSize && yPos + i < CheckerSize &&

chess[xPos+i][yPos+i].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

return count >= successSize ? true : false;

}

//反斜线

if (xPos-1>=0 && yPos+1

chess[xPos][yPos].getValue().equals(chess[xPos-1][yPos+1].getValue()) ||

xPos+1=0 &&

chess[xPos][yPos].getValue().equals(chess[xPos+1][yPos-1].getValue())){

int count = 1;

for (int i = 1; i < successSize; i++) {

if (xPos - i >= 0 && yPos + i

chess[xPos-i][yPos+i].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

for (int i = 1; i < successSize; i++) {

if (xPos + i < CheckerSize && yPos - i >= 0 &&

chess[xPos+i][yPos-i].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

return count >= successSize ? true : false;

}

return false;

}

private void runChess(String run){

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] = new Chess("●");

}

else if(run.equals("白棋")){

chess[xPos-1][yPos-1] = new Chess("〇");

}

for(int i=0;i

for (int j=0;j

System.out.print(chess[i][j].getValue());

}

System.out.println();

}

if(judge(xPos-1,yPos-1)){

flag = false;

System.out.println(run+"获胜");

System.out.println("游戏结束,是否重玩");

String finish = scanner.next();

if (finish.equals("是")){

flag = true;

start();

}

else if (finish.equals("否")){

System.exit(0);

}

}

}else {

System.out.println("该处已存在棋子,请重新选择");

runChess(run);

}

}

public void start(){

initCheck();

System.out.println("请选择先走方:黑棋or白棋");

String run = scanner.next();

for(int i=0;i

for (int j=0;j

System.out.print(chess[i][j].getValue());

}

System.out.println();

}

while (flag) {

switch (run) {

case "黑棋":

runChess("黑棋");

run = "白棋";

break;

case "白棋":

runChess("白棋");

run = "黑棋";

break;

default:

}

}

}

}

结点类

public class Chess {

private String value;

public Chess(String value){

this.value = value;

}

public String getValue() {

return value;

}

}

更多有趣的经典小游戏实现专题,分享给大家:

C++经典小游戏汇总

python经典小游戏汇总

python俄罗斯方块游戏集合

javascript经典游戏 玩不停

javascript经典小游戏汇总

chess[xPos][yPos].getValue().equals(chess[xPos+1][yPos+1].getValue())){

int count = 1;

for (int i = 1; i < successSize; i++) {

if (xPos - i >= 0 && yPos - i >= 0 &&

chess[xPos-i][yPos-i].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

for (int i = 1; i < successSize; i++) {

if (xPos + i < CheckerSize && yPos + i < CheckerSize &&

chess[xPos+i][yPos+i].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

return count >= successSize ? true : false;

}

//反斜线

if (xPos-1>=0 && yPos+1

chess[xPos][yPos].getValue().equals(chess[xPos-1][yPos+1].getValue()) ||

xPos+1=0 &&

chess[xPos][yPos].getValue().equals(chess[xPos+1][yPos-1].getValue())){

int count = 1;

for (int i = 1; i < successSize; i++) {

if (xPos - i >= 0 && yPos + i

chess[xPos-i][yPos+i].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

for (int i = 1; i < successSize; i++) {

if (xPos + i < CheckerSize && yPos - i >= 0 &&

chess[xPos+i][yPos-i].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

return count >= successSize ? true : false;

}

return false;

}

private void runChess(String run){

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] = new Chess("●");

}

else if(run.equals("白棋")){

chess[xPos-1][yPos-1] = new Chess("〇");

}

for(int i=0;i

for (int j=0;j

System.out.print(chess[i][j].getValue());

}

System.out.println();

}

if(judge(xPos-1,yPos-1)){

flag = false;

System.out.println(run+"获胜");

System.out.println("游戏结束,是否重玩");

String finish = scanner.next();

if (finish.equals("是")){

flag = true;

start();

}

else if (finish.equals("否")){

System.exit(0);

}

}

}else {

System.out.println("该处已存在棋子,请重新选择");

runChess(run);

}

}

public void start(){

initCheck();

System.out.println("请选择先走方:黑棋or白棋");

String run = scanner.next();

for(int i=0;i

for (int j=0;j

System.out.print(chess[i][j].getValue());

}

System.out.println();

}

while (flag) {

switch (run) {

case "黑棋":

runChess("黑棋");

run = "白棋";

break;

case "白棋":

runChess("白棋");

run = "黑棋";

break;

default:

}

}

}

}

结点类

public class Chess {

private String value;

public Chess(String value){

this.value = value;

}

public String getValue() {

return value;

}

}

更多有趣的经典小游戏实现专题,分享给大家:

C++经典小游戏汇总

python经典小游戏汇总

python俄罗斯方块游戏集合

javascript经典游戏 玩不停

javascript经典小游戏汇总

chess[xPos][yPos].getValue().equals(chess[xPos-1][yPos+1].getValue()) ||

xPos+1=0 &&

chess[xPos][yPos].getValue().equals(chess[xPos+1][yPos-1].getValue())){

int count = 1;

for (int i = 1; i < successSize; i++) {

if (xPos - i >= 0 && yPos + i

chess[xPos-i][yPos+i].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

for (int i = 1; i < successSize; i++) {

if (xPos + i < CheckerSize && yPos - i >= 0 &&

chess[xPos+i][yPos-i].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

return count >= successSize ? true : false;

}

return false;

}

private void runChess(String run){

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] = new Chess("●");

}

else if(run.equals("白棋")){

chess[xPos-1][yPos-1] = new Chess("〇");

}

for(int i=0;i

for (int j=0;j

System.out.print(chess[i][j].getValue());

}

System.out.println();

}

if(judge(xPos-1,yPos-1)){

flag = false;

System.out.println(run+"获胜");

System.out.println("游戏结束,是否重玩");

String finish = scanner.next();

if (finish.equals("是")){

flag = true;

start();

}

else if (finish.equals("否")){

System.exit(0);

}

}

}else {

System.out.println("该处已存在棋子,请重新选择");

runChess(run);

}

}

public void start(){

initCheck();

System.out.println("请选择先走方:黑棋or白棋");

String run = scanner.next();

for(int i=0;i

for (int j=0;j

System.out.print(chess[i][j].getValue());

}

System.out.println();

}

while (flag) {

switch (run) {

case "黑棋":

runChess("黑棋");

run = "白棋";

break;

case "白棋":

runChess("白棋");

run = "黑棋";

break;

default:

}

}

}

}

结点类

public class Chess {

private String value;

public Chess(String value){

this.value = value;

}

public String getValue() {

return value;

}

}

更多有趣的经典小游戏实现专题,分享给大家:

C++经典小游戏汇总

python经典小游戏汇总

python俄罗斯方块游戏集合

javascript经典游戏 玩不停

javascript经典小游戏汇总

chess[xPos-i][yPos+i].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

for (int i = 1; i < successSize; i++) {

if (xPos + i < CheckerSize && yPos - i >= 0 &&

chess[xPos+i][yPos-i].getValue().equals(chess[xPos][yPos].getValue())) {

count++;

} else {

break;

}

}

return count >= successSize ? true : false;

}

return false;

}

private void runChess(String run){

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] = new Chess("●");

}

else if(run.equals("白棋")){

chess[xPos-1][yPos-1] = new Chess("〇");

}

for(int i=0;i

for (int j=0;j

System.out.print(chess[i][j].getValue());

}

System.out.println();

}

if(judge(xPos-1,yPos-1)){

flag = false;

System.out.println(run+"获胜");

System.out.println("游戏结束,是否重玩");

String finish = scanner.next();

if (finish.equals("是")){

flag = true;

start();

}

else if (finish.equals("否")){

System.exit(0);

}

}

}else {

System.out.println("该处已存在棋子,请重新选择");

runChess(run);

}

}

public void start(){

initCheck();

System.out.println("请选择先走方:黑棋or白棋");

String run = scanner.next();

for(int i=0;i

for (int j=0;j

System.out.print(chess[i][j].getValue());

}

System.out.println();

}

while (flag) {

switch (run) {

case "黑棋":

runChess("黑棋");

run = "白棋";

break;

case "白棋":

runChess("白棋");

run = "黑棋";

break;

default:

}

}

}

}

结点类

public class Chess {

private String value;

public Chess(String value){

this.value = value;

}

public String getValue() {

return value;

}

}

更多有趣的经典小游戏实现专题,分享给大家:

C++经典小游戏汇总

python经典小游戏汇总

python俄罗斯方块游戏集合

javascript经典游戏 玩不停

javascript经典小游戏汇总

for (int j=0;j

System.out.print(chess[i][j].getValue());

}

System.out.println();

}

if(judge(xPos-1,yPos-1)){

flag = false;

System.out.println(run+"获胜");

System.out.println("游戏结束,是否重玩");

String finish = scanner.next();

if (finish.equals("是")){

flag = true;

start();

}

else if (finish.equals("否")){

System.exit(0);

}

}

}else {

System.out.println("该处已存在棋子,请重新选择");

runChess(run);

}

}

public void start(){

initCheck();

System.out.println("请选择先走方:黑棋or白棋");

String run = scanner.next();

for(int i=0;i

for (int j=0;j

System.out.print(chess[i][j].getValue());

}

System.out.println();

}

while (flag) {

switch (run) {

case "黑棋":

runChess("黑棋");

run = "白棋";

break;

case "白棋":

runChess("白棋");

run = "黑棋";

break;

default:

}

}

}

}

结点类

public class Chess {

private String value;

public Chess(String value){

this.value = value;

}

public String getValue() {

return value;

}

}

更多有趣的经典小游戏实现专题,分享给大家:

C++经典小游戏汇总

python经典小游戏汇总

python俄罗斯方块游戏集合

javascript经典游戏 玩不停

javascript经典小游戏汇总

System.out.print(chess[i][j].getValue());

}

System.out.println();

}

if(judge(xPos-1,yPos-1)){

flag = false;

System.out.println(run+"获胜");

System.out.println("游戏结束,是否重玩");

String finish = scanner.next();

if (finish.equals("是")){

flag = true;

start();

}

else if (finish.equals("否")){

System.exit(0);

}

}

}else {

System.out.println("该处已存在棋子,请重新选择");

runChess(run);

}

}

public void start(){

initCheck();

System.out.println("请选择先走方:黑棋or白棋");

String run = scanner.next();

for(int i=0;i

for (int j=0;j

System.out.print(chess[i][j].getValue());

}

System.out.println();

}

while (flag) {

switch (run) {

case "黑棋":

runChess("黑棋");

run = "白棋";

break;

case "白棋":

runChess("白棋");

run = "黑棋";

break;

default:

}

}

}

}

结点类

public class Chess {

private String value;

public Chess(String value){

this.value = value;

}

public String getValue() {

return value;

}

}

更多有趣的经典小游戏实现专题,分享给大家:

C++经典小游戏汇总

python经典小游戏汇总

python俄罗斯方块游戏集合

javascript经典游戏 玩不停

javascript经典小游戏汇总

for (int j=0;j

System.out.print(chess[i][j].getValue());

}

System.out.println();

}

while (flag) {

switch (run) {

case "黑棋":

runChess("黑棋");

run = "白棋";

break;

case "白棋":

runChess("白棋");

run = "黑棋";

break;

default:

}

}

}

}

结点类

public class Chess {

private String value;

public Chess(String value){

this.value = value;

}

public String getValue() {

return value;

}

}

更多有趣的经典小游戏实现专题,分享给大家:

C++经典小游戏汇总

python经典小游戏汇总

python俄罗斯方块游戏集合

javascript经典游戏 玩不停

javascript经典小游戏汇总

System.out.print(chess[i][j].getValue());

}

System.out.println();

}

while (flag) {

switch (run) {

case "黑棋":

runChess("黑棋");

run = "白棋";

break;

case "白棋":

runChess("白棋");

run = "黑棋";

break;

default:

}

}

}

}

结点类

public class Chess {

private String value;

public Chess(String value){

this.value = value;

}

public String getValue() {

return value;

}

}

更多有趣的经典小游戏实现专题,分享给大家:

C++经典小游戏汇总

python经典小游戏汇总

python俄罗斯方块游戏集合

javascript经典游戏 玩不停

javascript经典小游戏汇总

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:@ConfigurationProperties绑定配置信息至Array、List、Map、Bean的实现
下一篇:java项目实现猜拳小游戏
相关文章

 发表评论

暂时没有评论,来抢沙发吧~