我在运行我的程序时遇到问题。该程序应该构建一个由墙壁组成的盒子,该盒子应该覆盖 5-10 条街道/大道,并且每次运行程序时都有不同的大小和位置。虽然有时在运行它时我只得到 1 条大道和街道或 5 条以下的东西?我错过了什么?
public class CityWalls extends Thing {
public CityWalls(City c, int st, int av, Direction d) {
super(c, st ,av ,d);
Random rand = new Random();
int randomNum = rand.nextInt(11);
int oddIncrement = 0;
if (randomNum % 2 == 0)
{
oddIncrement = 1;
}
for (int i = 0; i < randomNum; i++) { // creating the box. 7 is the placement of the robot so he appears in the middle of the box.
new Wall(c, i+(7-randomNum/2), (7-randomNum/2), Direction.WEST);
new Wall(c, i+(7-randomNum/2), (7+randomNum/2) - oddIncrement, Direction.EAST);
new Wall(c, (7-randomNum/2), i+(7-randomNum/2), Direction.NORTH);
new Wall(c, (7+randomNum/2)-oddIncrement, i+(7-randomNum/2), Direction.SOUTH);
}