StarCraft php observer mode-PHP development

Source: Internet
Author: User
When we open a map in the space to fight with several computers, several players on the computer are equivalent to an alliance. Once we attack a computer, other computers will be rescued. So how can we let Computers know that their allies have been attacked? And automatically respond? The problem to be solved: Once a computer is attacked by us, other computers will be known and automatically dispatched for rescue. When we open a map in the space to fight with several computers, several players on the computer are equivalent to an alliance. Once we attack a computer, other computers will be rescued.


So how can we let Computers know that their allies have been attacked? And automatically respond?


The problem to be solved: Once a computer is attacked by us, other computers will be known and automatically dispatched for rescue.


Idea: Set up some additional observation systems for the computer to notify other computers.



Observer (Observer) mode example:

 OberserverCollection [] = new oberserver ($ oberserverName);} // notify the various observers of public function Policy ($ beAttackedPlayerName) of the name of the attacked computer) {// loop the set of observer foreach ($ this-> oberserverCollection as $ oberserver) {// call the rescue function of each observer. The parameter is the name of the attacked computer, if is used to exclude the observer of the attacked computer if ($ oberserver-> name! = $ BeAttackedPlayerName) $ oberserver-> help ($ beAttackedPlayerName);} abstract public function beAttacked ($ beAttackedPlayer );} // The specific Ally class Ally extends abstractAlly {// constructor, which uses the array of names of all computer players as the parameter public function

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.