如何在控制台中输出多行角色图像
我正在开发基于文本的游戏,我想让标题吸引人。我试图将文本转换为ASCII转换器来制作一个漂亮的标题,然后将其复制并粘贴到我的代码中以输出它,但它不起作用。
这是我试图做的:
System.out.println("
██████╗ ██╗ ██╗███╗ ██╗ ██████╗ ███████╗ ██████╗ ███╗ ██╗ ██████╗ ███████╗
██╔══██╗██║ ██║████╗ ██║██╔════╝ ██╔════╝██╔═══██╗████╗ ██║ ██╔═══██╗██╔════╝
██║ ██║██║ ██║██╔██╗ ██║██║ ███╗█████╗ ██║ ██║██╔██╗ ██║ ██║ ██║█████╗
██║ ██║██║ ██║██║╚██╗██║██║ ██║██╔══╝ ██║ ██║██║╚██╗██║ ██║ ██║██╔══╝
██████╔╝╚██████╔╝██║ ╚████║╚██████╔╝███████╗╚██████╔╝██║ ╚████║ ╚██████╔╝██║
╚═════╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═════╝ ╚══════╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═════╝ ╚═╝
████████╗██╗ ██╗███████╗ ███████╗ ██████╗ ██████╗ ██████╗ ██████╗ ████████╗████████╗███████╗███╗ ██╗
╚══██╔══╝██║ ██║██╔════╝ ██╔════╝██╔═══██╗██╔══██╗██╔════╝ ██╔═══██╗╚══██╔══╝╚══██╔══╝██╔════╝████╗ ██║
██║ ███████║█████╗ █████╗ ██║ ██║██████╔╝██║ ███╗██║ ██║ ██║ ██║ █████╗ ██╔██╗ ██║
██║ ██╔══██║██╔══╝ ██╔══╝ ██║ ██║██╔══██╗██║ ██║██║ ██║ ██║ ██║ ██╔══╝ ██║╚██╗██║
██║ ██║ ██║███████╗ ██║ ╚██████╔╝██║ ██║╚██████╔╝╚██████╔╝ ██║ ██║ ███████╗██║ ╚████║
╚═╝ ╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝ ╚══════╝╚═╝ ╚═══╝");
但似乎没有用。我知道它在JavaScript中起作用,但我想知道它是否也可以在Java中使用。
I am developing a text-based game and I want to make the title something catchy. I tried to use a text to ASCII converter to make a nice-looking title and then copy and paste it in my code to output it, but it didn't work.
Here is what I tried to do:
System.out.println("
██████╗ ██╗ ██╗███╗ ██╗ ██████╗ ███████╗ ██████╗ ███╗ ██╗ ██████╗ ███████╗
██╔══██╗██║ ██║████╗ ██║██╔════╝ ██╔════╝██╔═══██╗████╗ ██║ ██╔═══██╗██╔════╝
██║ ██║██║ ██║██╔██╗ ██║██║ ███╗█████╗ ██║ ██║██╔██╗ ██║ ██║ ██║█████╗
██║ ██║██║ ██║██║╚██╗██║██║ ██║██╔══╝ ██║ ██║██║╚██╗██║ ██║ ██║██╔══╝
██████╔╝╚██████╔╝██║ ╚████║╚██████╔╝███████╗╚██████╔╝██║ ╚████║ ╚██████╔╝██║
╚═════╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═════╝ ╚══════╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═════╝ ╚═╝
████████╗██╗ ██╗███████╗ ███████╗ ██████╗ ██████╗ ██████╗ ██████╗ ████████╗████████╗███████╗███╗ ██╗
╚══██╔══╝██║ ██║██╔════╝ ██╔════╝██╔═══██╗██╔══██╗██╔════╝ ██╔═══██╗╚══██╔══╝╚══██╔══╝██╔════╝████╗ ██║
██║ ███████║█████╗ █████╗ ██║ ██║██████╔╝██║ ███╗██║ ██║ ██║ ██║ █████╗ ██╔██╗ ██║
██║ ██╔══██║██╔══╝ ██╔══╝ ██║ ██║██╔══██╗██║ ██║██║ ██║ ██║ ██║ ██╔══╝ ██║╚██╗██║
██║ ██║ ██║███████╗ ██║ ╚██████╔╝██║ ██║╚██████╔╝╚██████╔╝ ██║ ██║ ███████╗██║ ╚████║
╚═╝ ╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝ ╚══════╝╚═╝ ╚═══╝");
But it didn't seem to work. I know it works in JavaScript, but I was wondering if it would also work in Java.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
字符串
文字 - 是一个字符串由双引号中包含的零或多个字符组成
“ myText”
。正是您尝试过它,就无法在Java中创建多行字母字体。根据语言规范,这是一个编译时错误,线侧端终止。
为了制作这样的字符串文字编译,可以用新的行字符
\ n
替换行终止。为了使其可读性,结果的字符串可能会变得很长每个部分。
尽管它会起作用,但可能很乏味。
带有Java 15的文本块
您可以使用文本块可用。
为了创建文本块,您需要将目标多行文本包装在三重双引号字符
“”“”“
。 “ 应立即为 ,然后是线终止,并且文本块的实际主体始终在下一行开始。
String literals
String literal - is a string consists of zero or more characters enclosed in double quotes
"myText"
.It is not possible to create a multiline string literal in Java, precisely as you've tried it. According to the language specification it's a compile-time error, line termination is present in a string lateral.
To make such string literal compile, line termination can be replaced with a new line character
\n
.The resulting string can become very long, in order to make it readable you can split the string into chunks concatenated with a plus sign
+
, appending a new line character\n
to each chunk.Although it'll work, it might be tedious.
Text Blocks
With Java 15 you can create a multiline string using text blocks available.
In order to create a text block, you need to enclose the target multiline text in triple double-quote characters
"""
.Note that the opening delimiter
"""
should be immediately followed by the line termination, and the actual body of the text block always starts on the next line.