- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试创建一个 Java 冒险游戏,您可以在其中向北、向南、向东、向西移动。但是,您无法根据每个房间的方向 boolean 值是否为 true
来移动这些方向。或false
(即,如果该房间的北为 true
,则您可以向北移动)。我的问题是我不确定如何跟踪玩家当前所在的房间/移动到新房间。跟踪玩家当前所在房间并移动到新房间的理想方法是什么?
代码:
import java.util.Hashtable;
import java.util.Scanner;
public class Adventure {
// Create each room
Room1 Room1 = new Room1();
Room2 Room2 = new Room2();
Room3 Room3 = new Room3();
Room4 Room4 = new Room4();
Room5 Room5 = new Room5();
Room6 Room6 = new Room6();
Room7 Room7 = new Room7();
Room8 Room8 = new Room8();
Room9 Room9 = new Room9();
Room10 Room10 = new Room10();
boolean allIngredients = false;
public void RoomSetup() {
// Create HashTable and add rooms to the HashTable
Hashtable<Integer, Room> RoomSet = new Hashtable<Integer, Room>();
RoomSet.put(1, Room1);
RoomSet.put(2, Room2);
RoomSet.put(3, Room3);
RoomSet.put(4, Room4);
RoomSet.put(5, Room5);
RoomSet.put(6, Room6);
RoomSet.put(7, Room7);
RoomSet.put(8, Room8);
RoomSet.put(9, Room9);
RoomSet.put(10, Room10);
// Set Room 1 Properties
Room1.setIntro(
"You are in a dark cave. In the middle, there is a cauldron boiling. With a clasp of thunder, three witches suddenly appear before you.");
Room1.setFirstVisit(
"The witches speak in unison: \"Mortal, we have summoned thee, make haste! And go forth into the farrow\'d waste.Find eye of newt, and toe of frog,And deliver thus to this Scottish bog. Lizard\'s leg, and owlet\'s wing, And hair of cat that used to sing. These things we need t\' brew our charm; Bring them forth -and suffer no \'arm. Leave us and go! \'Tis no more to be said,Save if you fail, then thou be stricken, dead.\"");
Room1.setPreAction("The witches stand before you, glaring; they seem to be expecting something from you.");
Room1.setPostAction(
"The witches look at your items with suspicion, but decide to go through with the incantation of the spell: \"Take lizard\'s leg and owlet\'s wing, And hair of cat that used to sing. In the cauldron they all shall go; Stirring briskly, to and fro. When the color is of a hog, Add eye of newt and toe of frog. Bubble all i\' the charmed pot; Bubble all \'til good and hot. Pour the broth into a cup of stone, And stir it well with a mummy's bone.\" You take the resulting broth offered to you and drink... As the fog clears, you find yourself at a computer terminal; your adventure is at an end.");
// Set Room 2 Properties
Room2.setFirstVisit(
"You're transported back in time ... you find yourself in Georgia during the midst of a congressional campaign.");
Room2.setPreAction(
"There is a campaign poster of Newt Gingrich, the Speaker of the House of Representatives, on the wall, with his large eyes looking right at you.");
Room2.setPostAction("There is a defaced poster of Newt Gingrich on the wall.");
// Set Room 3 Properties
Room3.setFirstVisit(
"You open the door and step in. It looks exactly like your own bedroom from back at home for some reason...");
// Set Room 4 Properties
Room4.setFirstVisit("You get transported to a Nickleback concert. Better get out quick!");
// Set Room 5 Properties
Room5.setFirstVisit(
"You get teleported onto the death star. You can hear darth vader breathing heavily somewhere...");
// Set Room 6 Properties
Room6.setFirstVisit("You find yourself in a frozen tundra. you must be in Antartica or something...");
// Set Room 7 Properties
Room7.setFirstVisit(
"You find yourself walking into a scene where the cast of Monty Python's Flying Circus is performing the \"Crunchy Frog\" sketch. You see the confectioner as he replies, \"If we took the bones out it wouldn't be crunchy now, would it?");
Room7.setPreAction(
"You see a box of \"Crunchy Frog\" chocolates, the contents of which contains a dozen nicely cleaned whole frogs that have been carefully hand-dipped in the finest chocolate.");
Room7.setPostAction(
"There's an onpen box of \"Crunchy Frog\" Chocolates with one of the frogs missing its leg");
// Set Room 8 Properties
Room8.setFirstVisit("You open the door into a room that's pure white. The door you came through dissapears.");
// Set Room 9 Properties
Room9.setFirstVisit(
"As you step through the time portal, your head begins to spin you're disoriented and then awaken. You find yourself at the outside door of a dormitory kitchen. Listening, you hear the Chef yelling, \"Stop! Stop!\" while several cats inside are singing a serenade of the \"Meow Mix\" commercial theme. Suddenly, the repeated thump of a cleaver puts an abrupt end to the music.");
// Set Room 10 Properties
Room10.setFirstVisit(
"You are in the kitchen. Looking out into the cafeteria, you see students reaching for Pepto-Bismol while trying to stomach the latest version of the Chef's Surprise. You see the Chef as he finishes dumping fresh meat into his 50-quart stewing pot.");
Room10.setPreAction(
"There are clumps of cat hair on the butcher's block. You hear the Chef muttering to himself, \"Prepared properly, cat tastes much like chicken...\"");
Room10.setPostAction("There's strands of cat hair all over the floor, and the kitchen smells foul!");
}
public void Play() {
Scanner sc = new Scanner(System.in);
System.out.println(Room1.getIntro());
while(allIngredients == false){
System.out.println("What would you like to do?");
String Question = sc.nextLine();
if(Question.equalsIgnoreCase("quit")){
System.exit(0);
}
if(Question.toLowerCase().contains("move")||Question.toLowerCase().contains("go")){
Question = (Question.replaceAll(" ",""));
move(Question);
}
}
}
private void move(String question) {
if()
}
}
编辑:那么,要链接房间,这是链接它们的好方法吗?如果用户输入北、南、东或西,则方向实际上与该方向的房间相关联。以下是其中一个房间执行此操作的示例:
public class Room6 {
Room4 north;
Room8 south;
Room1 west;
Room9 east;
}
最佳答案
创建一个玩家对象,其中包含对玩家所在房间的引用。
public class Player {
Room currentLocation;
...
}
正如其他人指出的那样,房间必须以某种方式相互连接。同样,您可以添加对“Room”对象的引用,例如 room_north、room_south,...
你的问题确实很难更准确地回答,因为你的代码示例距离正常运行的游戏太远了。希望我的尝试对您有所帮助。
关于java - 在 Java 冒险游戏中跟踪房间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34167911/
有没有办法在 xdebug 跟踪输出中查看 echo 或 print 函数调用。我正在为我在我的服务器中运行的所有脚本寻找一个全局配置(或一种方法)。 例子: 我希望跟踪输出显示 echo 调用。默
我将应用程序从2.0.0M2升级到了2.1.0,但是当我尝试运行该应用程序时,出现此错误: Note: /Volumes/Info/proyectos-grails/vincoorbis/Member
我如何在共享点中执行日志记录。我想使用跟踪。 以便它记录 12 个配置单元日志。 最佳答案 微软提供了一个例子: http://msdn.microsoft.com/en-us/library/aa9
如何跟踪 eclipse 和 android 模拟器的输出。我习惯于在 Flash 和 actionscript 中这样做。 在 AS3 中它将是: trace('我的跟踪语句'); 最佳答案 您有几
是否可以在 Postgresql 上进行查询跟踪?我在带有 OLEDB 界面的 Windows 上使用 9.0。 此外,我需要它是实时的,而不是像默认情况下那样缓冲... 最佳答案 我假设您的意思是在
第一天 HaxeFlixel 编码器。愚蠢的错误,但谷歌没有帮助我。 如何使用 Haxe、NME 和 Flixel 追踪到 FlashDevelop 输出。它在使用 C++ 执行时有效,但对 Flas
我有一个关于 iPhone 上跟踪触摸的快速问题,我似乎无法就此得出结论,因此非常感谢任何建议/想法: 我希望能够跟踪和识别 iPhone 上的触摸,即。基本上每次触摸都有一个起始位置和当前/移动位置
我正在做我的大学项目,我只想跟踪错误及其信息。错误信息应该与用户源设备信息一起存储在数据库中(为了检测源设备,我正在使用MobileDetect扩展名)。我只想知道应该在哪里编写代码,以便获得所有错误
我正在 Azure 中使用多个资源,流程如下所示: 从 sftp 获取文件 使用 http 调用的数据丰富文件 将消息放入队列 处理消息 调用一些外部电话 传递数据 我们如何跟踪上述过程中特定“运行”
在我的 WCF 服务中,当尝试传输大数据时,我不断收到错误:底层连接已关闭:连接意外关闭 我想知道引发此错误的具体原因,因此我设置了 WCF 跟踪并可以读取 traces.svclog 文件。 问题是
我的目标是在 Firebase Analytics 中获取应用数据,在 Google Universal Analytics 中获取其他自定义数据和应用数据。 我的问题是我是否在我的应用上安装 Fir
我正在 Azure 中使用多个资源,流程如下所示: 从 sftp 获取文件 使用 http 调用的数据丰富文件 将消息放入队列 处理消息 调用一些外部电话 传递数据 我们如何跟踪上述过程中特定“运行”
我们正在考虑跟踪用户通过 Tridion 管理的网站的旅程的要求,然后能够根据此行为将此用户识别为“潜在客户”,然后如果他们在之后没有返回,则触发向此用户发送电子邮件X 天。 SmartTarget
在 Common Lisp 中,函数(跟踪名称)可用于查看有关函数调用的输出。 如果我的函数是用局部作用域声明的,我如何描述它以进行跟踪? 例如,如何跟踪栏,如下: (defun foo (x)
有什么方法可以检测文本框的值是否已更改,是用户明确更改还是某些 java 脚本代码修改了文本框?我需要检测这种变化。 最佳答案 要跟踪用户更改,您可以添加按键处理程序: $(selector).key
int Enable ( int pid) { int status; #if 1 { printf ( "child pid = %d \n", pid ); long ret =
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 9 年前。 Improve this ques
我有以下测试代码: #include int main(void) { fprintf(stderr, "This is a test.\n"); int ret = open("s
我有一个闭源 Java 应用程序,供应商已为其提供了用于自定义的 API。由于我没有其他文档,我完全依赖 API 的 javadoc。 我想跟踪特定用例在不同类中实际调用的方法。有什么办法可以用 ec
我正在学习 PHP。我在我的一个 php 函数中使用了如下所示的 for 循环。 $numbers = $data["data"]; for ($i = 0;$i send($numbers[
我是一名优秀的程序员,十分优秀!