Object-oriented and Warcraft

xiaoxiao2021-03-05  21

Introduction:

Object-oriented: a common idea of ​​modern software development.

Warcraft: a very artistic instant strategy game.

Description:

This article is only an object-oriented object, which does not mean that Warcraft is designed.

I would like to dedicate this to my program design and Warcraft.

text:

Object-oriented fundamental thinking is "all things all things". What is the object? Objects are entities that describe objective things, which encapsulate their properties and operations in their own interior and only provide interfaces. Each entity in Warcraft can also be seen as an object. Whether it is a demon hunter, death knight and other heroes, or female hunting, wolf ride, etc. Everything in World of Warcraft is object, just like people in the hacker empire will be regarded as 01.

Objects come from class instantiation, each object contains its own properties and operations. Each object in Warcraft has its own properties and operations, such as DK, has its own properties: agility, intellectual value, health, magic value; operation: four magic: death, death contract, evil ring, manipulation Dead corpse, etc.

Such as:

Class Obj {

Objattribute1 x;

Objatribute2 y;

...... ..

Public void obj () {

... ..

}

Public void objoprate11 () {

... ..

}

Public void objoprate2 () {

... ..

}

}

Class newobj {

Public void newobjoperate () {

Obj obj1 = new obj ();

Obj obj2 = new obj ();

}

}

Where OBJ is a class, contains attributes X, Y, Objoperate11, Objoperate2. Newobj is an instantiated class specifically, which instant two objects OBJ1, OBJ2. Each object in Warcraft can also be seen as a class of art.

Such as:

// Death Knight

Class deadking {

DEADKING DKINSTANCE = NULL;

Image [] dkimg; // contains a set of pictures of DK, used to display time map

INT LifeValue; // Health

INT MAGICVALUE; // Magic Value

INT degree; // rating

Teasurebasket [6] tbasket; // treasure basket, through the object aggregated to record the treasures brought by DK.

Boolean isinvulnerable; // is invincible

......... / Other related properties such as attack power, armor, agility, intelligence, etc.

// Create a DK instance using a single piece

Public static synchronized deadking getInstance () {

IF (instance == null)

DKINSTANCE = New deadKing ();

Return DKINSTANCE;

}

// Initialization of related properties;

Private deadking () {

LifeValue =

MagicValue =

ISINVULNERABLE = FALSE;

........

}

// Warcraft map, perhaps use animation

Public Image Putimage () {

Image IMG;

/ / The correct map is selected;

Switch (INDEX) {

Case North: IMG = DKIMG [0];

Case South: IMG = DKIMG [1]; Break; Case East: IMG = DKIMG [2]; Break;

.........

Case Dead: IMG = DKIMG [N]; Break;

.........

DEFAULT:

IMG = NULL; BREAK;

}

Return IMG;

}

// Use bean to set up and get LifeValue, MagicValue's operation Similar

Public void setLifeValue (int lifevalue) {

THIS.LIFEVALUE = LiftValue;

}

Public int getLifeValue () {

Return LifeValue;

}

// Use this method when eating life agents, as for life agents or strong life agents, perform // judge the corresponding ADDVALUE in the event response of life agents and then modulate;

Public Void AddLifeValue (int addValue) {

LifeValue = addValue;

}

// is attacked to reduce life value

Public void subtractlifevalue (int Subvalue) {

LifeValue - = SubValue;

}

// ....... Magic operation and the value of health

// Some related properties are operated, such as the speed of speed boots in the treasure basket, and the gel of the gel.

//magic

// Death entanglement

Public void deathcoil () {

MagicValue - = 75;

..................

}

// Death Contact

Public void deathpact () {

MagicValue - = 50;

..................

}

// evil ring

Public void unholyaura () {

..................

}

// manipulate dead body

Public void animatedead () {

MagicValue - = 175;

........

}

}

// Invincible medicine water

Class INVULNERABILITY {

Image IMG;

Int delayTime;

...... ..

Public infulnerability () {

........

}

//duration

Public int getDelaytime () {

Return delayTime;

}

............ .....

}

Note: The method of setting a conctruct method to private in the DK class has added a GetInstance because DK belongs to heroes, only one instance (if you can produce a team of NB), this is used in Singleton mode to fulfill. In fact, the above example is the simple version, in fact, with design patterns, more powerful, such as using Factory mode, Proxy mode, Builder mode, etc.

The characteristics of object-oriented thinking:

Encapsulation

From the above two examples, it can be clearly seen that in object-oriented design, the object is stored closely and only the interface is provided, usually the attribute value is set to private, to read the attribute to read and Modifications To achieve the GET and SET implementations of the method, but only the interface method to which the object to be disclosed is set to the user. So the object is a good black box, we can only access it through the interface.

