- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要帮助在我的文字 RPG 游戏中设置检查点。我给用户两种选择,其中之一会导致他们被杀。他们死后,我想让他们回到检查点的起点,但我不知道该怎么办。
我尝试过 while (true) {, continue;, break;,但它只是搞乱了我的代码。我发布的部分非常困惑,但我希望您能看到我正在尝试做的事情。
import java.util.Scanner;
public class Tester {
public static void main (String []args) {
Scanner sc = new Scanner(System.in);
while (true) {
System.out.println("These men are on the other side of the street. They're carrying large laser rifles, and pointing them at civilians.");
try {
Thread.sleep(3000);
} catch (InterruptedException e) {}
System.out.println("You quickly find cover behind a large tree near the Square, and they haven't seen you yet.");
try {
Thread.sleep(3000);
} catch (InterruptedException e) {}
System.out.println("Do you choose to shoot as many as you can, or find a way to save the civilians? (Hint: shoot them or save people)");
String input2 = sc.nextLine();
switch(input2) {
case "shoot them":
System.out.println("You decide to try to shoot as many as you can. You take down 2, but the 5 men remaining have taken cover. They now know exactly where you are now. They toss a grenade your way.");
try {
Thread.sleep(3000);
} catch (InterruptedException e) {}
System.out.println("*BOOM*");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {}
System.out.println("You died by explosion.");
try {
Thread.sleep(2000);
} catch (InterruptedException e) {}
System.out.println("GAME OVER");
continue;
case "save people":
System.out.println("Good decision...");
break;
}
}
}
}
如果用户写“射击他们”,结果是他们死亡,但代码不会返回到检查点。
最佳答案
我知道这不是 CodeReview,只是仅供引用,您可以将 throws InterruptedException
添加到您的主方法签名中,这样您就不必捕获所有这些异常。
实现 RPG 游戏的一种基本方法是使用对象图,也就是说,您有一个类 Option
和 Scenario
并遍历它来玩角色扮演游戏。例如:
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
class Scratch {
public static void main(String[] args) throws InterruptedException {
Scanner scanner = new Scanner(System.in);
Scenario root = new Scenario("Welcome to the forest", 500);
Scenario left = new Scenario("You went left!", 500);
Scenario right = new Scenario("You went right!", 500);
Option step1a = new Option("Go left", left);
Option step1b = new Option("Go right", right);
Option step1c = new Option("Go back to the beginning", root);
root.branches.add(step1a);
root.branches.add(step1b);
root.branches.add(step1c);
Scenario current = root;
while (true) {
System.out.println(current.text);
if (current.branches.size() == 0) break;
Thread.sleep(current.delay);
System.out.println("What would you like to do?");
for (int i = 0; i < current.branches.size(); i++) {
System.out.printf("%s. %s\n", i, current.branches.get(i).text);
}
int choice = Integer.parseInt(scanner.nextLine());
current = current.branches.get(choice).result;
}
System.out.println("Game over!");
}
}
class Scenario {
List<Option> branches = new ArrayList<>();
String text;
int delay;
public Scenario(String text, int delay) {
this.text = text;
this.delay = delay;
}
}
class Option {
Scenario result;
String text;
public Option(String text, Scenario result) {
this.text = text;
this.result = result;
}
}
如果您有任何疑问,请告诉我。
关于java - 如何返回 RPG 游戏中的某个检查点行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58423558/
作为背景,我一直在根据 Ray Wenderlich 的教程开发一款角色扮演游戏。 (示例)http://www.raywenderlich.com/1163/how-to-make-a-tile-b
有谁知道在哪里可以找到 RP 游戏开发的类图示例?类似here的东西会很有用的。我不是在寻找可以盲目复制的东西,而是在寻找不同的示例,这些示例为我在尝试用铅笔记下自己的类时发现的问题绘制了各种解决方案
我的代码有问题,当调用时,它似乎使战斗持续的时间比应有的时间长。 我认为问题出在 if 语句上,所以我一直在研究它们,但我似乎无法把它弄对。 class Enemy: def __init__
我的 RPG 统计代码有点问题。我希望人们使用 6 个基本属性(力量、敏捷、体质、智力、智慧和魅力),最小值为 10。创建角色时,我希望他们有 15 点可以使用,并且在我的代码,一切正常,除非你在到达
我正在尝试制作一个角色扮演游戏战斗系统,您可以在其中与地精作战。不幸的是,我用来制作运气系统的随机发生器并没有像我想要的那样工作。出于某种原因,当我希望它每次都是不同的值时,随机变量在每个循环中总是相
我正在为我的研究开发一款角色扮演游戏,我们需要使用设计模式,并且我正在尝试编写动态角色技能。例如,我会有一些元素,在装备后,会添加角色以前没有的新技能(治疗...)。 为此,我想使用装饰器模式,但是使
我正在用 js 制作一个网络 Angular 色扮演游戏,使用 melon JS 和 SQL DB 以及 PHP。这个问题是关于如何存储每个非玩家 Angular 色 (NPC) 的已完成任务和当前任
鉴于以下树结构,每个登录的玩家都可以拥有当前和已完成级别的数据、每个级别的任务、每个任务的 NPC 以及每个 NPC 的多个任务......我正在尝试找出最好的方法存储每个玩家的当前和完成数据。 我之
所以我一直在学习 C++ 和 SDL 来制作一些基本的 2d 游戏。我想创建一个类似于魔兽世界的游戏,但它是一个 2D 版本。我希望它在线并使用数据库或其他东西来启动数据,如黄金数量、HP 等。不过我
既然我终于弄清楚了类继承在 ruby 中的工作原理,我正在为文本 rpg 设计一个库存系统。但是,有些怪癖我无法弄清楚。 项目类别: class Item attr_accessor :n
我需要帮助在我的文字 RPG 游戏中设置检查点。我给用户两种选择,其中之一会导致他们被杀。他们死后,我想让他们回到检查点的起点,但我不知道该怎么办。 我尝试过 while (true) {, cont
我正在制作一个角色扮演游戏,但是,我现在遇到了一个错误。玩家的角色可以在所有四个主要方向上移动,但如果您向右、向上或向下移动,玩家就会卡住。 此外,错误似乎有一些逻辑: 如果向下移动,角色会卡在向下移
为了练习,我正在使用 Java 创建一个基于文本的 RPG。我目前正在使用 .properties 文件来处理字符信息。我知道 YAML 可能是一个更好的选择,但我不太确定如何实现它。使用属性,创建库
我正在编写 RPG 程序,我希望角色对象创建控制其“能力”的对象 每个字符都有一个字符串变量 powerOne、PowerTwo 等。 powerOne =“攻击” 我需要一种方法来做到这一点: "
我不确定我的代码有什么问题,我正在尝试创建一个 while 循环,该循环将使用在 SQL 中声明的游标获取字段(代码)中的下一个字符。目标是通过循环获取下一个匹配的字符。然后我想在循环结束时返回结果。
我在 RPG 中编写了一个监控程序,用于检查 fax/400 是否正常运行。 现在我希望这个程序每 15 分钟检查一次。 我没有在作业调度程序中每 15 分钟放置一个作业(这很难管理),而是使用 DL
我需要为我的 RPG 程序中的现有物理文件创建一个新成员。我知道有两种方法,但我必须说,我都不喜欢: 使用QCMDEXC调用ADDPFM 编写一个 CL 程序,调用 ADDPFM 并从 RPG 调用它
我只是在玩一个基于文本的 RPG,我想知道,命令解释器究竟是如何实现的,现在有没有更好的方法来实现类似的东西?编写大量 if 语句很容易,但这似乎很麻烦,特别是考虑到大多数情况下 pick up th
我正在尝试创建一个过程,该过程将采用一个数组并返回已使用元素的计数(为什么这不是 BIF??)。我正在努力寻找一种将未知大小的数组传递给我的程序的方法。 类似... P count B
我正在尝试制作一个简单的基于文本的游戏。 while True: choice = raw_input('>>: ') aa = choice.split() if aa[0]
我是一名优秀的程序员,十分优秀!