8. StarCraft PHP design mode--Enjoy meta mode

Source: Internet
Author: User

Preface
==============================================================================
This PHP design mode album from the blog (jymoz.com), now has no access, this series of articles I have been looking for a long time to find the complete, thanks to the author Jymoz's Hard Pay Oh!

This address:http://www.cnblogs.com/davidhhuan/p/4248186.html
==============================================================================


Star battle reached the back, the map of the troops are many, if we take each soldier's image animation and property values as an object, the system memory will be very expensive.
We'll find out when we play, because there are only three races in the galaxy, but there are only dozens of of them.
Although the remaining blood of each individual soldier is different, the same class image animation is the same, even if different players, just different colors. Like everyone's machine-gun soldiers.
And most players only use some of the most commonly used classes, and many times they don't make all the classes.

problem to be solved: share the image animation of the class.

idea: We put the image animation model of each class as an object and put it into memory sharing. Once you have a screen with this class, just take the shared image animation and change the color.

Example of the Flyweight mode:

<?PHP//The machine gun to enjoy the yuan    classMarineflyweight {//Draw the image animation of the machine gun, parameters of the state, such as which player belongs to         Public functionDrawmarine ($state)        {            //draw a machine gun soldier        }    }    //enjoy the Yuan factory    classFlyweightfactory {//an array of elements for storing multiple privileges        Private $flyweights; //ways to get the benefits         Public functionGetflyweight ($name)        {            if(!isset($flyweights[$name]))            {                $flyweights[$name] =New $name." Flyweight "; }            return $flyweights[$name]; }    }    //initialize the enjoy meta factory    $flyweightFactory=Newflyweightfactory (); //when we need to draw a machine gun, we also pass a state array containing the remaining blood and so on .    $marine=$flyweightFactory->getflyweight ("Marine"); $marine->drawmarine ($status);?>

Summary of usage: enjoy meta-mode to centralize resources that need to be shared, manage them uniformly, and prevent duplication of consumption.

Implementation Summary: a shared resource is required to manage shares, such as the flyweightfactory above. The production of all shared resources is given to a factory.

Related articles:

1. StarCraft PHP Object-oriented (i)

2. StarCraft PHP Object-oriented (ii)

3. StarCraft PHP design mode-Simple Factory mode

4. StarCraft PHP Design mode-factory method mode

5. StarCraft PHP design mode-Abstract Factory mode

6. StarCraft PHP design mode-builder mode

7. The PHP design mode of StarCraft--The mediator mode

8. StarCraft PHP design mode--Enjoy meta mode

9. StarCraft PHP Design mode--proxy mode

10. StarCraft PHP design mode-prototype mode

11. The PHP design mode of StarCraft--Memo mode

12. StarCraft PHP design mode-template mode

13. StarCraft PHP design mode-positive mode

14. StarCraft PHP design mode-state mode

15. StarCraft PHP design mode--strategy mode

16. StarCraft PHP Design mode--combination mode

17. StarCraft PHP Design mode--responsibility chain mode

18. StarCraft PHP design mode-Observer mode

19. The PHP design mode of StarCraft--iterator mode

? 20. StarCraft PHP design mode-Adapter mode

8. StarCraft PHP design mode--Enjoy meta mode

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.