我创建了这个程序,以帮助在我创建的文本冒险中绘制地图。到目前为止,它所做的只是画出你输入的黑色方格。有没有办法去除每条线之间的空间,所以没有白线穿过广场?如何去除印刷线条之间的空白?
这里是我的代码:
import java.util.Scanner;
public class MapGrid {
static String createGrid(int x, int y) {
String output = "";
String block = new String("\u2588\u2588"); //A string of two unicode block symbols: ██
if(x * y != 0) { //If neither x nor y is 0, a map of length x and height y will be returned
for(int n = 1; n <= y; n++) {
for(int i = 1; i <= x; i++) {
output += block;
}
output += "\n";
}
}
return output;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
try(Scanner sc = new Scanner(System.in)) {
System.out.println("Please enter the length of your map");
int length = sc.nextInt();
System.out.println("Please enter the height of your map");
int height = sc.nextInt();
System.out.println(createGrid(length,height));
}
}
}
这是它打印,当用户输入5和5:
我花了截图,因为它是很难看到什么,我正在谈论这个字体
每一个新的块之间有一个小的差距,使它看起来不正确。有可能没有办法解决这个问题,但我想我会问,以防万一。
线条之间的空格是字符顶部和线条顶部之间的空格。你的问题是与字体,而不是代码。 –
谢谢!但是,如何更改字体? (对不起,我很新) – tarboy9
你的输出在哪里?你使用IDE吗? –