public static function main(array $args = array())
 {
     $remoteControl = new RemoteControl();
     $livingRoomLight = new Light("Living Room");
     $kitchenLight = new Light("Kitchen");
     $ceilingFan = new CeilingFan("Living Room");
     $garageDoor = new GarageDoor("");
     $stereo = new Stereo("Living Room");
     $livingRoomLightOn = new LightOnCommand($livingRoomLight);
     $livingRoomLightOff = new LightOffCommand($livingRoomLight);
     $kitchenLightOn = new LightOnCommand($kitchenLight);
     $kitchenLightOff = new LightOffCommand($kitchenLight);
     $ceilingFanOn = new CeilingFanOnCommand($ceilingFan);
     $ceilingFanOff = new CeilingFanOffCommand($ceilingFan);
     $garageDoorUp = new GarageDoorUpCommand($garageDoor);
     $garageDoorDown = new GarageDoorDownCommand($garageDoor);
     $stereoOnWithCD = new StereoOnWithCDCommand($stereo);
     $stereoOff = new StereoOffCommand($stereo);
     $remoteControl->setCommand(0, $livingRoomLightOn, $livingRoomLightOff);
     $remoteControl->setCommand(1, $kitchenLightOn, $kitchenLightOff);
     $remoteControl->setCommand(2, $ceilingFanOn, $ceilingFanOff);
     $remoteControl->setCommand(3, $stereoOnWithCD, $stereoOff);
     println($remoteControl);
     $remoteControl->onButtonWasPushed(0);
     $remoteControl->offButtonWasPushed(0);
     $remoteControl->onButtonWasPushed(1);
     $remoteControl->offButtonWasPushed(1);
     $remoteControl->onButtonWasPushed(2);
     $remoteControl->offButtonWasPushed(2);
     $remoteControl->onButtonWasPushed(3);
     $remoteControl->offButtonWasPushed(3);
 }
 public static function main(array $args = array())
 {
     $remoteControl = new RemoteControl();
     $light = new Light("Living Room");
     $tv = new TV("Living Room");
     $stereo = new Stereo("Living Room");
     $hottub = new Hottub();
     $lightOn = new LightOnCommand($light);
     $stereoOn = new StereoOnCommand($stereo);
     $tvOn = new TVOnCommand($tv);
     $hottubOn = new HottubOnCommand($hottub);
     $lightOff = new LightOffCommand($light);
     $stereoOff = new StereoOffCommand($stereo);
     $tvOff = new TVOffCommand($tv);
     $hottubOff = new HottubOffCommand($hottub);
     $partyOn = array($lightOn, $stereoOn, $tvOn, $hottubOn);
     $partyOff = array($lightOff, $stereoOff, $tvOff, $hottubOff);
     $partyOnMacro = new MacroCommand($partyOn);
     $partyOffMacro = new MacroCommand($partyOff);
     $remoteControl->setCommand(0, $partyOnMacro, $partyOffMacro);
     println($remoteControl);
     println("--- Pushing Macro On---");
     $remoteControl->onButtonWasPushed(0);
     println("--- Pushing Macro Off---");
     $remoteControl->offButtonWasPushed(0);
 }
