项目要求
四连珠游戏,两个玩家交替落子。
每次输入一个数表示在该列落子,由下往上落子。若同一玩家在同行、同列或对角线出现四连珠则获胜。
代码如下
package curriculum.java;
import java.util.Scanner;
public class connectFour {
private static int girds[][] = new int[7][7];
private static int column;
private static int player1 = 1, player2 = 2;// player1表示为R(red),player2表示为Y(yellow)
private static int player = player1; // 初始化先落子的玩家为R玩家
private static int win = 0;// 记录获胜情况
private static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
// 一直循环至有玩家获胜或者平局
while (judgeDraw() == true && win == 0) {
// 一直循环至玩家输入正确
while (true) {
System.out.print("Drop a " + (player == 1 ? "red" : "yellow")
+ " disk at column (0-6): ");
column = input.nextInt();
if (judgeToken(column, player) ==