print("00000\n")
print("0 0\n")
print("00000\n")
//output
00000
0 0
00000
00000 00 00 00 00
在航站楼如何做到这一点?
这将根据用户输入的内容设置一个具有不同状态的控制台。就目前而言,我只有向上(“W”)或向下(“S”)的能力
public static void main(String[] args) {
HashMap<Integer, HashMap<String, String>> consoleStates = CreateConsoleStates();
String input = "default";
Scanner userInput = new Scanner(System.in);
do {
//draw default state of board
if(input.equals("default") || input.equals("w") || input.equals("s"))
printConsole(input, consoleStates);
//get input from user until they exit
input = userInput.nextLine().replaceAll("\n", "");
} while (!input.equals("exit"));
}//main method
public static HashMap<Integer, HashMap<String, String>> CreateConsoleStates()
{
HashMap<Integer, HashMap<String, String>> consoleStates = new HashMap<>();
HashMap<String, String> line1, line2, line3;
line1 = new HashMap<>();
line1.put("default", "00000");
line1.put("w", "00000");
line1.put("s", "00 00");
line2 = new HashMap<>();
line2.put("default", "0 0");
line2.put("w", "00 00");
line2.put("s", "00 00");
line3 = new HashMap<>();
line3.put("default", "00000");
line3.put("w", "00 00");
line3.put("s", "00000");
consoleStates.put(1, line1);
consoleStates.put(2, line2);
consoleStates.put(3, line3);
return consoleStates;
}
public static void printConsole(String state, HashMap<Integer, HashMap<String, String>> consoleStates)
{
//adding this will make it seem like a brand new console as suggested in another answer
//System.out.println("\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
//each number corresponds to the line in the console
System.out.println(consoleStates.get(1).get(state));
System.out.println(consoleStates.get(2).get(state));
System.out.println(consoleStates.get(3).get(state));
}
}
输出如下所示:
00000
0 0
00000
s
00 00
00 00
00000
w
00000
00 00
00 00
e
00000
0 0
00000
exit
注意:我使用的是大多数游戏都有的标准wsad控件。我推荐它.w代表上,a代表左,s代表下,d代表右。此外,每当按下错误的键时,我会显示默认状态,并且使用“exit”退出游戏。
我试图使用TDD(测试驱动开发)与。当我使用时,不会到控制台。 我正在使用来运行它。 似乎说默认情况下它应该工作:http://pytest.org/latest/capture.html 但是: 没有任何东西被打印到我的标准输出控制台(只是正常的进度和多少测试通过/失败)。 我正在测试的脚本包含打印: 在模块中,默认情况下打印所有内容,这正是我所需要的。但是,出于其他原因,我希望使用。 有人知道
打印是不属于 JavaScript 语言标准的功能。但是,我们在这里进行的所有操作,浏览器和 Node.js 都是支持的。 打印意味着“在控制台上显示内容”,其中“控制台”是浏览器控制台或运行 Node.js 的终端。 完整的console.* API 在 MDN 的网页 以及 Node.js 官网都有相关文档。接下来我们将快速浏览以下两个操作: console.log() console.err
问题内容: 如何在控制台中打印颜色?我想在处理器发送数据时以彩色显示数据,而在接收数据时以不同的颜色显示数据。 问题答案: 我创建了一个名为JCDP(Java彩色调试打印机)的库。 对于Linux,macOS和Windows 10,它使用WhiteFang提到的ANSI转义代码,但是使用单词而不是代码来抽象它们,这更加直观。它变得像:
问题内容: 如何打印(在控制台),,等这个结构中Golang的? 问题答案: 要在结构中打印字段名称: 从包装中: 打印结构时,加号()添加字段名称 假设您有一个Project的实例(在’ ‘中) 文章JSON和Go将提供有关如何从JSON结构中检索值的更多详细信息。 此“按示例进行搜索”页面提供了另一种技术: 那会打印: 如果没有任何实例,则需要 使用反射 来显示给定结构的字段名称,如本例所示。
如何在Golang中打印(在控制台中)该结构的、、等?
问题内容: 我使用urlib打我的应用程序而不是浏览器,所以发生错误时我看不到调试屏幕。将常规调试信息发送到控制台或文件的最佳方法是什么? 编辑:我已经捕获了页面的输出,但是当我将其打印到屏幕上时,它充满了无用的html吨。我可以得到错误吗? 问题答案: 我建议使用以下使用内置日志记录系统的方法之一。 以类似的方式将异常通过管道传递到管理员电子邮件处理程序,你可以将数据发送到控制台记录器,文件记录