首页 > 解决方案 > Java:更改播放器

问题描述

我不知道如何编写转换回合来改变玩家正在玩

编辑:从布尔播放器或 while ...

import java.util.*;
public class Assignment {
static Scanner sc = new Scanner(System.in);
static int height = 6, width = 6, blank = 0;          //do checkerboard
static int white = 1, black = 2;                      //do player chess
static int[][] board;
    public static void main(String[] args) {
    board = new int[height][width];

    board[width / 2-1][height / 2-1] = board[width / 2][height / 2] = 1;
    board[width / 2-1][height / 2] = board[width / 2][height / 2-1] = 2;

    printHead();
    printboard();
    input();
}
    public static void input() {

}

}

标签: java

解决方案


要决定哪个玩家在玩,你可以有一个boolean变量,例如boolean player1. 只要player1为真,则轮到第一个玩家。当它为假时,是第二个玩家轮到。在播放器完成后的方法中,您可以添加该行

player1 = !player1;

切换 的值,player1以便在下一回合您的程序将知道玩家已切换。


推荐阅读