Skip to content

Commit

Permalink
change the function name that upperline and bottomline in throw.h
Browse files Browse the repository at this point in the history
  • Loading branch information
onon1101 committed Apr 29, 2024
1 parent 16387b6 commit 4d132d3
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 6 deletions.
8 changes: 8 additions & 0 deletions include/Player/Config.h
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions include/Player/Equipment/IEquip.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// Created by adven on 2024/4/28.
//

#ifndef FUCK_PTSD_IEQUIP_HPP
#define FUCK_PTSD_IEQUIP_HPP

#include <GameElement.h>

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
4 changes: 2 additions & 2 deletions include/Player/Equipment/Throw.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
48 changes: 48 additions & 0 deletions include/Player/Items/Tool.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// Created by adven on 2024/4/28.
//

#ifndef FUCK_PTSD_TOOLSYSTEM_HPP
#define FUCK_PTSD_TOOLSYSTEM_HPP

#include <map>
#include "Player/Equipment/IEquip.h"
#include "ToolFactory.h"
class Tool final {
public:
explicit Tool() {
m_ToolFactory = std::make_shared<Players::Items::ToolFactory>();
m_GameElement = std::make_shared<GameElement>();
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<IEquip>& ge) {
m_ToolList.push_back(ge);
m_GameElement->AddChild(ge);
};

std::shared_ptr<Util::GameObject> GetGameObject() {
return static_cast<std::shared_ptr<Util::GameObject>>(m_GameElement);
}

private:
const std::map<std::string, std::string> m_BaseTool = {
{"BOMB", "1"},
{"SHOVEL", "Shovel"},
{"WEAPON", "Dagger"}};

std::vector<std::shared_ptr<IEquip>> m_ToolList;

std::shared_ptr<Players::Items::ToolFactory> m_ToolFactory;

std::shared_ptr<GameElement> m_GameElement;
};

#endif // FUCK_PTSD_TOOLSYSTEM_HPP
41 changes: 41 additions & 0 deletions include/Player/Items/ToolFactory.h
Original file line number Diff line number Diff line change
@@ -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<IEquip> 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<IEquip> m_Result;
};
} // namespace Players::Items

#endif // FUCK_PTSD_TOOLFACTORY_H
40 changes: 40 additions & 0 deletions include/Settings/Hash.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// Created by adven on 2024/4/29.
//

#ifndef FUCK_PTSD_HASH_H
#define FUCK_PTSD_HASH_H

#include <iostream>

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<std::size_t>(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
8 changes: 4 additions & 4 deletions src/Player/Equipment/Throw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ Throw::Throw() {

GenWin();
GenItem();
GeneralLowerText();
GeneralUpperText();
GenSecondLine();
GenFirstLine();

m_Throw->SetVisible(false);
};
Expand Down Expand Up @@ -51,7 +51,7 @@ void Throw::GenItem() {
m_Throw->AddChild(m_Item);
}

void Throw::GeneralUpperText() {
void Throw::GenFirstLine() {
const auto UpperTextObject = std::make_shared<Util::Text>(
m_TextStylePath,
m_FontSize,
Expand All @@ -67,7 +67,7 @@ void Throw::GeneralUpperText() {
m_Throw->AddChild(m_UpperText);
}

void Throw::GeneralLowerText() {
void Throw::GenSecondLine() {
const auto LowerTextObject = std::make_shared<Util::Text>(
m_TextStylePath,
m_FontSize,
Expand Down

0 comments on commit 4d132d3

Please sign in to comment.