add collections

This commit is contained in:
2025-03-20 12:31:44 +01:00
parent 4a753b0b8d
commit abb1ea4a38
9 changed files with 383 additions and 4 deletions
+1
View File
@@ -159,6 +159,7 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
+2 -1
View File
@@ -1,8 +1,9 @@
#include "Entity.h"
#include <iostream>
Entity::Entity()
{
}
Entity::Entity(std::string name) : name(name)
+28 -2
View File
@@ -1,3 +1,5 @@
#include <format>
#include "Monster.h"
Monster::Monster(int strength) : Entity("My Monster"), _strength(strength)
@@ -5,10 +7,34 @@ Monster::Monster(int strength) : Entity("My Monster"), _strength(strength)
this->name = "My Monster";
}
//Monster Monster::Create(Monsters type)
//{
// Monster monster;
// switch (type)
// {
// case Ork:
// monster._strength = 10;
// monster._speed = 1.0f;
// break;
// case Troll:
// monster._strength = 5;
// monster._speed = 3.0f;
// break;
// case Elve:
// monster._strength = 1;
// monster._speed = 10.0f;
// break;
// default:
// break;
// }
//
// return monster;
//}
std::string Monster::ToString()
{
return name + " " + "(" + std::to_string(_strength) + ")";
// TODO: show format
//return name + " " + "(" + std::to_string(_strength) + ")";
return std::format("{} ({})", name, _strength);
}
int Monster::Compare(ICompareable* other)
+11 -1
View File
@@ -2,15 +2,25 @@
#include "Entity.h"
#include "ICompareable.h"
//enum Monsters
//{
// Ork,
// Troll,
// Elve
//};
class Monster : public Entity, public ICompareable
{
public:
Monster(int strength);
//static Monster Create(Monsters type);
virtual void Move() = 0; // abstract (pure virtual method)
std::string ToString() override;
int Compare(ICompareable* other) override;
protected:
int _strength = 0;
};
float _speed = 0.0f;
};
+1
View File
@@ -12,6 +12,7 @@ int main()
entity.name = "My Entity";
//Monster monster; // can't be instantiated, because Monster is abstract
//Monster monster2 = Monster::Create(Monsters::Ork);
Ork ork;
ork.name = "My Ork";