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/4248195.html
==============================================================================
The battles in the stars are on the map, and as long as we can edit the map, we can create some new battles. However, if the map drawing related code in Interstellar is open, it is estimated that most of them will not understand, let alone edit the map.
problem to solve: without understanding the map code structure, we want to let the player edit the map themselves.
idea: for players, he is familiar with the Crystal mine, the heights of these shapes, he and the system through the mouse interaction. We can design a map editor for the player to use without having to study the detail code of the map.
(In fact Blizzard is doing this, many players and even blizzard insiders are using the Star Map Editor to make maps)
Example of positive mode (facade):
<?PHP//The player's mouse object that records the state of the mouse in which it was edited classMouse {//the x-axis coordinates where the mouse is located Public Static $X; //objects currently being drawn by the mouse, such as crystal mines, rivers, etc. Public Static $object; //the y-axis coordinates of the mouse Public Static $Y; } //Map Editor classMapedit {//Drawing Method Public Static functionDraw () {//draw various things on the map based on the state of the mouse object//If it is a crystal mine if(Mouse::$object= = "Ore") { //call the drawing method of the crystal ore class, this class is defined below, which is really drawn, but the player does not have to learn his detailsOre::Draw (); } //if it's a river ElseIf(Mouse::$object= = "River") { //call the draw method of the River class, this class is defined below, which is really drawn, but the player does not have to learn his detailsRiver::Draw (); } } } //Crystal Ore class classOre {//the remaining mines, as well as other properties, have been skipped here Public $remain; //Draw Crystal Mine Public Static functionDraw () {//actual drawing of the bottom detail code of the Crystal Mine } } //River Class classRiver {//Draw a River Public Static functionDraw () {//actual drawing of the underlying detail code of the river } } //The player clicks on the crystal Ore object on the drawing object list on the map editor .Mouse::$object= "Ore"; //player moves MouseMouse::$X= 311; Mouse::$Y= 126; //Click on the map to indicate the drawing of the current object, i.e. a crystal mineMapedit::Draw ();?>
Usage Summary: The positive mode allows the user to focus on the work he wants to do without having to know all the details, or providing an easy-to-use tool that shields the underlying details from the user's re-learning.
Implementation Summary: need a similar to the above map editor code class, to help the player easy to operate.
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
13. StarCraft PHP design mode-positive mode