java - 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() {
}
}
解决方案
要决定哪个玩家在玩,你可以有一个boolean
变量,例如boolean player1
. 只要player1
为真,则轮到第一个玩家。当它为假时,是第二个玩家轮到。在播放器完成后的方法中,您可以添加该行
player1 = !player1;
切换 的值,player1
以便在下一回合您的程序将知道玩家已切换。
推荐阅读
- python - 从没有 homedir 的用户的 tex 生成 pdf
- c++ - 为什么'static'关键字允许函数返回正确的引用?
- android - Retrofit 2 错误响应处理
- mbed - 我可以将简易连接库与 Roving Network XV Wifi 模块一起使用吗?
- python - python SELECT COLUMN FROM TABLE WHERE COLUMN = self.variable
- html - CSS 流体视频
- c++ - GetModuleHandle() 无法检索“notepad.exe”加载的“advapi32.dll”句柄
- python - 来自串行的高延迟
- spring - 使用 Kotlin 在 Spring 中注入组件的最佳方法
- linux - 如何在远程机器上 ssh 时在 lua 脚本中自动提供密码