# 游戏:宝石宝石 **Repository Path**: itmwuma/MyDiamond ## Basic Information - **Project Name**: 游戏:宝石宝石 - **Description**: 一个简单的2D PUZ游戏的Demo。 重点在游戏框架的构建,借鉴了虚幻引擎的Gameplay框架。 - **Primary Language**: C++ - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2023-05-15 - **Last Updated**: 2023-05-16 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # MyDiamond A simple demo of 2D PUZ game. However, constructing by a self-designed gameplay framework, which taking a page from ***Unreal Engine's Gameplay Framework***. ## Game Features - Move character in the map - Grab and throw diamonds to eliminate same diamonds - Diamonds will be generated each turn - DO NOT LET DIAMONDS MEET DEADLINE!!! ## Build Project - **From source code** Use Visual Studio to build the project - **Get release version** ## Project Structure ![UML](https://gitee.com/itmwuma/MyDiamond/raw/main/Images/Project_%20MD.jpg) ### MDGameInstance A instance of the game. Generate **GameMode**. Create a game iteration. ```cpp class MDGameInstance { public: MDGameInstance(); // ... private: void CreateGameMode(); // ... }; ``` Game iteration ```cpp class MDGameInstance { // ... protected: virtual void OnEndPlay(); virtual void OnEnterNextTurn() const; virtual void OnGameOver(); virtual void OnGameStart(); virtual void OnBeginPlay(); virtual void OnUpdata(); virtual void OnSaveGame(); // ... }; ``` A global variable. ```cpp extern unique_ptr GameInstance; ``` ### MDGameMode A Config contains information of **PlayerController, PlayerState, Pawn, GameState**. ```cpp class MDGameMode { // ... private: shared_ptr DefaultPawn; shared_ptr PlayerController; shared_ptr PlayerState; shared_ptr GameState; shared_ptr HUD; }; ``` ### MDScene A singleton class. As actors container. ```cpp class MDScene final { public: typedef vector>> Map; // ... public: static MDScene* Get(); // ... private: static MDScene* SceneInstance; /* Each slot can contain an actor */ Map Slots; /* A list recording all actors which have been registered */ unordered_set> ActorSet; }; ``` ### MDActor Base class of all actors. Containing SceneComponent which means that it has the information of position. Can be stored by **MDScene**. ```cpp class MDActor { // ... public: std::shared_ptr SceneComponent; }; ``` ### MDPlayerController Controller can possess a pawn. Receiving the player's input and deal with it, powered by **InputComponent** ```cpp class MDPlayerController : enable_shared_from_this { public: // ... void Possess(const shared_ptr& PossessedPawn); void UnPossess(); void OnPawnMove(EMoveDirection Direction) const; shared_ptr InputComponent; // ... private: shared_ptr PlayerState; shared_ptr PossessedPawn; }; ``` ### MDPawn An actor that can be possessed by **controller**. Acting according to controller's command. ```cpp class MDPawn : public MDActor, public enable_shared_from_this { public: void Move(EMoveDirection Direction); // ... }; ``` ### MDPlayerState Information of Pawn. ### MDGameState Information of the whole game. ### MDUserWidget Construct UI part of the game. Giving some render interfaces. ```cpp class MDUserWidget { public: void Render() const; void RenderQuitUI() const; private: void RenderHeader() const; void RenderGameInfo() const; static void RenderNewLine(); // ... }; ``` ### MDInputComponent Handle player's input and generate **input commands**. ```cpp class MDInputComponent { public: MDInputComponent(const weak_ptr& OwnerCache); shared_ptr HandleInput() const; }; ``` ### IInputCommand Send a message to **controller** to deal with the player's input. ```cpp class IInputCommand { public: virtual ~IInputCommand() = default; virtual void Execute(const shared_ptr& PlayerController) = 0; }; ``` ### MDUserWidget Create UI for the process of game. ```cpp class MDUserWidget { public: // ... virtual void Render() const; // ... }; ``` ### MDSaveGame Contain data to serialize and deserialize. ```cpp struct MDSaveGame { float BestScore; template void serialize(Archive& archive) { archive(BestScore); } }; ``` ## 作者信息 - GitHub: https://github.com/itmWUMA