Esempio n. 3
0
//--------------------------------------------------------
//Создаём пульт управления
$remoteControl = new RemoteControl();
echo "<b>Start remote control.</b><hr>";
//Создаём команды для освещения
$light = new Light();
$lightOn = new LightOnCommand($light);
$lightOff = new LightOffCommand($light);
//Создаём команды для двери
$door = new GarageDoor();
$doorOpen = new OpenDoorCommand($door);
$doorClose = new CloseDoorCommand($door);
//Создаём команды для телевизора
$tv = new TV();
$tvOn = new TVOnCommand($tv);
$tvOff = new TVOffCommand($tv);
//Назначаем команды
$remoteControl->setCommand(0, $doorOpen, $doorClose);
$remoteControl->setCommand(1, $lightOn, $lightOff);
$remoteControl->setCommand(2, $tvOn, $tvOff);
echo "<b>Remote control initialized.</b><hr>";
//----- тестируем пульт
echo "<b>Test remote control.</b><hr>";
echo "<i>All device online:<br></i>";
$remoteControl->onButtonWasPressed(0);
$remoteControl->onButtonWasPressed(1);
$remoteControl->onButtonWasPressed(2);
echo "<i>All device offline:<br></i>";
$remoteControl->offButtonWasPressed(0);
$remoteControl->offButtonWasPressed(1);
$remoteControl->offButtonWasPressed(2);
Esempio n. 4
0
require_once "CeilingFanLowCommand.php";
require_once "CeilingFanMediumCommand.php";
require_once "CeilingFanHighCommand.php";
require_once "RemoteControl.php";
//--------------------------------------------------------
//Создаём пульт управления
$remoteControl = new RemoteControl();
echo "<b>Start remote control.</b><hr>";
//Создаём команды для вентилятора
$fan = new CeilingFan("GuestRoom");
$fanHigh = new CeilingFanHighCommand($fan);
$fanOff = new CeilingFanOffCommand($fan);
//Создаём команды для освещения
$light = new Light();
$lightOn = new LightOnCommand($light);
$lightOff = new LightOffCommand($light);
//Создаём команды для телевизора
$tv = new TV();
$tvOn = new TVOnCommand($tv);
$tvOff = new TVOffCommand($tv);
//Создаём Макрокоманду - начать вечеринку
$startParty = new MacroCommand(array($fanHigh, $lightOff, $tvOn));
//Создаём Макрокоманду - закончить вечеринку
$closeParty = new MacroCommand(array($fanOff, $lightOn, $tvOff));
//------назначаем пульт
$remoteControl->setCommand(0, $startParty, $closeParty);
//----- тестируем пульт
echo "<b>Start party.</b><hr>";
$remoteControl->onButtonWasPressed(0);
echo "<b>Close party.</b><hr>";
$remoteControl->offButtonWasPressed(0);
Esempio n. 5
0
    {
        println('set volume=' . $volume);
    }
}
println();
$control1 = new RemoteControl();
#电灯
$light1 = new Light1();
$light_on_command = new LightOnCommand1($light1);
$light_off_command = new LightOffCommand1($light1);
#音响
$steteo = new Stereo();
$steteo_on_command = new StereoOnCommand($steteo);
$stereo_off_command = new StereoOffCommand($steteo);
#设置插槽控制xx
$control1->setCommand(0, $light_on_command, $light_off_command);
$control1->setCommand(1, $steteo_on_command, $stereo_off_command);
echo $control1;
$control1->bottonOnWasPressed(0);
$control1->bottonOffWasPressed(0);
echo $control1;
println('undo botton was pressed');
$control1->bottonUndoWasPressed();
#开音响
$control1->bottonOnWasPressed(1);
echo $control1;
println('undo botton was pressed');
#把音响关了
$control1->bottonUndoWasPressed();
println(SEPARATE, 'END', SEPARATE);
/**
Esempio n. 6
0
<?php

include_once __DIR__ . "/remoteControl.php";
include_once __DIR__ . "/devices/light.php";
include_once __DIR__ . "/commands/lightOnCommand.php";
include_once __DIR__ . "/commands/lightOffCommand.php";
$device = new RemoteControl();
$light = new Light("Bathroom");
$lightOnCommand = new lightOnCommand($light);
$lightOffCommand = new lightOffCommand($light);
$device->setCommand(1, $lightOnCommand, $lightOffCommand);
$light = new Light("Kitchen");
$lightOnCommand = new lightOnCommand($light);
$lightOffCommand = new lightOffCommand($light);
$device->setCommand(2, $lightOnCommand, $lightOffCommand);
$device->onButtonWasPushed(1);
$device->onButtonWasPushed(2);
$device->undoButtonWasPushed();
$device->undoButtonWasPushed();
Esempio n. 7
0
    require_once implode(DIRECTORY_SEPARATOR, $parts) . '.php';
}
//Simple Remote
$remote = new SimpleRemoteControl();
$light = new Machine\Light("Corridor Light");
$lightOn = new Command\LightOnCommand($light);
$remote->setCommand($lightOn);
$remote->buttonWasPressed();
//Remote Control
$re = new RemoteControl();
$livingRoom = new Machine\Light('Living Room');
$kitchenLight = new Machine\Light('Kitchen');
$ceilingFan = new Machine\CeilingFan('Living Room');
$garageDoor = new Machine\GarageDoor('Main');
$stereo = new Machine\Stereo('My Room');
$re->setCommand(0, new Command\LightOnCommand($livingRoom), new Command\LightOffCommand($livingRoom));
$re->setCommand(1, new Command\LightOnCommand($kitchenLight), new Command\LightOffCommand($kitchenLight));
$re->setCommand(2, new Command\CeilingFanHighCommand($ceilingFan), new Command\CeilingFanOffCommand($ceilingFan));
$re->setCommand(3, new Command\GarageDoorOnCommand($garageDoor), new Command\GarageDoorOffCommand($garageDoor));
$re->setCommand(4, new Command\StereoOnWithCDCommand($stereo), new Command\StereoOffCommand($stereo));
echo $re;
$re->onButtonWasPushed(0);
$re->offButtonWasPushed(0);
$re->onButtonWasPushed(1);
$re->undoButtonWasPushed();
$re->offButtonWasPushed(1);
$re->onButtonWasPushed(2);
$re->undoButtonWasPushed();
$re->offButtonWasPushed(2);
$re->onButtonWasPushed(3);
$re->undoButtonWasPushed();
Esempio n. 8
0
require_once "LightOffCommand.php";
require_once "CeilingFanOffCommand.php";
require_once "CeilingFanLowCommand.php";
require_once "CeilingFanMediumCommand.php";
require_once "CeilingFanHighCommand.php";
require_once "RemoteControl.php";
//--------------------------------------------------------
//Создаём пульт управления
$remoteControl = new RemoteControl();
echo "<b>Start remote control.</b><hr>";
//Создаём команды для вентилятора
$fan = new CeilingFan("GuestRoom");
$fanLow = new CeilingFanLowCommand($fan);
$fanMedium = new CeilingFanMediumCommand($fan);
$fanHigh = new CeilingFanHighCommand($fan);
$fanOff = new CeilingFanOffCommand($fan);
//Назначаем команды
$remoteControl->setCommand(0, $fanLow, $fanOff);
$remoteControl->setCommand(1, $fanMedium, $fanOff);
$remoteControl->setCommand(2, $fanHigh, $fanOff);
echo "<b>Remote control initialized.</b><hr>";
//----- тестируем пульт
echo "<b>Test remote control.</b><hr>";
echo "<i>All device online:<br></i>";
$remoteControl->onButtonWasPressed(0);
$remoteControl->onButtonWasPressed(1);
$remoteControl->undoButtonWasPressed();
$remoteControl->onButtonWasPressed(2);
$remoteControl->undoButtonWasPressed();
echo "fan status:<br>";
$fan->status();
Esempio n. 9
0
<?php

include_once '../../class/pattern/command.php';
$remoteControl = new RemoteControl();
$car = new Car();
$carPowerOn = new PowerOnCommand($car);
$carPowerOff = new PowerOffCommand($car);
$carTurnLeft = new TurnLeftCommand($car);
$carTurnRight = new TurnRightCommand($car);
$remoteControl->setCommand(0, $carPowerOn);
// 將按鈕0號設為發動汽車引擎
$remoteControl->setCommand(1, $carPowerOff);
// 將按鈕1號設為關閉汽車引擎
$remoteControl->setCommand(2, $carTurnLeft);
// 將按鈕2號設為汽車左轉
$remoteControl->setCommand(3, $carTurnRight);
// 將按鈕3號設為汽車右轉
/*
$remoteControl->execute(0);     // 按下按鈕0號
$remoteControl->execute(1);     // 按下按鈕1號
$remoteControl->execute(2);     // 按下按鈕2號
$remoteControl->execute(3);     // 按下按鈕3號
*/
// 設定蛇行巨集, 開啟引擎、左轉、右轉、關閉引擎
$macroCmd = new MarcoCommand(array($carPowerOn, $carTurnLeft, $carTurnRight, $carPowerOff));
// 將按鈕4號設為蛇行指令
$remoteControl->setCommand(4, $macroCmd);
// 執行按鈕4號
$remoteControl->execute(4);
/*
$boat = new Boat();