网站建设资讯

NEWS

网站建设资讯

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 Chess[CheckerSize][CheckerSize];
 }
 private void initCheck(){
 for(int i=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 (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= 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= 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=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= 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

结点类

public class Chess {
 private String value;
 public Chess(String value){
 this.value = value;
 }
 public String getValue() {
 return value;
 }
}

看完这篇关于Java项目如何实现五子棋小游戏的文章,如果觉得文章内容写得不错的话,可以把它分享出去给更多人看到。


当前文章:Java项目如何实现五子棋小游戏
URL分享:http://cdweb.net/article/geodid.html