2015-11-03 87 views
6

我创建了这个程序,以帮助在我创建的文本冒险中绘制地图。到目前为止,它所做的只是画出你输入的黑色方格。有没有办法去除每条线之间的空间,所以没有白线穿过广场?如何去除印刷线条之间的空白?

这里是我的代码:

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:

enter image description here

我花了截图,因为它是很难看到什么,我正在谈论这个字体

每一个新的块之间有一个小的差距,使它看起来不正确。有可能没有办法解决这个问题,但我想我会问,以防万一。

+2

线条之间的空格是字符顶部和线条顶部之间的空格。你的问题是与字体,而不是代码。 –

+0

谢谢!但是,如何更改字体? (对不起,我很新) – tarboy9

+0

你的输出在哪里?你使用IDE吗? –

回答

5

您可能需要将您的System.out重定向到其他地方。
如果你想与Swing工作,那么你可以看看here

然后,它就是你把它重定向其他地方的责任。
但现在它只是你的IDE的一个东西(Eclipse)。它独立于您的Java逻辑。

如果你认真考虑它。您不想在您的Eclipse IDE中播放文字冒险。因此,如果您使用的是Windows,接下来的问题是您是否想要使用窗口命令行。这对你来说可能已经足够了。但我仍然会建议先思考要在哪种窗口中输入文字

+0

谢谢!我认为这会起作用。 – tarboy9