From 4d132d3e020bfa9209693013a3c2df45ff00d65c Mon Sep 17 00:00:00 2001 From: onon1101 Date: Mon, 29 Apr 2024 08:14:02 +0800 Subject: [PATCH] change the function name that upperline and bottomline in throw.h --- include/Player/Config.h | 8 +++++ include/Player/Equipment/IEquip.h | 19 ++++++++++++ include/Player/Equipment/Throw.h | 4 +-- include/Player/Items/Tool.h | 48 ++++++++++++++++++++++++++++++ include/Player/Items/ToolFactory.h | 41 +++++++++++++++++++++++++ include/Settings/Hash.h | 40 +++++++++++++++++++++++++ src/Player/Equipment/Throw.cpp | 8 ++--- 7 files changed, 162 insertions(+), 6 deletions(-) create mode 100644 include/Player/Config.h create mode 100644 include/Player/Equipment/IEquip.h create mode 100644 include/Player/Items/Tool.h create mode 100644 include/Player/Items/ToolFactory.h create mode 100644 include/Settings/Hash.h diff --git a/include/Player/Config.h b/include/Player/Config.h new file mode 100644 index 00000000..1e110fb0 --- /dev/null +++ b/include/Player/Config.h @@ -0,0 +1,8 @@ +// +// Created by adven on 2024/4/28. +// + +#ifndef FUCK_PTSD_CONFIG_H +#define FUCK_PTSD_CONFIG_H + +#endif // FUCK_PTSD_CONFIG_H diff --git a/include/Player/Equipment/IEquip.h b/include/Player/Equipment/IEquip.h new file mode 100644 index 00000000..16c35ffb --- /dev/null +++ b/include/Player/Equipment/IEquip.h @@ -0,0 +1,19 @@ +// +// Created by adven on 2024/4/28. +// + +#ifndef FUCK_PTSD_IEQUIP_HPP +#define FUCK_PTSD_IEQUIP_HPP + +#include + +class IEquip : public GameElement { +public: + enum Pos { COL = 0, ROW }; + + virtual std::string GetName() const = 0; + + virtual std::string GetType() const = 0; +}; + +#endif // FUCK_PTSD_IEQUIP_HPP diff --git a/include/Player/Equipment/Throw.h b/include/Player/Equipment/Throw.h index d73d7a09..a24f790a 100644 --- a/include/Player/Equipment/Throw.h +++ b/include/Player/Equipment/Throw.h @@ -52,8 +52,8 @@ class Throw final : public IEquipment { private: void GenWin(); void GenItem(); - void GeneralUpperText(); - void GeneralLowerText(); + void GenFirstLine(); + void GenSecondLine(); }; #endif // FUCK_PTSD_THROW_H diff --git a/include/Player/Items/Tool.h b/include/Player/Items/Tool.h new file mode 100644 index 00000000..85f243ba --- /dev/null +++ b/include/Player/Items/Tool.h @@ -0,0 +1,48 @@ +// +// Created by adven on 2024/4/28. +// + +#ifndef FUCK_PTSD_TOOLSYSTEM_HPP +#define FUCK_PTSD_TOOLSYSTEM_HPP + +#include +#include "Player/Equipment/IEquip.h" +#include "ToolFactory.h" +class Tool final { +public: + explicit Tool() { + m_ToolFactory = std::make_shared(); + m_GameElement = std::make_shared(); + m_GameElement->SetVisible(false); + + for (const auto& elem : m_BaseTool) { + const auto& obj = m_ToolFactory->MakeTool(elem.first, elem.second); + + m_ToolList.push_back(obj); + m_GameElement->AddChild(obj); + } + }; + + void AddTool(const std::shared_ptr& ge) { + m_ToolList.push_back(ge); + m_GameElement->AddChild(ge); + }; + + std::shared_ptr GetGameObject() { + return static_cast>(m_GameElement); + } + +private: + const std::map m_BaseTool = { + {"BOMB", "1"}, + {"SHOVEL", "Shovel"}, + {"WEAPON", "Dagger"}}; + + std::vector> m_ToolList; + + std::shared_ptr m_ToolFactory; + + std::shared_ptr m_GameElement; +}; + +#endif // FUCK_PTSD_TOOLSYSTEM_HPP diff --git a/include/Player/Items/ToolFactory.h b/include/Player/Items/ToolFactory.h new file mode 100644 index 00000000..e27a2d6f --- /dev/null +++ b/include/Player/Items/ToolFactory.h @@ -0,0 +1,41 @@ +// +// Created by adven on 2024/4/28. +// + +#ifndef FUCK_PTSD_TOOLFACTORY_H +#define FUCK_PTSD_TOOLFACTORY_H + +#include "Player/Equipment/IEquip.h" +#include "Settings/Hash.h" + +using namespace Settings::Hash; + +namespace Players::Items { +class ToolFactory { +public: + explicit ToolFactory() = default; + + std::shared_ptr MakeTool( + const std::string& name, + const std::string& type + ) { + switch (Settings::Hash::HashConvert(name)) { + case "BOMB"_hash: GenBomb(); break; + case "SHOVEL"_hash: GenShovel(); break; + case "WEAPON"_hash: GenWeapon(); break; + default: throw std::runtime_error("Tool type is not available"); break; + } + + return m_Result; + }; + +private: + void GenBomb(); + void GenShovel(); + void GenWeapon(); + + std::shared_ptr m_Result; +}; +} // namespace Players::Items + +#endif // FUCK_PTSD_TOOLFACTORY_H diff --git a/include/Settings/Hash.h b/include/Settings/Hash.h new file mode 100644 index 00000000..cddf8488 --- /dev/null +++ b/include/Settings/Hash.h @@ -0,0 +1,40 @@ +// +// Created by adven on 2024/4/29. +// + +#ifndef FUCK_PTSD_HASH_H +#define FUCK_PTSD_HASH_H + +#include + +namespace Settings { +namespace Hash { +typedef std::size_t ht; + +constexpr ht prime = 0x100000001B3ull; +constexpr ht basis = 0xCBF29CE484222325ull; + +static ht HashConvert(const std::string& str) { + ht ret = basis; + + for (std::size_t i = 0; i < str.size(); ++i) { + ret ^= static_cast(str[i]); + ret *= prime; + } + + return ret; +} + +constexpr ht hash_compile_time(const char* str, ht last_value = basis) { + return *str ? hash_compile_time(str + 1, (*str ^ last_value) * prime) + : last_value; +} + +static constexpr unsigned long long operator"" _hash(const char* str, size_t) { + return hash_compile_time(str); +} + +} // namespace Hash +} // namespace Settings + +#endif // FUCK_PTSD_HASH_H diff --git a/src/Player/Equipment/Throw.cpp b/src/Player/Equipment/Throw.cpp index 430ddea0..c876ddfa 100644 --- a/src/Player/Equipment/Throw.cpp +++ b/src/Player/Equipment/Throw.cpp @@ -14,8 +14,8 @@ Throw::Throw() { GenWin(); GenItem(); - GeneralLowerText(); - GeneralUpperText(); + GenSecondLine(); + GenFirstLine(); m_Throw->SetVisible(false); }; @@ -51,7 +51,7 @@ void Throw::GenItem() { m_Throw->AddChild(m_Item); } -void Throw::GeneralUpperText() { +void Throw::GenFirstLine() { const auto UpperTextObject = std::make_shared( m_TextStylePath, m_FontSize, @@ -67,7 +67,7 @@ void Throw::GeneralUpperText() { m_Throw->AddChild(m_UpperText); } -void Throw::GeneralLowerText() { +void Throw::GenSecondLine() { const auto LowerTextObject = std::make_shared( m_TextStylePath, m_FontSize,