1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
#include "stdafx.h"
#include <iostream>
#include <string>
#include <stdlib.h>
#include <time.h>
#include <stack>
#include <vector>
#define LootNumber 14
using namespace std;
// the 3 arrays stand for the 3 stats of each item
string NameOption[] = { "Stone", "Leather Gloves", "Dragon Gauntlets", "Chair Leg", "Dragon Scale Helmet", "Pebble", "Rusted Breastplate", "Dragon Breastplate", "Empty Bottle", "Chainmail Trousers", "Dragon Skin Trousers", "Broken Stick", "Dagger", "Dragons Sword" };
int RarityOption[] = { 0, 1, 3, 0, 3, 0, 2, 3, 0, 2, 3, 1, 2, 3 };
bool SetOption[] = { 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1 };
class Loot // grouping Name Rarity and Set
{
public:
string Name;
int Rarity;
bool Set;
Loot(string N, int R, bool S) // constructor initialises each of the fields
{
Name = N;
Rarity = R;
Set = S;
}
};
class TreasureChest
{
public:
stack<Loot> Chest;
// defines default constructor
TreasureChest(string E)
{
E = "Empty";
}
TreasureChest() // for loop gives the same random item every time return too later
{
int i = rand() % LootNumber;
int j = rand() % LootNumber;
int k = rand() % LootNumber;
int h = rand() % LootNumber;
Chest.push(Loot(NameOption[j], RarityOption[j], SetOption[j]));
Chest.push(Loot(NameOption[k], RarityOption[k], SetOption[k]));
Chest.push(Loot(NameOption[i], RarityOption[i], SetOption[i]));
Chest.push(Loot(NameOption[h], RarityOption[h], SetOption[h]));
}
};
//Gives player choise whether to keep or discard each loot item as it is revealed from the stack
void PlayerChoice()
{
PlayerRucksack();
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;
FillBag(PlayerRucksack().Rucksack);
// 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;
//store item in bag
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 << "This chest is now empty" << endl;
return;
}
class PlayerRucksack
{
public:
vector<Loot> Rucksack;
};
void FillBag(vector<Loot> &NewRucksack)
{
Loot NewLoot(NameOption[0], RarityOption[0], SetOption[0]);
NewRucksack.push_back(NewLoot);
}
void PrintBag(const vector <Loot>&NewRucksack)
{
for (unsigned int i = 0; i < NewRucksack.size(); i++)
{
cout << "Bag Item: " << NewRucksack[i].Name() << endl;
}
}
int main()
{
PrintBag(Rucksack);
return 0;
}
|