diff --git a/14.ChainOfResponsibility/2.Code/CMakeLists.txt b/14.ChainOfResponsibility/2.Code/CMakeLists.txt new file mode 100644 index 0000000..90b1024 --- /dev/null +++ b/14.ChainOfResponsibility/2.Code/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.15) +project(BuilderPattern) +set(SRC_LIST main.cpp) + +get_filename_component(FOLDER_NAME ${CMAKE_CURRENT_SOURCE_DIR} DIRECTORY) +get_filename_component(FOLDER_NAME ${FOLDER_NAME} NAME) +set(EXECUTABLE_OUTPUT_PATH ${OUTPUT_DIR}/${FOLDER_NAME}) +add_executable(app14 ${SRC_LIST}) \ No newline at end of file diff --git a/15.CommandPattern/2.Code/CMakeLists.txt b/15.CommandPattern/2.Code/CMakeLists.txt index e6420d5..234b410 100644 --- a/15.CommandPattern/2.Code/CMakeLists.txt +++ b/15.CommandPattern/2.Code/CMakeLists.txt @@ -1,10 +1,8 @@ -cmake_minimum_required(VERSION 3.17) -project(Command) +cmake_minimum_required(VERSION 3.15) +project(BuilderPattern) +set(SRC_LIST main.cpp) -message(STATUS "start building......") - -set(OUT_DIR ../) -set(EXECUTABLE_OUTPUT_PATH ${OUT_DIR}/bin) - -file(GLOB SRC_LIST ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) -add_executable(app ${SRC_LIST}) +get_filename_component(FOLDER_NAME ${CMAKE_CURRENT_SOURCE_DIR} DIRECTORY) +get_filename_component(FOLDER_NAME ${FOLDER_NAME} NAME) +set(EXECUTABLE_OUTPUT_PATH ${OUTPUT_DIR}/${FOLDER_NAME}) +add_executable(app15 ${SRC_LIST}) \ No newline at end of file diff --git a/16.InterpreterPattern/2.Code/CMakeLists.txt b/16.InterpreterPattern/2.Code/CMakeLists.txt new file mode 100644 index 0000000..5d9154f --- /dev/null +++ b/16.InterpreterPattern/2.Code/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.15) +project(BuilderPattern) +set(SRC_LIST main.cpp) + +get_filename_component(FOLDER_NAME ${CMAKE_CURRENT_SOURCE_DIR} DIRECTORY) +get_filename_component(FOLDER_NAME ${FOLDER_NAME} NAME) +set(EXECUTABLE_OUTPUT_PATH ${OUTPUT_DIR}/${FOLDER_NAME}) +add_executable(app16 ${SRC_LIST}) \ No newline at end of file diff --git a/18.MediatorPattern/2.Code/CMakeLists.txt b/18.MediatorPattern/2.Code/CMakeLists.txt new file mode 100644 index 0000000..3f0faef --- /dev/null +++ b/18.MediatorPattern/2.Code/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.15) +project(BuilderPattern) + +file(GLOB SRC_LIST ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) + +get_filename_component(FOLDER_NAME ${CMAKE_CURRENT_SOURCE_DIR} DIRECTORY) +get_filename_component(FOLDER_NAME ${FOLDER_NAME} NAME) +set(EXECUTABLE_OUTPUT_PATH ${OUTPUT_DIR}/${FOLDER_NAME}) +add_executable(app18 ${SRC_LIST}) \ No newline at end of file diff --git a/18.MediatorPattern/2.Code/Colleague.h b/18.MediatorPattern/2.Code/Colleague.h index c706cf3..e8a88d9 100644 --- a/18.MediatorPattern/2.Code/Colleague.h +++ b/18.MediatorPattern/2.Code/Colleague.h @@ -2,6 +2,7 @@ #define __COLLEAGUE_H__ #include "common.h" +#include using namespace std; // 前向声明 diff --git a/19.MementoPattern/2.Code/CMakeLists.txt b/19.MementoPattern/2.Code/CMakeLists.txt new file mode 100644 index 0000000..ba08c8a --- /dev/null +++ b/19.MementoPattern/2.Code/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.15) +project(BuilderPattern) +file(GLOB SRC_LIST ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) + +get_filename_component(FOLDER_NAME ${CMAKE_CURRENT_SOURCE_DIR} DIRECTORY) +get_filename_component(FOLDER_NAME ${FOLDER_NAME} NAME) +set(EXECUTABLE_OUTPUT_PATH ${OUTPUT_DIR}/${FOLDER_NAME}) +add_executable(app19 ${SRC_LIST}) \ No newline at end of file diff --git a/20.ObserverPattern/2.Code/AllyCenter.cpp b/20.ObserverPattern/2.Code/AllyCenter.cpp index 8083c5c..1bdce73 100644 --- a/20.ObserverPattern/2.Code/AllyCenter.cpp +++ b/20.ObserverPattern/2.Code/AllyCenter.cpp @@ -35,14 +35,14 @@ AllyCenterController::AllyCenterController(){ void AllyCenterController::notify(INFO_TYPE infoType, std::string name){ switch (infoType){ case RESOURCE: - for each (Observer* obs in playerList){ + for (Observer* obs : playerList){ if (obs->getName() != name){ ((Player*)obs)->come(); } } break; case HELP: - for each (Observer* obs in playerList){ + for (Observer* obs : playerList){ if (obs->getName() != name){ ((Player*)obs)->help(); } diff --git a/20.ObserverPattern/2.Code/AllyCenter.h b/20.ObserverPattern/2.Code/AllyCenter.h index 2e96720..136c39d 100644 --- a/20.ObserverPattern/2.Code/AllyCenter.h +++ b/20.ObserverPattern/2.Code/AllyCenter.h @@ -3,6 +3,7 @@ #include "common.h" #include +#include // 前向声明 class Observer; diff --git a/20.ObserverPattern/2.Code/CMakeLists.txt b/20.ObserverPattern/2.Code/CMakeLists.txt new file mode 100644 index 0000000..8d0231e --- /dev/null +++ b/20.ObserverPattern/2.Code/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.15) +project(BuilderPattern) +file(GLOB SRC_LIST ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) + +get_filename_component(FOLDER_NAME ${CMAKE_CURRENT_SOURCE_DIR} DIRECTORY) +get_filename_component(FOLDER_NAME ${FOLDER_NAME} NAME) +set(EXECUTABLE_OUTPUT_PATH ${OUTPUT_DIR}/${FOLDER_NAME}) +add_executable(app20 ${SRC_LIST}) \ No newline at end of file diff --git a/21.StatePattern/2.Code/CMakeLists.txt b/21.StatePattern/2.Code/CMakeLists.txt new file mode 100644 index 0000000..3d5ca45 --- /dev/null +++ b/21.StatePattern/2.Code/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.15) +project(BuilderPattern) +file(GLOB SRC_LIST ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) + +get_filename_component(FOLDER_NAME ${CMAKE_CURRENT_SOURCE_DIR} DIRECTORY) +get_filename_component(FOLDER_NAME ${FOLDER_NAME} NAME) +set(EXECUTABLE_OUTPUT_PATH ${OUTPUT_DIR}/${FOLDER_NAME}) +add_executable(app21 ${SRC_LIST}) \ No newline at end of file diff --git a/21.StatePattern/2.Code/GameAccount.cpp b/21.StatePattern/2.Code/GameAccount.cpp index a5edd94..1e95460 100644 --- a/21.StatePattern/2.Code/GameAccount.cpp +++ b/21.StatePattern/2.Code/GameAccount.cpp @@ -1,6 +1,6 @@ #include "GameAccount.h" #include "Level.h" -#include +// #include #include #define random(x) (rand()%x) @@ -40,7 +40,7 @@ string GameAccount::getName(){ void GameAccount::playCard(){ this->level->playCard(); - Sleep(100); + // Sleep(100); srand((int)time(0)); int res = random(2); if (res % 2 == 0){ diff --git a/22.StrategyPattern/2.Code/CMakeLists.txt b/22.StrategyPattern/2.Code/CMakeLists.txt new file mode 100644 index 0000000..d9e9598 --- /dev/null +++ b/22.StrategyPattern/2.Code/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.15) +project(BuilderPattern) +file(GLOB SRC_LIST ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) + +get_filename_component(FOLDER_NAME ${CMAKE_CURRENT_SOURCE_DIR} DIRECTORY) +get_filename_component(FOLDER_NAME ${FOLDER_NAME} NAME) +set(EXECUTABLE_OUTPUT_PATH ${OUTPUT_DIR}/${FOLDER_NAME}) +add_executable(app22 ${SRC_LIST}) \ No newline at end of file diff --git a/23.TemplateMethodPattern/2.Code/CMakeLists.txt b/23.TemplateMethodPattern/2.Code/CMakeLists.txt new file mode 100644 index 0000000..5ff56e9 --- /dev/null +++ b/23.TemplateMethodPattern/2.Code/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.15) +project(BuilderPattern) +file(GLOB SRC_LIST ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) + +get_filename_component(FOLDER_NAME ${CMAKE_CURRENT_SOURCE_DIR} DIRECTORY) +get_filename_component(FOLDER_NAME ${FOLDER_NAME} NAME) +set(EXECUTABLE_OUTPUT_PATH ${OUTPUT_DIR}/${FOLDER_NAME}) +add_executable(app23 ${SRC_LIST}) \ No newline at end of file diff --git a/24.VisitorPattern/2.Code/CMakeLists.txt b/24.VisitorPattern/2.Code/CMakeLists.txt new file mode 100644 index 0000000..c6a0492 --- /dev/null +++ b/24.VisitorPattern/2.Code/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.15) +project(BuilderPattern) +file(GLOB SRC_LIST ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) + +get_filename_component(FOLDER_NAME ${CMAKE_CURRENT_SOURCE_DIR} DIRECTORY) +get_filename_component(FOLDER_NAME ${FOLDER_NAME} NAME) +set(EXECUTABLE_OUTPUT_PATH ${OUTPUT_DIR}/${FOLDER_NAME}) +add_executable(app24 ${SRC_LIST}) \ No newline at end of file diff --git a/24.VisitorPattern/2.Code/main.cpp b/24.VisitorPattern/2.Code/main.cpp index bc17e14..208d099 100644 --- a/24.VisitorPattern/2.Code/main.cpp +++ b/24.VisitorPattern/2.Code/main.cpp @@ -1,7 +1,7 @@ #include "Element.h" #include "Visitor.h" #include "ShoppingCart.h" -#include +// #include int main() { diff --git a/CMakeLists.txt b/CMakeLists.txt index 1599011..ebd9f46 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,4 +17,14 @@ add_subdirectory(10.DecoratorPattern/2.Code/) add_subdirectory(11.FacadePattern/2.Code/) add_subdirectory(12.FlyweightPattern/2.Code/) add_subdirectory(13.ProxyPattern/2.Code/) +add_subdirectory(14.ChainOfResponsibility/2.Code/) +add_subdirectory(15.CommandPattern/2.Code/) +add_subdirectory(16.InterpreterPattern/2.Code/) add_subdirectory(17.IteratorPattern/2.Code/) +add_subdirectory(18.MediatorPattern/2.Code/) +add_subdirectory(19.MementoPattern/2.Code/) +add_subdirectory(20.ObserverPattern/2.Code/) +add_subdirectory(21.StatePattern/2.Code/) +add_subdirectory(22.StrategyPattern/2.Code/) +add_subdirectory(23.TemplateMethodPattern/2.Code/) +add_subdirectory(24.VisitorPattern/2.Code/)