所以我一直无法找到对这种情况的直接回应。作为 Flash Builder AS3 的练习,我正在制作一个基于文本的冒险游戏。
我有物品,对于物品,我有可装备的物品,在可装备的物品中,我有头、腿、胸部等。
头部可装备物品、腿部可装备物品等都具有相同的特性,因为它们都是可装备物品,尽管将来它们可能会略有不同,所以我希望将它们作为单独的类别。
当我按照我的预期去做(嵌套类)时,我得到了关于不嵌套类的错误,然后是关于在文件中有多个类等的其他错误。
这样做的明智方法是什么?
谢谢你的时间。
这是一些代码...
我破碎的课程代码:
package classes
{
public class Item
{
public var iName:String;
public var iDesc:String;
public var isRemovable:Boolean;
public function Item(iName:String, iDesc:String, isRemovable:Boolean )
{
var name:String = iName;
var desc:String = iDesc;
var removable:Boolean = isRemovable;
}
}
}
class Equippable extends Item{
function Equippable(pName:String, pSpeedMod:Number, pAttackMod:Number, pLocation:String)
{
var name:String = pName;
var speedMod:Number = pSpeedMod;
var attackMod:Number = pAttackMod;
var location:String = pLocation;
}
}
class Head extends Equippable{
}
class Chest extends Equippable{
}
class Legs extends Equippable{
}
class Belt extends Equippable{
}
我的 MXML 文件(它显示了我在这个项目中有多早!):
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
<![CDATA[
import classes.*;
private function createRooms():void {
var NorthRoom:Room = new Room("North Room","This is the North Room.", "None", "None", "Central Room", "None");
var EastRoom:Room = new Room("East Room","This is the East Room.", "None", "None", "None", "Central Room");
var SouthRoom:Room = new Room("South Room","This is the South Room.", "Central Room", "None", "None", "None");
var WestRoom:Room = new Room("West Room","This is the West Room.", "None", "Central Room", "None", "None");
var CentralRoom:Room = new Room("Central Room","This is the Central room.", "North Room", "East Room", "South Room", "West Room");
}
public function createItems():void {
}
private function buttonClick(event:Event):void {
TextArea.text = "Button number " + event.target.id + " has been pressed.";
}
var ThePlayer:Player = new Player()
while(1){
}
]]>
</fx:Script>
<mx:TextArea left="20" height="250" width="600" id="TextArea"/>
<mx:Button width="100" click="buttonClick(event)" y="270" x="520" label="Inventory" id="InvBTN"/>
<mx:Button width="100" click="buttonClick(event)" y="310" x="520" label="Examine Area" id="ExArea"/>
<mx:TextArea left="20" height="20" width="300" y="270" id="CEntry"/>
<mx:Button width="100" click="buttonClick(event)" y="310" x="20" label="OK" id="SEntry"/>
</s:Application>