- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我不确定这个问题或类似的问题以前是否有人问过,但我搜索了又搜索,但一无所获。我刚在学校开始编程,但是老师给我们的项目,我可以很快完成,而且几乎有点太简单了,所以我开始看 Oracle 的 java 教程。经过大量的实验,我决定基于 MGSV TPP 制作一款基于文本的潜行游戏。无论如何,背景故事已经足够了。我的问题是我的代码中的开关没有执行。没什么。我一遍又一遍地检查我的代码,但我不知道出了什么问题。这是我第一次使用开关。以下是带有开关的代码片段:
public void shoot() {
Random rand = new Random();
String farshot = this.shoot[rand.nextInt(this.shoot.length)];
if(reload == 1) {
if(supressor > 1) {
if(dbme<=75) {
System.out.println("Great Job! He's out cold!");
if(dbme == Guard1)
Guard1 = 0;
else if(dbme == Guard2)
Guard2 = 0;
else if(dbme == Guard3)
Guard4 = 0;
else if(dbme == Guard4)
Guard4 = 0;
else if(dbme == Guard5)
Guard5 = 0;
else if(dbme == Guard6)
Guard6 = 0;
else if(dbme == Guard7)
Guard7 = 0;
else if(dbme == Guard8)
Guard8 = 0;
dbme = 0;
reload = 0;
supressor--;
}
} else { System.out.println("You're suppressor had worn out! You alerted the guards! But Great shot, you knocked him out!");
if(dbme == Guard1)
Guard1 = 0;
else if(dbme == Guard2)
Guard2 = 0;
else if(dbme == Guard3)
Guard4 = 0;
else if(dbme == Guard4)
Guard4 = 0;
else if(dbme == Guard5)
Guard5 = 0;
else if(dbme == Guard6)
Guard6 = 0;
else if(dbme == Guard7)
Guard7 = 0;
else if(dbme == Guard8)
Guard8 = 0;
dbme = 0;
reload = 0;
supressor--;
alert = 1;
actions();
}
if(dbme > 75)
System.out.println("He's too faraway. but...");
switch (farshot) {
case "headshot":
System.out.println("Wow! You're a great shot! He's out cold! He's now unmarked");
if(dbme == Guard1)
Guard1 = 0;
else if(dbme == Guard2)
Guard2 = 0;
else if(dbme == Guard3)
Guard4 = 0;
else if(dbme == Guard4)
Guard4 = 0;
else if(dbme == Guard5)
Guard5 = 0;
else if(dbme == Guard6)
Guard6 = 0;
else if(dbme == Guard7)
Guard7 = 0;
else if(dbme == Guard8)
Guard8 = 0;
dbme = 0;
break;
case "miss":
if(supressor != 0)
System.out.println("YOU MISSED! But Your shot was suppressed, so you're safe!");
else {
System.out.println("YOU MISSED! You've alerted everyone of your presence!!!!");
reload = 0;
combat();
}
break;
case "alert":
System.out.println("It wasn't a headshot, but he doesn't know anything yet. He's alerted, so becareful!");
break;
}
dbme = 0;
actions();
reload = 0;
} else { System.out.println("Reload your gun first!");
markedAction();
}
}
我不确定您是否还需要更多内容,但这是完整的代码:
package metalgear;
import java.util.Scanner;
import java.util.Random;
public class MetalGear {
//Arrays
String[] objects = {"Food, Water, Ammo, Suppressor, Mags"};
String[] shoot = {"miss, headshot, alert"};
//Player
int health = 150;
int ammo = 10;
int food = 5; //5 packets
int water = 2; //2 liters
int damage = 20;
int xp;
int reload;
int supressor = 10;
int mags = 1;
int dbme;
String recon = "";
//Enemy
int distanceFromEnemyGuard = 200;
int returnDamage;
int foodDrop = 30;
int waterDrop = 20;
int ammoDrop = 50;
int emags = 15;
int esupp = 10;
int alert = 0;
int Guard1 = -1;
int Guard2 = -1;
int Guard3 = -1;
int Guard4 = -1;
int Guard5 = -1;
int Guard6 = -1;
int Guard7 = -1;
int Guard8 = -1;
int locations = 0;
public void enter() {
java.util.Scanner keyboard = new java.util.Scanner(System.in);
keyboard.nextLine();
}
public static void main(String[] args) {
MetalGear a=new MetalGear();
a.intro();
a.Page1();
}
public void intro()
{
java.util.Scanner input = new java.util.Scanner(System.in);
String x;
System.out.println("Welcome to a Text-Based Mission of MGSV-The Phantom Pain");
System.out.print("Enter your name... ");
x = input.next();
System.out.println("");
System.out.print("Hello " + x + ". " + "I'm Ocelot, and I'll be breifing you on your mission today. [Press Enter]");
enter();
System.out.print("Your job is to succesfully infiltrate the Soviet outpost located ");
enter();
System.out.print("at the village of Di Wialo Kalai in Afghanistan.");
enter();
System.out.print("Currently, you have 150 health, you do 20 damage,");
enter();
System.out.print("Have 10 bullets in your gun, and 5 food packets,");
enter();
System.out.print("2 liters of water, and 1 magazine(10 bullets) in your ");
enter();
System.out.println("Backpack. Use your supplies wisely.");
System.out.println("");
}
public void Page1() {
System.out.println("The chopper has dropped you at the best recon point at the edge of Di Wialo Kalai");
actions();
}
//Action Methods
public void actions() {
Scanner in = new Scanner(System.in);
String y;
System.out.println("");
System.out.println("Now, You... (Type help for a list of commands)");
y = in.next();
if(y.equalsIgnoreCase("help"))
help();
else if (y.equalsIgnoreCase("Recon"))
recon();
else if (y.equalsIgnoreCase("Reload"))
reload();
else if (y.equalsIgnoreCase("Backpack"))
backpack();
else if (y.equalsIgnoreCase("iDroid"))
iDroid();
else if (y.equalsIgnoreCase("Mark"))
marking();
else {
System.out.println("You can't do that!");
System.out.println("");
actions();
}
}
public void backpack() {
Scanner in = new Scanner(System.in);
String x;
boolean n = true;
while(n) {
System.out.println("You have " + this.food + " packets");
System.out.println("You have " + this.water + " liters of water");
System.out.println("You have " + this.mags + " magazines");
System.out.println("You can 'eat', 'drink', or 'load mag', or exit");
x = in.next();
if(x.equalsIgnoreCase("eat")) {
if(this.food >= 1) {
this.food--;
this.health += 30;
System.out.println("");
System.out.println("You now have " + health + " health");}
else {
System.out.println(""); System.out.println("You don't have enough food"); }
}
else if(x.equalsIgnoreCase("drink")) {
this.damage +=5;
this.water--;
System.out.println("");
System.out.println("You will now do " + damage + " damage"); }
else if(x.equalsIgnoreCase("load mag")) {
this.ammo = 10;
this.mags--;
System.out.println(""); System.out.println("Your now has full ammo(20 shots)");
System.out.println("");
}
else if(x.equalsIgnoreCase("exit"))
actions();
else System.out.println("YOu can't do that!"); System.out.println("");
backpack(); }
}
public void iDroid() {
Scanner in = new Scanner(System.in);
System.out.println("You have " + health + " health left");
System.out.println("You still have " + supressor + " suppressed shots left.");
System.out.println("You can currently do " + damage + " damage");
System.out.println("And your gun's magazine currently has " + ammo + " ammo left" );
if(!"".equals(recon))
System.out.println(recon);
else
System.out.println("You haven't obtained any intel files yet");
System.out.println("");
if((Guard1 != 1) && (Guard2 != 1) && (Guard3 != 1) && (Guard4 != 1) && (Guard5 != 1) && (Guard6 != 1) && (Guard7 != 1) && (Guard8 != 1)) {
if(Guard1 == 0) System.out.println("Guard 1 was eliminated"); else System.out.println("Guard 1 is " + Guard1 + " meters away.");
if(Guard2 == 0) System.out.println("Guard 2 was eliminated"); else System.out.println("Guard 2 is " + Guard2 + " meters away.");
if(Guard3 == 0) System.out.println("Guard 3 was eliminated"); else System.out.println("Guard 3 is " + Guard3 + " meters away.");
if(Guard4 == 0) System.out.println("Guard 4 was eliminated"); else System.out.println("Guard 4 is " + Guard4 + " meters away.");
if(Guard5 == 0) System.out.println("Guard 5 was eliminated"); else System.out.println("Guard 5 is " + Guard5 + " meters away.");
if(Guard6 == 0) System.out.println("Guard 6 was eliminated"); else System.out.println("Guard 6 is " + Guard6 + " meters away.");
if(Guard7 == 0) System.out.println("(Guard 7 was eliminated"); else System.out.println("Guard 7 is " + Guard7 + " meters away.");
if(Guard8 == 0) System.out.println("Guard 8 was eliminated"); else System.out.println("Guard 8 is " + Guard8 + " meters away."); }
else System.out.println("You haven't done any recon yet!");
System.out.println("");
if(locations != 0)
marking();
else actions();
}
public void reload() {
if (this.ammo>1) {
if(this.reload==0) {
this.reload++;
this.ammo--;
System.out.println("Locked and Loaded!");
System.out.println("You now have " + ammo + " ammo left");
System.out.println("");
}
else if(this.reload==1) {
System.out.println("You're gun is already loaded!");
System.out.println(""); }
}
else { System.out.println("You don't have any ammo!");
System.out.println(""); }
if(locations == 2)
markedAction();
else actions();
}
public void help() {
System.out.println("Recon-Spots the number of enemies and each of their distances from you");
System.out.println("Reload- Relaod your weapon. YOu need to do so after EACH shot.");
System.out.println("Backpack- Look, equip, or use your supplies");
System.out.println("iDroid- Tells you your health, your reconed enemies, and intel you have obtained.");
System.out.println("Mark- Marks a Guard, allowing for interaction with that Guard");
System.out.println("");
actions();
}
public void recon() {
Scanner in = new Scanner(System.in);
Random rand = new Random();
if((Guard1 == -1) && (Guard2 == -1) && (Guard3 == -1) && (Guard4 == -1) && (Guard5 == -1) && (Guard6 == -1) && (Guard7 == -1) && (Guard8 == -1)) {
Guard1 = rand.nextInt(this.distanceFromEnemyGuard);
Guard2 = rand.nextInt(this.distanceFromEnemyGuard);
Guard3 = rand.nextInt(this.distanceFromEnemyGuard);
Guard4 = rand.nextInt(this.distanceFromEnemyGuard);
Guard5 = rand.nextInt(this.distanceFromEnemyGuard);
Guard6 = rand.nextInt(this.distanceFromEnemyGuard);
Guard7 = rand.nextInt(this.distanceFromEnemyGuard);
Guard8 = rand.nextInt(this.distanceFromEnemyGuard);
System.out.println("Guard 1 is " + Guard1 + " meters away.");
System.out.println("Guard 2 is " + Guard2 + " meters away.");
System.out.println("Guard 3 is " + Guard3 + " meters away.");
System.out.println("Guard 4 is " + Guard4 + " meters away.");
System.out.println("Guard 5 is " + Guard5 + " meters away.");
System.out.println("Guard 6 is " + Guard6 + " meters away.");
System.out.println("Guard 7 is " + Guard7 + " meters away.");
System.out.println("Guard 8 is " + Guard8 + " meters away.");
actions();
}
else System.out.println("You already reconed the guards! Check your iDroid for their locations!");
actions();
}
public void marking() {
locations = 1;
Scanner in = new Scanner(System.in);
String abs;
if ((Guard1 != -1) && (Guard2 != -1) && (Guard3 != -1) && (Guard4 != -1) && (Guard5 != -1) && (Guard6 != -1) && (Guard7 != -1) && (Guard8 != -1)) {
System.out.println("Which Guard would you like to mark?");
abs = in.next();
if(abs.equalsIgnoreCase("1"))
dbme = Guard1;
else if(abs.equalsIgnoreCase("2"))
dbme = Guard2;
else if(abs.equalsIgnoreCase("3"))
dbme = Guard2;
else if(abs.equalsIgnoreCase("4"))
dbme = Guard4;
else if(abs.equalsIgnoreCase("5"))
dbme = Guard5;
else if(abs.equalsIgnoreCase("6"))
dbme = Guard6;
else if(abs.equalsIgnoreCase("7"))
dbme = Guard7;
else if(abs.equalsIgnoreCase("8"))
dbme = Guard8;
else if(abs.equalsIgnoreCase("idroid")) {
iDroid();
}
else if(abs.equalsIgnoreCase("exit")) {
System.out.println("No one was marked");
locations = 0;
actions();
}
else { System.out.println("That's not a Guard!");
marking();
}
}
else { System.out.println("Do some Recon first! YOu can't mark guards without knowing their locations!");
locations = 0;
actions(); }
System.out.println("");
if(dbme != 0)
markedAction();
}
//----------------------------------------------------------------------------------------------------------
//Marked ACtions
public void markedAction() {
locations = 2;
Scanner in = new Scanner(System.in);
System.out.println("The Guard has been marked. (Type 'help' for another list of commands)");
String x;
x = in.next();
if(x.equalsIgnoreCase("shoot"))
shoot();
else if(x.equalsIgnoreCase("CQC"))
CQC();
else if(x.equalsIgnoreCase("sneak"))
sneak();
else if(x.equalsIgnoreCase("unmark")) {
System.out.println("The Guard has been unmarked");
dbme = 0;
System.out.println("Returning to Actions");
actions();
}
else if(x.equalsIgnoreCase("reload"))
reload();
else if(x.equalsIgnoreCase("help"))
help2();
else { System.out.println("You can't do that"); markedAction();
}
locations = 0;
}
public void shoot() {
Random rand = new Random();
String farshot = this.shoot[rand.nextInt(this.shoot.length)];
if(reload == 1) {
if(supressor > 1) {
if(dbme<=75) {
System.out.println("Great Job! He's out cold!");
if(dbme == Guard1)
Guard1 = 0;
else if(dbme == Guard2)
Guard2 = 0;
else if(dbme == Guard3)
Guard4 = 0;
else if(dbme == Guard4)
Guard4 = 0;
else if(dbme == Guard5)
Guard5 = 0;
else if(dbme == Guard6)
Guard6 = 0;
else if(dbme == Guard7)
Guard7 = 0;
else if(dbme == Guard8)
Guard8 = 0;
dbme = 0;
reload = 0;
supressor--;
}
} else { System.out.println("You're suppressor had worn out! You alerted the guards! But Great shot, you knocked him out!");
if(dbme == Guard1)
Guard1 = 0;
else if(dbme == Guard2)
Guard2 = 0;
else if(dbme == Guard3)
Guard4 = 0;
else if(dbme == Guard4)
Guard4 = 0;
else if(dbme == Guard5)
Guard5 = 0;
else if(dbme == Guard6)
Guard6 = 0;
else if(dbme == Guard7)
Guard7 = 0;
else if(dbme == Guard8)
Guard8 = 0;
dbme = 0;
reload = 0;
supressor--;
alert = 1;
actions();
}
if(dbme > 75)
System.out.println("He's too faraway. but...");
switch (farshot) {
case "headshot":
System.out.println("Wow! You're a great shot! He's out cold! He's now unmarked");
if(dbme == Guard1)
Guard1 = 0;
else if(dbme == Guard2)
Guard2 = 0;
else if(dbme == Guard3)
Guard4 = 0;
else if(dbme == Guard4)
Guard4 = 0;
else if(dbme == Guard5)
Guard5 = 0;
else if(dbme == Guard6)
Guard6 = 0;
else if(dbme == Guard7)
Guard7 = 0;
else if(dbme == Guard8)
Guard8 = 0;
dbme = 0;
break;
case "miss":
if(supressor != 0)
System.out.println("YOU MISSED! But Your shot was suppressed, so you're safe!");
else {
System.out.println("YOU MISSED! You've alerted everyone of your presence!!!!");
reload = 0;
combat();
}
break;
case "alert":
System.out.println("It wasn't a headshot, but he doesn't know anything yet. He's alerted, so becareful!");
break;
}
dbme = 0;
actions();
reload = 0;
} else { System.out.println("Reload your gun first!");
markedAction();
}
}
public void CQC() {
}
public void sneak() {
}
public void combat() {
}
public void help2() {
}
}
感谢您的所有回复!
最佳答案
在代码顶部,您声明字符串数组,但每个数组仅包含一个字符串:
String[] objects = {"Food, Water, Ammo, Suppressor, Mags"};
String[] shoot = {"miss, headshot, alert"};
因此,当您初始化 farshot
变量时
String farshot = this.shoot[rand.nextInt(this.shoot.length)];
它将始终包含值miss、headshot、alert
。这与您正在测试的任何案例都不匹配。
我假设您想要执行以下操作:
String[] objects = {"Food", "Water", "Ammo", "Suppressor", "Mags"};
String[] shoot = {"miss", "headshot", "alert"};
不知道它是否能解决您的所有问题,但这是一个开始。
关于java - 开关不执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33470930/
我有一个“有趣”的问题,即以两种不同的方式运行 wine 会导致: $> wine --version /Applications/Wine.app/Contents/Resources/bin/wi
我制作了这个网络抓取工具来获取网页中的表格。我使用 puppeteer (不知道 crontab 有问题)、Python 进行清理并处理数据库的输出 但令我惊讶的是,当我执行它时 */50 * * *
JavaScript 是否被调用或执行取决于什么?准确地说,我有两个函数,它们都以相同的方式调用: [self.mapView stringByEvaluatingJavaScriptFromStri
我目前正在使用 python 做一个机器学习项目(这里是初学者,从头开始学习一切)。 只是想知道 statsmodels 的 OLS 和 scikit 的 PooledOlS 使用我拥有的相同面板数据
在使用集成对象模型 (IOM) 后,我可以执行 SAS 代码并将 SAS 数据集读入 .Net/C# 数据集 here . 只是好奇,使用 .Net 作为 SAS 服务器的客户端与使用 Enterpr
有一些直接的 jQuery 在单击时隐藏打开的 div 未显示,但仍将高度添加到导航中以使其看起来好像要掉下来了。 这个脚本工作正常: $(document).ready(funct
这个问题已经有答案了: How do I compare strings in Java? (23 个回答) 已关闭 4 年前。 这里是 Java 新手,我正在使用 NetBeans 尝试一些简单的代
如果我将它切换到 Python 2.x,它执行 10。这是为什么? 训练逻辑回归模型 import keras.backend as
我有两个脚本,它们包含在 HTML 正文中。在第一个脚本中,我初始化一个 JS 对象,该对象在第二个脚本标记中引用。 ... obj.a = 1000; obj.
每当我运行该方法时,我都会收到一个带有数字的错误 以下是我的代码。 public String getAccount() { String s = "Listing the accounts";
我已经用 do~while(true) 创建了我的菜单;但是每次用户输入一个数字时,它不会运行程序,而是再次显示菜单!你怎么看? //我的主要方法 public static void main(St
执行命令后,如何让IPython通知我?我可以使用铃声/警报还是通过弹出窗口获取它?我正在OS X 10.8.5的iTerm上运行Anaconda。 最佳答案 使用最新版本的iTerm,您可以在she
您好,我刚刚使用菜单栏为 Swing 编写了代码。但是问题出现在运行中。我输入: javac Menu.java java Menu 它没有给出任何错误,但 GUI 没有显示。这是我的源代码以供引用:
我觉得这里缺少明显的东西,但是我看不到它写在任何地方。 我使用Authenticode证书对可执行文件进行签名,但是当我开始学习有关它的更多信息时,我对原样的值(value)提出了质疑。 签名的exe
我正在设计一个应用程序,它使用 DataTables 中的预定义库来创建数据表。我想对数据表执行删除操作,为此应在按钮单击事件上执行 java 脚本。 $(document).ready(functi
我是 Haskell 新手,如果有人愿意帮助我,我会很高兴!我试图让这个程序与 do while 循环一起工作。 第二个 getLine 命令的结果被放入变量 goGlenn 中,如果 goGlenn
我有一个用 swing 实现迷你游戏的程序,在主类中我有一个循环,用于监听游戏 map 中的 boolean 值。使用 while 实现的循环不会执行一条指令,如果它是唯一的一条指令,我不知道为什么。
我正在尝试开发一个连接到 Oracle 数据库并执行函数的 Java 应用程序。如果我在 Eclipse 中运行该应用程序,它可以工作,但是当我尝试在 Windows 命令提示符中运行 .jar 时,
我正在阅读有关 Java 中的 Future 和 javascript 中的 Promises 的内容。下面是我作为示例编写的代码。我的问题是分配给 future 的任务什么时候开始执行? 当如下行创
我有一个常见的情况,您有两个变量(xSpeed 和 ySpeed),当它们低于 minSpeed 时,我想将它们独立设置为零,并在它们都为零时退出。 最有效的方法是什么?目前我有两种方法(方法2更干净
我是一名优秀的程序员,十分优秀!