java - (JAVA)我必须将一个字符放入数组中,然后我必须移动字符(扫描仪)
问题描述
我必须在数组中放置一个 X,然后我必须移动 X(左、上、右、下)。我想我必须用 java.util.Scanner 来做。我需要帮助。
我用数组创建了一个字段,点是我可以移动我的 X(播放器)的字段。
规则:我不能移动到 R 或 O
public class Main {
public static void main(String[] args) {
final int WIDTH = 18;
final int HEIGHT = 11;
final int CHAR_COUNT = 30;
final int PLAYER = 1;
final int endgame = 1;
final int PLAYERCOUNTER = 2;
final char[] CHARS = {
'R',
'O'
};
final char[] PLAYERPOINTS = {
'X',
'+'
};
String player = "X";
// Create field filled with '.'
char[][] field = new char[HEIGHT][WIDTH];
for (int i = 0; i < HEIGHT; i++) {
Arrays.fill(field[i], '.');
}
// the holes and robots (R and O)
Random random = new Random();
for (char ch: CHARS) {
for (int j = 0, x, y; j < CHAR_COUNT; j++) {
do {
x = random.nextInt(WIDTH);
y = random.nextInt(HEIGHT);
} while (field[y][x] != '.');
field[y][x] = ch;
}
}
//print field
for (char[] row: field) {
System.out.println(Arrays.toString(row).replaceAll(",", "") + " ");
}
//Player
Scanner input = new Scanner(System.in);
}
}
解决方案
推荐阅读
- javascript - 过滤不以字母开头的字符串数组
- xml - 在 GJS 中解析 XML?
- java - 如何从表单获取输入值到servlet
- java - 如何将字符串从 HQL 查询结果转换为 ManagedBean 中的日期
- ffmpeg - 如何使用 ffmpeg 为编码的视频添加字幕?
- c++ - Visual Studio Code 运行环境
- batch-file - 用于获取文件夹和子文件夹列表以及类型为文件的批处理脚本
- excel - Excel 帮助:查找/匹配案例的适当函数
- wordpress - 禁用特定用户的密码更改选项
- javascript - Office.js:AddImage() 在 Excel 在线版本中不起作用