remote.cpp
来自「一个类似遥控器的源码程序。可以有多种功能」· C++ 代码 · 共 55 行
CPP
55 行
#include "Remote.hpp"
using namespace HeadFirstDesignPatterns::Command::Remote;
int main(int argc, char* argv[]) {
RemoteControl* remoteControl = new RemoteControl();
Light* livingRoomLight = new Light("Living Room"); Light* kitchenLight = new Light("Kitchen"); CeilingFan* ceilingFan= new CeilingFan("Living Room"); GarageDoor* garageDoor = new GarageDoor(""); Stereo* stereo = new Stereo("Living Room"); LightOnCommand* livingRoomLightOn = new LightOnCommand(livingRoomLight); LightOffCommand* livingRoomLightOff = new LightOffCommand(livingRoomLight); LightOnCommand* kitchenLightOn = new LightOnCommand(kitchenLight); LightOffCommand* kitchenLightOff = new LightOffCommand(kitchenLight); CeilingFanOnCommand* ceilingFanOn = new CeilingFanOnCommand(ceilingFan); CeilingFanOffCommand* ceilingFanOff = new CeilingFanOffCommand(ceilingFan); GarageDoorUpCommand* garageDoorUp = new GarageDoorUpCommand(garageDoor); GarageDoorDownCommand* garageDoorDown = new GarageDoorDownCommand(garageDoor); StereoOnWithCDCommand* stereoOnWithCD = new StereoOnWithCDCommand(stereo); StereoOffCommand* stereoOff = new StereoOffCommand(stereo); remoteControl->setCommand(0, livingRoomLightOn, livingRoomLightOff); remoteControl->setCommand(1, kitchenLightOn, kitchenLightOff); remoteControl->setCommand(2, ceilingFanOn, ceilingFanOff); remoteControl->setCommand(3, stereoOnWithCD, stereoOff); std::cout << remoteControl->toString() << std::endl; remoteControl->onButtonWasPushed(0); remoteControl->offButtonWasPushed(0); remoteControl->onButtonWasPushed(1); remoteControl->offButtonWasPushed(1); remoteControl->onButtonWasPushed(2); remoteControl->offButtonWasPushed(2); remoteControl->onButtonWasPushed(3); remoteControl->offButtonWasPushed(3);
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?