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