gpt4 book ai didi

JAVA:文字游戏查询

转载 作者:行者123 更新时间:2023-12-01 13:33:32 25 4
gpt4 key购买 nike

各位程序员大家好!

到目前为止我有这个代码:

public class Levels {
int cLevel;

public void newGame() {
boolean newGame = true;
if (newGame) {
cLevel = 1;

List<String> list = new ArrayList<String>();

try {
BufferedReader bf = new BufferedReader(new FileReader(
"src/WordGuess/ReadFile/LevelFiles/Level_" + cLevel
+ ".txt"));
String cLine;
while ((cLine = bf.readLine()) != null) {
list.add(cLine);
}
String words[] = new String[list.size()];
words = list.toArray(words);

System.out
.println("These are your help letters so you can beat that level: "
+ words[0]);

for (int i = 1; i < words.length; i++) {
char[] replaceChar = words[i].toCharArray();

for (int x = 0; x < replaceChar.length; x++) {
replaceChar[x] = '*';
}
String replacement = new String(replaceChar);

System.out.println("\f" + replacement);

}

System.out.println("\t Score: " + Score(0) + ";\t Lives: "
+ Lives(5) + ";");

System.out.println("\n Enter Word:");
System.in.read();

} catch (Exception e) {
System.out
.println("Oh! Something went terribly wrong. A team of highly trained and koala-fied koalas have been dispatched to fix the problem. If you dont hear from them please restart this program.");
e.printStackTrace();
}
}
}

private int Lives(int lives) {
int wrongTries = 0;
boolean correctWord;
int counter = 0;

String livesForm[] = new String[lives];

// for (int i = 0; i == lives; i++) {
// livesForm[i] = "♥";
// }

return lives;
}

private int Score(int score) {

return score;
}}

所以我的查询如下。

我想将生命显示为心形符号,并仍保留其整数值以用于功能目的。因此,如我的代码示例所示,5 条生命由 5 颗心表示,但仍保持 int 生命值 5。如我的示例所示,我还尝试使用整数值“生命”大小的字符串数组,并将被心取代。据我运行代码,没有显示任何错误,所以我假设数组已填充,但我不知道如何在控制台中将数组显示为“Lives:♥♥♥♥♥”。

我尝试过常规:

System.out.println(livesForm[i]);

但它没有显示任何内容。我不知道我的问题是否已经完全清晰地表达出来了。如果你们中的任何人能给我建议或提示,我会很高兴。感谢您花时间回答这个问题!

最佳答案

为什么不:

public String getLivesAsString(int lives) {
StringBuilder sb = new StringBuilder(lives);
for(int i = 0; i < lives; i++) {
sb.append("♥");
}
return sb.toString();
}

不确定为什么需要一个数组来显示由整数定义的一定数量的“♥”符号?

关于JAVA:文字游戏查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21419862/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com