Hey guys so i'm trying to make a mini game for my coursework.
I'm trying to create a "bag"(an array) to store the "loot" items a player selects during players choise.
Im trying to make the bag something along the lines of:
string *Bag[6]
Bag = &(chest.top.Name);
but i cant seem to get my head around how im meant to be doing this correctly. I'v read loads online but i think iv hit that stupidity wall that keeps tripping me up haha.
please can someone tell me how to create a pointer array that will store the loot item from the top of the stack called chest.
class Loot // grouping name rarity into set
{
public:
string Name;
int Rarity;
bool Set;
Loot(string N, int R, bool S) // constructor initialises each of the feilds
{
Name = N;
Rarity = R;
Set = S;
}
};
class TreasureChest
{
public:
stack<Loot> Chest;
// define default constructor
TreasureChest()
{
int i = rand() % LootNumber;
for (i = 0; i < 5; i++)
{
Chest.push(Loot(NameOption[i], RarityOption[i], SetOption[i]));
}
}
};
// This prints a random selected item of loot to the screen
void PrintLoot()
{
int i = rand() % LootNumber;
Loot A(NameOption[i], RarityOption[i], SetOption[i]);
cout << "Loot item: " << A.Name << endl;
cout << "Rarity out of 3: " << A.Rarity << endl;
cout << "Part of set: " << A.Set << endl;
}
//Gives player choise whether to keep or discard each loot item as it is revealed from the stack
void PlayerChoice()
{
char Answer;
cout << "If you want to keep the item press Y" << endl;
cout << "If you want to discard the item press N" << endl;
cin >> Answer;
while (Answer == 'Y' || Answer == 'y')
{
cout << "Item stored in your bag" << endl;
// store item in bag array using pointer
return;
}
while (Answer == 'N' || Answer == 'n')
{
cout << "Item was discared from the Treasure Chest" << endl;
return;
}
while (Answer != 'y' || Answer != 'Y' || Answer != 'N' || Answer != 'n')
{
cout << "To decide press Y for accept OR press N for Decline" << endl;
cin >> Answer;
if (Answer == 'Y' || Answer == 'y') {
cout << "Item stored in your bag" << endl;
//*Bag = TreasureChest().Chest.top;
return;
}
else (Answer == 'N' || Answer == 'n'); {
cout << "Item was discared from the Treasure Chest" << endl;
return;
}
return;
}
}
// function that prints the contents of TreasureChest to the screen whilst asking the player if they want each item.
void PrintTreasureChest()
{
TreasureChest A;
int j;
for (j = 1; j < 5; j++)
{
cout << "Item " << j << " in your chest is: " << endl;
cout << "Name:" << (A.Chest.top()).Name << " Rarity out of 3: " << (A.Chest.top()).Rarity << " Part of a set: " << (A.Chest.top()).Set << endl;
PlayerChoice();
A.Chest.pop();
}
cout << "The chest is now empty" << endl;
return;
}
How would you recommend building something that stores things and can be accessed later?
I do apologies for my terrible everything really i am so new to this it literally blows my mind at times I dont seem to have the natural talent a lot of coders do.
Sorry, @Chronic Arrow,
haven't been around for a while.
I'm sure you have already found your solution, but just to put in my two pennies' worth: I'd use a std::vector.