五子棋游戏Java代码简单实现(含活动图和类图设计)
活动图设计
![五子棋游戏活动图](https://i-blog.csdnimg.cn/blog_migrate/72de6263f19727af69c4b7876cb15874.png)
类图设计
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/bb9c11e14c3c0ccfcacddd7b8702bc57.png)
代码实现
import java.lang.Math;
import java.io.*;
import java.util.Scanner;
class Gobang
{
private String[][] board;
private static int size = 15;
private int[] score = {
0, 0};
public void initBoard()
{
board = new String[size][size];
for ( int i = 0; i <= size - 1; i++)
{
for ( int j =0 ; j <=size - 1; j++)
board[i][j] = "+";
}
}
public void printBoard()
{
System.out.println("------------------------------");
for ( int i = 0; i < size; i++)
{
for ( int j =0 ; j < size; j++)
{
System.out.print(board[i][j]);
}
System.out.print("\n");
}
System.out.println("------------------------------");
}
public boolean end(String[] posis)
{
boolean flag = false;
String color = posis[0];
for (int i=1; i < 5; i++)
{
if (color != posis[i])
{
flag = false;
break;
}
else
flag = true;
}
if (flag && posis[0] == "●")
{
System.out.println(&#