I am looking for code correctness and design usage as I think I might be over doing it in the class department.
There are two things I'm mostly concerned with.
The possible redundancy of classes derived from
IPerks. AsCommonPerks,UncommonPerks, etc, all look identical except for the rows/columns in its internal perk list. I'm thinking I should just have a concrete PerksList class instead.The use of an
enumto keep track of constant values for the different indices associated with theperkList. AllperkList's will follow the same order, so the indices will always mean the same thing regardless of whichIPerksderived class is being used.
PerkSlotEnums.h
enum class PERK_SLOTS { COMMON_SLOT_COLUMNS = 1, COMMON_SCOPE_PERK_COUNT = 2, SCOPE_SLOT_INDEX =0, STATS_UPGRADE_A_SLOT_INDEX = 1, UNIQUE_PERK_A_SLOT_INDEX = 2, STATS_UPGRADE_B_SLOT_INDEX = 3, UNIQUE_PERK_B_SLOT_INDEX = 4, STATS_UPGRADE_C_SLOT_INDEX = 5, UNIQUE_PERK_C_SLOT_INDEX = 6 }; IPerks.h
#pragma once #include "IPerk.h" #include "IComponent.h" #include <vector> class IPerks : public IComponent { public: IPerks(void); virtual ~IPerks(void); virtual void AddPerk(IPerk* perk, int column, int row) = 0; virtual void RemovePerk(unsigned int index_1, unsigned int index2) =0; virtual IPerk* GetPerk(unsigned int perkId) const = 0; }; CommonPerks.cpp
#include "CommonPerks.h" #include "PerkSlotEnums.h" CommonPerks::CommonPerks(void) { perkList.resize((int)PERK_SLOTS::COMMON_SLOT_COLUMNS); perkList[(int)PERK_SLOTS::SCOPE_SLOT_INDEX].resize((int)PERK_SLOTS::COMMON_SCOPE_PERK_COUNT); } CommonPerks::~CommonPerks(void) { } void CommonPerks::AddPerk(IPerk* perk, int column, int row) { perkList[column][row] = perk; } void CommonPerks::RemovePerk(unsigned int index_1, unsigned int index_2) { if(index_1 < perkList.size()) { if(index_2 < perkList.at(index_1).size()) { perkList.at(index_1).at(index_2) = nullptr; } } } IPerk* CommonPerks::GetPerk(unsigned int index_1, unsigned int index_2) const { if(index_1 < perkList.size()) { if(index_2 < perkList.at(index_1).size()) { return perkList.at(index_1).at(index_2); } } return nullptr; }
perkLista 2D vector? Why do you have a column and a row here? Do you not want to just store the "perks" by value in some sort of container? Additionally is CommonPerks a derived class ofIPerks? Do you have the newer c++11 available to you? \$\endgroup\$