我是一名编程初学者,需要编写一些代码来创建一个简单的游戏,在屏幕上提供一个10x10矩阵板。 (上),D(下),左(左)& R(右)键盘笔画,同时在途中吃甜甜圈,并避免与墙壁达到家庭'H'位置的目标。Java甜甜圈游戏
该程序应该随机放置两个垂直的墙壁,其中包括一排5'X',以及一个水平墙壁包含一个5'X'的水平排。 两个垂直墙不应相交,但可能与水平线相交或邻接。否'X'应放置在董事会最左边,最右边,最上面或最下面的'禁止区'。
五个象征为'@'的甜甜圈应该随机放置。不能将甜甜圈放在'禁区'或墙壁上的任何广场上。没有被墙壁,甜甜圈,玩家或家庭占据的广场标有'。'。一旦一名玩家登上他吃的甜甜圈,在离开那个方格时,'@'应该被替换为'。'。
我正在努力将随机放置的墙壁和甜甜圈合并到上述规则中。
package doughnut;
import java.util.Random;
import java.util.Scanner;
/**
*
* @author Torrin
*/
public class Doughnut {
static int row = 10;
static int column = 10;
static char[][] table = new char[row][column];
static int num = 5;
private static Random random = new Random();
public static void main(String[] args) {
setArray();
displayArray();
//buildWallsArray();
Scanner scan = new Scanner(System.in);
}
static void setArray() {
for (int i = 0; i < row; i++) {
for (int j = 0; j < column; j++) {
table[i][j] = '.';
}
}
table[9][0] = 'P';
table[0][9] = 'H';
}
static void displayArray() {
for (int i = 0; i < row; i++) {
for (int j = 0; j < column; j++) {
System.out.print(table[i][j]);
}
System.out.println();
}
}
/*static void buildWallsArray() {
int counter = 0;
int X, Y;
while (counter < num) {
int i = random.nextInt(8);
X = i + 1;
int j = random.nextInt(4);
Y = j + 3;
if (table[i][j] == '.') {
table[i][j] = 'X';
++counter;
System.out.print(table[i][j]);
}
System.out.println();
*/
}
package rand;
import java.util.Random;
public class Rand {
private static Random random = new Random();
//Random placement for vertical walls
public static void main(String[] args) {
system.out.print("Running Test");
vertical();
horizontal();
}
public static void vertical(String[] args) {
int X, Y;
int n = random.nextInt(7);
X = n + 1;
System.out.print("Vertical X" + "=" + X);
int m = random.nextInt(3);
Y = m + 3;
System.out.println("Vertical Y" + "=" + Y);
}
//Random placement of horizontal wall
public static void horizontal(String[] args) {
int X, Y;
int n = random.nextInt(4);
X = n + 3;
System.out.print("Horizontal X" + "=" + X);
int m = random.nextInt(8);
Y = m + 1;
System.out.println("Horizontal Y" + "=" + Y);
}
}
请详细说明你说你在哪里挣扎。你的输出错了吗?你有错误吗?还是有你缺少的概念? –