The object-oriented new point is that the object is a responsible entity (<< Design Mode Extrusion >> One book in the book). Each object is responsible for yourself, so the details inside the object do not need to be exposed to the external object, which is packaged. For example, when we selected the devil hunter, right-click on a location on the map, then the object of the Devil Hunter after obtaining the map's coordinates, you know how to get to the destination, and no longer need the participation of the program. That is, the user gives what to implement, the specific implementation details are implemented inside the object, and the user does not have to know. The package makes the object more responsibility for its own behavior. The less responsibility is negative, the procedure is more clear, the less side effects are generated. The package also enables the inside of the object to be transparent to the outside, and the outside world can only access objects through an interface.

Inheritance

Abstract categories are a class definition method and public belonging to a set of concepts, which can be instantiated.

Detective classes are specialized in a super-class class. It contains all the properties and methods, but it can also contain additional properties and different ways implementation.

Inheritance refers to derived class (subclasses) inherits abstract classes (base classes, parent classes), which is a kind of special way for contact derived class and abstract classes.

For example, the goods in Warcraft can generally be divided into three categories:

Permanent type: speed boots, noble head rings, flame tarpisting, smart headscarf, balls of each family, etc.

Consumption: Life Pharmacy, Magic Pharmaceutical, Round Roll, Rebirth Ten Cross, etc.

Supplementary: Treatment: Crystal ball, phantom (Hurricane), etc.

Therefore, you can set a base class for a type of product, using a permanent product as an example.

Abstract Class PermanentTreasure {// Permanent Treasure

............

Public abstract void function ();

...............

}

Class SpeedBoots Extends PermanentTreasure {// Speed ​​Boots

Public void function () {

............

}

}

Class NoBilityCirclet Extends Permanenttreasure {// noble head ring

Public void function () {

........

}

}

An example is to give a "peasant" in the family of four people (the dark night is called Xiaojing, the beast is called hard work, and the family is called farmers, and the non-mission is called a servant) as an example.

Elf character:

Property: Health, Attack, Armor, Mobile Speed, etc.

Method: Collection, construction, repair, self-explosion, etc.

Hard work characteristics:

Property: Health, Attack, Armor, Mobile Speed, etc.

Methods: Collection, construction, repair, plundering, etc.

Farmers' characteristics:

Property: Health, Attack, Armor, Mobile Speed, etc.

Method: Collection, construction, repair, emergency mobilization (change militia), etc.

Horses characteristics:

Property: Health, Attack, Armor, Mobile Speed, etc.

Method: Collection, construction, repair, recycling, sacrifice, etc.

From above, we can see that the properties and methods of the four-family farmers are similar, so you can set a base class and then set each family farmer as a subclass.

Abstract Class Farmer {

INT LifeValue;

Int beatValue;

Int armorvalue;

int SpeedValue;

.......

Public foumer () {

......

}

Public Abstract void Gather ();

Public abstract void build ();

Public Abstract void repair ();

........

}

Class nefarmer extends farmer {...

Public nefarmer () {

// Set related properties

}

Public void gather () {

...... ..

}

Public void build () {

.........

}

Public void repair () {

........

}

// self-explosion

Public void detonate () {

.........

}

........

}

The writing of the class of other three families is similar to those of the NE. It is only some ways to be different (the features of each family), such as the plunder of the beast, the people's militia, the arrogant sacrifice of the people.

Polymorphism

Polymorphism refers to the relevant objects to implement the ability to achieve methods according to their own type, which is very close to inheritance. Polymorphisms can be divided into compile time polymorphism and running polymorphism. Compiling time polymorphism means that it can be determined during the compilation phase, and the runtime can be determined to wait until the operation phase can be determined. As an example, from the above example, we can see that the four-family farmers have some common methods.

such as:

Farmer finstance = new farmer ();

NEFARMER NEFINSTANCE = New nefarmer ();

HMfarmer hmfinstance = new hmfarmer ();

Orcfarmer orcfinstance = new orcfarmer ();

Udfarmer udfinstance = new udfarmer ();

FINSTANCE = Nefinstance;

FINSTANCE.GATHER (); // Adopt Ne's acquisition method

FINSTANCE = HMFINSTANCE;

FINSTANCE.BUILD (); // Using HM construction

FINSTANCE = Orcfinstance;

FINSTANCE.REPAIR (); // Adopt ORC repair method

FINSTANCE = UDFINSTANCE;

FINSTANCE.GATHER (); // Using UD acquisition method

The above is running a polymorphism, which is the method of performing the corresponding type by determining the type of object to the time of runtime.

to sum up:

Object-oriented thinking is a profound, you have to be proficient. Here is just some of the object-oriented basic concepts and features combined with the Warcraft hegemony, it is also necessary to continue to study.

转载请注明原文地址:https://www.9cbs.com/read-32435.html

New Post(0)