Im trying to create an adventure game in which the user types North, South, East, and West in order to move to different rooms. So i have a player class that has a Currentroom variable with a room assigned to it as the default room. What i want to do is when a player enters a direction, it updates the Currentroom variable of the player to a different room object. How do i do this so i can navi
我试图创建一个冒险游戏,用户在其中输入North,South,East和West来移动到不同的房间。 所以我有一个玩家类,它有一个Currentroom变量,一个房间分配给它作为默认房间。 我想要做的是当玩家进入方向时,它将玩家的Currentroom变量更新为不同的房间对象。 我如何做到这一点,所以我可以浏览房间? 我将发布Adventure类,以及其中一个房间的示例。 冒险类: import java.util.Hashtable; import java.util.Scanner; pu
I am trying to create a Java adventure game in which you can move north, south, east, and west. However you cannot move these directions depending on whether each room's direction boolean value is true or false (ie if north is true for that room, you can move north). My issue is I am not sure how to go about keeping track of what room the player is currently in/move to a new room. What wou
我正在尝试创建一个Java冒险游戏,您可以在其中移动北部,南部,东部和西部。 但是,您不能移动这些方向,具体取决于每个房间的方向布尔值是true还是false (即,如果该房间的北部为true ,则可以向北移动)。 我的问题是我不知道如何去跟踪玩家目前在哪个房间/搬到新房间。 什么是跟踪球员现在的房间并转移到新房间的理想方式? 码: import java.util.Hashtable; import java.util.Scanner; public class Adventure {
This is my second semester at college and we've learned about linkedLists (Nodes). I had an idea to do something like that for fun in java which is a Room class with 4 pointers to other Room objects: north, south, west, east, and every Room object also contains a char object, so I can keep track of it. My main function asks for w/a/s/d input from scanner and then creates/points to the corr
这是我在大学的第二个学期,我们已经了解linkedLists(节点)。 我有一个想法,就是在java中这样做,这是一个Room类,带有指向其他Room对象的指针:北,南,西,东,每个Room对象也包含一个char对象,所以我可以跟踪它。 我的主要功能是要求扫描仪输入w / a / s / d,然后创建/指向相应的房间,并用char填充每个房间。 但是,由于某种原因,它很快就会耗尽堆空间(比如当字符到达'?'时)。 这是我的代码: impor
I'll try to be as clear as I can about this so that there's no confusion. Also, I'm not looking for a how-to process, just some tips on how to get started and head in the right direction. I'm relatively new to programming in general (programming in Java for barely 5 months) and I'm barely learning a lot of things about programming. I understand a few concepts already, but
我会努力尽可能清楚地说明这一点,以免混淆。 另外,我并不是在寻找一个如何操作的流程,只是一些关于如何开始并朝正确方向前进的提示。 一般来说,我对编程相对来说比较陌生(用Java进行编程仅用了5个月),而我几乎没有学习很多关于编程的知识。 我已经理解了一些概念,但我一直试图理解MVC(模型,视图,控制器)的概念。 我已经做了一些研究,并希望将其应用于基于视觉文本的游戏。 在游戏中,玩家可以通过一系列“房
I have written an android activity to act as a simple camera but when I photo is taken the activity stores the image and stores a txt file along side, which records the gps location and orientation of the phone (ie the accelerometer and digital compass readings). The activity works but I'm unsure it has been written correctly. I'm abit of a novice on android and java so if some one coul
我已经编写了一个android活动来充当简单的相机,但是当我拍摄照片时,活动存储图像并在边上存储txt文件,该文件记录手机的gps位置和方向(即加速度计和数字罗盘读数) 。 该活动有效,但我不确定它是否已正确书写。 我在Android和Java中习惯新手,所以如果有人能检查它并且会很棒。 我很担心,因为当我第一次开发这个产品时,我的开发设备开始变得有趣而且过热。 虽然我不是100%确定的,但这可能与编码错误有关。 也许这样
I'm currently reading the book Head First Design Patterns and in the Decorator chapter there is the following example: In the book the CondimentDecorator class is described as an abstract decorator . Here is the code example: public abstract class CondimentDecorator extends Beverage { public abstract String getDescription(); } So basically inside is only an abstract method which forc
我目前正在阅读“Head First Design Patterns”一书,并在Decorator章节中有以下示例: 在本书中,CondimentDecorator类被描述为abstract decorator 。 这里是代码示例: public abstract class CondimentDecorator extends Beverage { public abstract String getDescription(); } 所以基本上,里面只是一个抽象的方法,它强制所有的子类重写Beverage类中的getDescription()方法。 这里是作为decorator者的Mocha类的代
I'm trying to learn the Decorator Design Pattern. In this example, I create an app that calculates the cost of a coffee based on its type (espresso, decaf, house blend), size (tall, grande, venti), and condiment-decorators (soy, whipped cream, steamed milk) -- some code excluded for brevity. As you can see from the output at the bottom, if I setSize(GRANDE) and don't wrap the object, g
我正在努力学习Decorator设计模式。 在这个例子中,我创建了一个应用程序,根据咖啡的类型(意式浓缩咖啡,咖啡豆,混合咖啡),大小(高,大,通风)和调味品装饰(大豆,奶油,蒸牛奶) - 为简洁起见,排除一些代码。 从底部的输出中可以看到,如果setSize(GRANDE)并不包装对象,getSize()将返回GRANDE。 如果我设置了大小(GRANDE),然后修饰该对象,则getSize()返回TALL(在Beverage类中设置的默认值)。 如果
I'm in the process of learning to use the decorator pattern, and I ran into a problem which I reckon is simple but I can't seem to find the answer to. Let's say I have a Beverage class that's abstract. Then let's say I have a few concrete components extending Beverage: americano, espresso, latte etc. And also an abstract Condiment class extending Beverage. The Condiments cl
我正在学习使用装饰模式,我遇到了一个我认为很简单的问题,但我似乎无法找到答案。 假设我有一个抽象的饮料类。 然后,假设我有几个延伸饮料的具体组件:americano,espresso,latte等。还有一个抽象的调味品类扩展了饮料。 调味品类然后有多个小类:牛奶,糖,大豆,鞭子。 每个调味品子类都有一个分别从Beverage和Condiments继承的cost和getdescription()方法。 我的问题是,在测试时,如何阻止某个具有多种同类型调味
This question already has an answer here: Why do we need the decorator in the decorator design pattern? 4 answers It enables the decoration of the base class independently with various decorators in different combinations without having to derive a class for each possible combination. For example, say you want your Beverage with milk and nutmeg. Using decorators based on the abstract decor
这个问题在这里已经有了答案: 为什么我们需要装饰器设计模式中的装饰器? 4个答案 它使用不同组合的各种装饰器独立装饰基类,而不必为每种可能的组合导出类。 例如,假设你想要牛奶和肉豆蔻的Beverage 。 使用基于抽象装饰器类的装饰器,只需使用Milk和Nutmeg装饰器进行包装。 如果它来源于Beverage ,那么你必须有一个MilkWithNutmegBeverage类,一个MilkBeverage类和一个NutmegBeverage类。 您可以想象随着可能组合
I want create app, which rerouting packets. I use vpnservice (because no need root phone), use toyVpn and this code http://www.thegeekstuff.com/2014/06/Android-vpn-service/ but problem is in this line DatagramChannel tunnel = DatagramChannel.open(); this line throw exception. this is my code public class MyVpnService extends VpnService { public static String CONNECTION = "StartService";
我想创建应用程序,重新路由数据包。 我使用vpnservice(因为不需要root电话),使用toyVpn和这个代码http://www.thegeekstuff.com/2014/06/Android-vpn-service/但问题在这一行DatagramChannel tunnel = DatagramChannel.open() ; 这一行抛出异常。 这是我的代码 public class MyVpnService extends VpnService { public static String CONNECTION = "StartService"; public static String DISCONNECTION = "Stop