Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- typedef unsigned uint;
- using namespace std;
- class Player
- {
- private:
- const static uint PLAYER_BAG_SIZE = 50;
- string m_strPlayerName;
- int bag[PLAYER_BAG_SIZE];
- public:
- Player(string NAME)
- {
- m_strPlayerName = NAME;
- for (uint i = 0; i < 50; ++i)
- {
- bag[i] = 0;
- }
- }
- void WriteBagContent()
- {
- cout << GetPlayerName() << "'s bag: " << endl;
- for (uint i = 0; i < 50; ++i)
- {
- cout << "Slot: " << i << " contains: " << bag[i] << endl;
- }
- }
- void AddItem(int nItemID)
- {
- for (uint i = 0; i < 50; ++i)
- {
- while (bag[i] != 0)
- {
- i++;
- }
- if (bag[i] == 0)
- {
- bag[i] = nItemID;
- break;
- }
- }
- }
- void CraftItem(int nItemID)
- {
- //Troche głupi ale działający handler poszczególnych itemów do craftingu
- if (nItemID == 1)//np. pochodnia (ID = 1)
- {
- if (HasItemCount(10, 4) && HasItemCount(11, 1))
- {
- AddItem(1);
- }
- else return;
- //patyki (ID = 10), węgiel (ID = 11)
- }
- else if (nItemID == 2)//np. włócznia
- {
- if (HasItemCount(10, 2) && HasItemCount(12, 1))
- {
- AddItem(2);
- }
- else return;
- //znów patyki (ID = 10), żelazo (ID = 13)
- }
- cout << "Player: " << GetPlayerName() << " has crafted item: " << nItemID << endl;
- //Na nic lepszego nie wpadłem :(
- }
- bool HasItemCount(int nItemID, int count)
- {
- int tempcount = 0;
- for (uint i = 0; i < 50; ++i)
- {
- if (bag[i] == nItemID)
- {
- tempcount++;
- }
- }
- if (tempcount == count || tempcount > count)
- return true;
- else return false;
- return false;
- }
- string GetPlayerName() const
- {
- return m_strPlayerName;
- }
- };
- int main()
- {
- Player* tester = new Player("Tester");
- cout << "Player's name: " << tester->GetPlayerName() << endl;
- tester->WriteBagContent();
- cout << endl;
- tester->CraftItem(1);
- //Nie powiedzie się = brak przedmiotów aby stworzyć pochodnię
- tester->WriteBagContent();
- cout << endl;
- tester->AddItem(10);
- tester->AddItem(10);
- tester->AddItem(10);
- tester->AddItem(10);
- tester->AddItem(11);
- tester->WriteBagContent();
- cout << endl;
- tester->CraftItem(1);
- //Powinno się powieść
- tester->WriteBagContent();
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement