java - Eclipse 控制台在运行程序的过程中会自行清除的一些原因是什么?
问题描述
我正在 Eclipse 中制作 RPG(基于文本的)游戏。
我尝试使用“System.err.println”调试我的代码,但是,控制台没有显示任何内容,并且似乎处于无限循环打印新行(“\n”)
这是到目前为止我必须运行我的游戏的循环:
while(Health > 0) {
if(!ENEMY) {
output("\n");
ERRoutput("CHECK1");
encounterEnemy(classBase.lvl);
}
move();
if(Health > MAX_HEALTH) {
Health = MAX_HEALTH;
output("\n");
ERRoutput("CHECK2");
}
if(!ENEMY && classBase.XP >= classBase.neededXP){
classBase.lvlUp();
output("\n");
}
if(classBase.LVLUP()) {
output("\n");
ERRoutput("CHECK3");
distributePoints();
if(Strength < 2) Strength = 2;
}
}
这也是唯一使用“\n”的位置(创建新行)
我希望代码的输出是:
- 如果敌人尚未生成,则生成敌人
- 提示用户杀死敌人直到敌人死亡(移动方法)
- 检查是否获得了足够的 XP(经验)来升级
- 重启循环
实际发生的情况:
- 生成敌人
- 提示用户杀死敌人直到敌人死亡(移动方法)
- 检查是否获得了足够的 XP(经验)来升级
- 生成敌人
- 控制台自行清除并陷入无限循环
控制台根本没有输出
对于询问“敌人”分配在哪里的人:
static boolean ENEMY = false;
public static void encounterEnemy(int lvl) {
eHealth = 20;
eHealth *= lvl + 1;
eStamina *= lvl;
eStamina *= lvl;
eStrength *= lvl;
eSpeed *= lvl;
eSpeed /= 2;
eDamage = 8;
eDamage *= lvl;
if(lvl > 7) {
eDamage /= 2;
}
ENEMY = true;
output("A LVL" + lvl + " enemy has appeared!");
showEnemyHealth();
}
它在“encounterEnemy”中分配 (当敌人被杀死时,它在“move()”中再次设置为false)
升级代码:
public static void lvlUp() {
upgrade = true;
lvl++;
Main.output(" _ _ _ _ _ _ _ _");
Main.output("| |");
Main.output("| LVL UP |");
Main.output("| LEVEL: " + lvl + " |");
Main.output("| HEALTH:+25 |");
Main.output("| STAMINA:+15 |");
Main.output("| STEALTH:+5 |");
Main.output("| STRENGTH:+15 |");
Main.output("| SPEED:+2 |");
Main.output("| _ _ _ _ _ _ _ |");
Main.Health += 25;
Main.Stamina += 15;
Main.Stealth += 5;
Main.Strength += 15;
Main.Speed += 2;
neededXP = 35*lvl;
XP = 0;
}
对于询问所有大写字母的升级方法是什么的人:
public static boolean LVLUP() {
if(upgrade) {
upgrade = false;
Main.points += 2;
return true;
} else {
upgrade = false;
return false;
}
}
最后但并非最不重要的一点是 move 方法:
static boolean proceed;
static boolean Continue;
public static void move() {
while(Health > 0 && eHealth > 0 && Health > 0) {
showStats();
proceed = true;
Continue = true;
output("What do you do?");
if(classBase.dmg_Spls == true) {
output("[10] Damage enemy with spell (Damage: " + (7.5*classBase.lvl) + ")");
}
if(classBase.heal_Spls == true) {
output("[2] Heal self with spell (Health Restore: 10 * lvl)");
}
output("[33] Attack with class weapon (Damage: " + (Strength/2) + " (Strength / 2))");
output("[41] Drink Elixer of Death");
try {
validMove = false;
while(!validMove) {
input(" -> ");
int move = Integer.parseInt(scan.nextLine());
if(move < 0 || move > 4) {
proceed = false;
}
if(move != 10 && move != 2 && move != 33 && move != 41) {
proceed = false;
}
if(move == 10 || move == 2 || move == 33 || move == 41) proceed = true;
if(move == 10 && (classBase.sselcClass == "Mage" || classBase.sselcClass == "Demon")) {
Damage = 0;
Damage = (15 * classBase.lvl);
Damage /= 2;
validMove = true;
} else if(move == 2 && (classBase.sselcClass == "Mage" || classBase.sselcClass == "Priest")) {
Damage = 0;
Health += (10*classBase.lvl);
if(Health > MAX_HEALTH) {
Health = MAX_HEALTH;
}
validMove = true;
} else if(move == 33) {
Damage = Strength / 2;
validMove = true;
} else if(move == 41) {
Health = 0;
output("You Killed Yourself! (Health: " + Health + " )");
System.exit(-1);
}
}
} catch (NumberFormatException e) {
ERRoutput("Please enter a valid numberical value!");
}
if(!proceed) {
Continue = false;
while(!proceed) {
output("What do you do? (Select Number)");
if(classBase.dmg_Spls == true) {
output("[10] Damage enemy with spell (Damage: " + (7.5*classBase.lvl) + ")");
}
if(classBase.heal_Spls == true) {
output("[2] Heal self with spell (Health Restore: 10 * lvl)");
}
output("[33] Attack with class weapon (Damage: " + (Strength/2) + " (Strength / 2))");
output("[41] Drink Elixer of Death");
try {
validMove = false;
while(!validMove) {
input(" -> ");
int move = Integer.parseInt(scan.nextLine());
if(move < 0 || move > 4) {
proceed = false;
}
if(move != 10 && move != 2 && move != 33 && move != 41) {
proceed = false;
}
if(move == 10 || move == 2 || move == 33 || move == 41) proceed = true;
if(move == 10 && (classBase.sselcClass == "Mage" || classBase.sselcClass == "Demon")) {
Damage = 0;
Damage = (15 * classBase.lvl);
Damage /= 2;
validMove = true;
} else if(move == 2 && (classBase.sselcClass == "Mage" || classBase.sselcClass == "Priest")) {
Damage = 0;
Health += (10 * classBase.lvl);
if(Health > MAX_HEALTH) {
Health = MAX_HEALTH;
}
} else if(move == 33) {
Damage = Strength / 2;
} else if(move == 41) {
Health = 0;
output("You Killed Yourself! (Health: " + Health + " )");
System.exit(-1);
}
}
} catch (NumberFormatException e) {
ERRoutput("Please enter a valid numberical value!");
}
}
}
eHealth -= Damage;
showEnemyHealth();
int allowed;
int am = 0;
if(Stealth != 0) {
for(int i = 0; i < Stealth/2; i++) {
am++;
}
} else {
am = 0;
}
allowed = r.nextInt(am);
if(allowed == 0) {
if(proceed && eHealth > 0) {
output("Enemy attacked and dealt " + eDamage + " damage!");
Health -= eDamage;
if(Health <= 0) {
output("You have died! (Health: " + Health + ")");
System.exit(-1);
}
} else if(eHealth <= 0) {
output("Enemy defeated!");
classBase.XP += 5;
ENEMY = false;
}
} else {
output("The enemy missed it's attack!");
}
}
if(Health == 0) {
output("You have died! (Health: " + Health + ")");
System.exit(-1);
}
}
解决方案
推荐阅读
- react-native - React Native:在哪里放置其他屏幕的导航器?
- nginx - nginx服务404而不传递给代理
- r - 处理在 R 中记录数据集的错误
- c# - Asp.Net Microsoft 身份和 OAuth 和 OpenId
- php - 用 XAMPP 托管我的项目破坏了我的 MVC 结构
- python - MIMEImage 中包含的 svg 文件未正确显示在 html 电子邮件中
- ios - 当 iOS 应用程序进入后台时,gRPC 服务器停止接收请求
- swift - 如果有条件,@ObservedObject 不会触发重绘
- python - 大熊猫在json标准化后删除句点
- nested-loops - get_the_content() 和无限嵌套循环中的 wordpress 简码