所以我无法找到对这种情况的直接反应。作为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>
答案 0 :(得分:2)
您应为每个可用类制作单独的AS3文件。基本上就是全部,但你也可以考虑重新构建你的类树 - 比如说,可装备的物品可能只有一个属性“槽”,它具有这个物品可以装备的含义,比如说EQUIP_LEG
或{{1作为常量(整数)。或者你可以把装备分成武器,盔甲,魔法物品(珠宝,护身符,浮动装置等)。武器有更多的共同点,而不仅仅是装备,装甲(当然,它们在插槽中有所不同,也许武器也可能会被束缚在腿上?由你决定),珠宝IMO更接近装甲,但可以成为一个单独的类。