所以我有这个代码,我想当用户键入A来激活在此代码下面的while(attack)时,它就不能继续攻击;我在while(attack)上方放置了一个名为Attack:的标签,但它无法识别,因为稍后会对其进行声明。
String M2 = JOptionPane.showInputDialog(Name2 + "'s Turn. Here are your options\n 1.Invade \n 2.Buy \n 3.End Turn \n 4.Check Money Balance \n 5.Check Soldier Count \n 6.Citizen's Hapinness \n 7.Owned Islands \n 8.Check Rules", "Type the Number of the action you want to take place");
if (M2.equals("1")) {
String Inv=JOptionPane.showInputDialog(null, "Open up the map and Check the island that you are in! If you dont remember the islands name type B to go back and then go into Owned Islands and come back! Then see the attack option you have and choose where you want to attack.Type A to Attack");
if(Inv.equalsIgnoreCase("A")){
Attack=false;
Attack=true;
continue attack;
}else{
continue P2Menu2;
}
}
这是播放器键入A时必须开始的代码。谢谢您的时间.. :)
//Attack Phase
attack:
while (Attack) {
Random r = new Random();
int R = r.nextInt(6 - 1) + 1;
int R2 = r.nextInt(6 - 1) + 1;
int R3 = r.nextInt(6 - 1) + 1;
int R4 = r.nextInt(6 - 1) + 1;
int R5 = r.nextInt(6 - 1) + 1;
int R6 = r.nextInt(6 - 1) + 1;
int totalr[] = {R, R2, R3, R4, R5, R6};
标签不能像这样工作。在Java中,没有任何goto label
功能。当您有内部循环且需要break
或continue
有外部循环时,将使用标签,如以下示例所示:
outterloop:
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
// this would break the inner loop and go to the next outter loop iteration
// break;
// this would break the outter loop, thus exiting both loops
// break outterloop;
// this would jump to the next inner loop iteration
// continue;
// this would jump to the next outter loop iteration, exiting the inner loop
// continue outterloop;
}
}
您需要的是在不使用标签的情况下改进代码结构以实现所需的功能。
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/branch.html
问题内容: 我的问题:使用net.Read …方法仅复制给定字节数组或切片大小的字节数。我当然不想每次分配64 kB的最大UDP数据报。 有没有一种确定数据报大小(在数据报标头中)或再次读取直到数据报被完全读取的方法? 问题答案: 尝试ReadFromUDP: ReadFromUDP从c读取UDP数据包,并将有效负载复制到b。它返回复制到b中的字节数以及该数据包上的返回地址。 数据包的大小应该从中
问题内容: 有没有一种方法可以检查切片/映射中是否存在值? 我 只想 在切片中 不 存在值 时才 向切片添加值。 这可行,但似乎很冗长。有更好的方法吗? 问题答案: 您的方法将为每次插入花费线性时间。更好的方法是使用。另外,您也可以使用a 或类似名称,但是empty 的优点是它不占用任何额外空间。因此,是一组整数的普遍选择。 例:
问题内容: 我在src /下的子目录下有多个软件包,使用每个软件包运行测试都可以正常工作。 尝试运行所有测试时,所有测试都在运行,但失败。 这些测试是针对本地数据库服务器运行的,每个测试文件都有带有db指针的全局变量。 我尝试运行测试以防止在数据库中争用,但是测试仍然失败。 这里有什么问题? 编辑:某些测试在缺少数据库条目上失败,我在每次测试之前和之后都彻底清除了数据库。我能想到发生这种情况的唯一
我正试图建立一个二叉树来执行以下操作: > 如果我写Y,它将打印左边的子对象。如果我写N,它将打印正确的子对象。 如果它只是一个叶节点,它将只写下答案。
问题内容: 我正在Go中构建一个JSON API,我想将错误响应作为json返回。 响应示例: 我以为我可以创建一个实现错误接口的包装器结构,然后使用Go的json封送处理程序作为获取错误的json表示形式的一种干净方法: 这只会将JsonErr 封送为,是否可以使用默认的Go json封送处理程序对该结构进行编码,还是需要为JsonErr结构编写快速的自定义MarshalJson? 问题答案:
本文向大家介绍js实现正方形颜色从下往上升的效果,包括了js实现正方形颜色从下往上升的效果的使用技巧和注意事项,需要的朋友参考一下