InstancePlayer class, InstanceNpc, InstanceBox these three classes represent the player, NPCS, and furniture, boxes,
And then items have InstanceWeapon, InstanceDrug, weapon class, potions classes, weapon class can not stack, potions classes can be stacked, all classes can be loaded containers as objects implementing an interface Imoveable,
Now want to achieve is goods can into the Container, in order to implement code reuse, and defines the Container class exists in Instanceplayer respectively, InstanceNpc, InstanceBox class, ideally the Container handling Imoveable all the load and took out, such as the Container. The Add (Imoveable) Remove (Imoveable),
But the real question is can stack and can not stack items have no way to do good logic clear design in the Container,
So could you please tell me how to design the container system under the current demand is better? For example the Container class is unnecessary, so how to design better? To solve the
CodePudding user response:
Well, actually, this still depends on demand, more complex backpack system involves many aspects, such as the UI, such as inventory systems, such as the use effect of the item, I do this thing before, generally say to you:Item management:
The Item class, the base class for all items. Derived classes have Weapon_Item Drup_Item etc., in fact, I am not using class inheritance, but use an Enum to distinguish goods category, the Enum design is as follows:
Public enum ItemType: uint
{
Weapon x00000001=0,
Drup x00000002=0,
Task x00000004=0,
//...
}
The advantage is, one item is possible this class, and that species, that can be easily used Mask (Mask) to distinguish the phase operation,
Items, main record of item's ID and class attributes, attributes include: level, such as rare, rare, such as effect, such as to add 10, 20 shooting, improve the defense, and so on, of the 10 o 'clock,
UI:
WindowsManager, window management, mainly used for processing the focus problem when multiple Windows overlap, such as pop-up dialog box, you can have two modal and non-modal, once the modal window pop up, will disable the focus of the other Windows, and a new popup window is in the top, window management class is essentially a stack, but is not entirely, because of the need to deal with the modal,
Windows, the base class for all Windows, mainly used for calculating the size of the window, the boundary information, such as
Drapable class, component, the component needs to be the ancestors of object or object must have a window components, if a component has a window object or child added this component, then the window can be dragged, mainly for the window's title bar, then drag the title bar of the window can drag the entire window, and will test the boundary of the window,
Icon class, the base class for all ICONS, derived has two: ItemIcon and AbitilyIcon, namely items, ICONS and skill Icon ItemIcon class, is mainly used to record the item's Icon in the address and number of items, such as a bundle of drugs, the number 99 can be displayed on the a Icon, only takes up a slot, but weapons are not allowed to stack, in addition, the Icon class articles or skills using the cooling process after processing, can be a fan of the mask,,
Solt, all the Icon of the slot, a container, allowing the child to have an Icon component object Icon, you can set the allowed to place the types of ICONS, done by Mask, for example, the character of the state of the gear slot, allowing only prevent equipment, are not allowed to put drugs, are not allowed to place skills, but the shortcut key slot, allow placement and skills, but are not allowed to place equipment,,,,
Special effects:
Buff class, mainly recorded using items after effects, divided into the timing, permanent type, etc., such as a bottle of medicine, drink growth life immediately after 100 points, the other a medicine drink growth for 10 seconds after the maximum 100 points, life, and belong to different types, Buff the object of the class mainly operating role of information,
BuffIcon class, this is mainly used for display in the task bar, used to represent the current state of the role, for example, is at a state of intoxication, etc,,,
Role information:
CharInfo class: the role of information, primary record character attributes, such as: maximum life, current life values, the remaining mana, attack, defense,,,,,,,
CodePudding user response: