0

所以我一直无法找到对这种情况的直接回应。作为 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>
4

1 回答 1

2

您应该为每个可用的类制作单独的 AS3 文件。基本上就是这样,但你也可以考虑重组你的类树——比如,可装备的物品可能只有一个属性“槽”,它意味着可以装备这个物品的位置,比如EQUIP_LEGEQUIP_HEAD作为常量(整数)。或者你可以将装备分解成武器、盔甲、魔法专用的东西(珠宝、护身符、浮动装置等)。武器的共同点不仅仅是可装备,还有盔甲(当然,它们的插槽不同,也许武器也可以固定在腿上?由你决定),珠宝 IMO 更接近盔甲,但可以成为单独的班级。

于 2013-09-27T12:07:26.247 回答