-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInventory.cpp
More file actions
120 lines (114 loc) · 2.75 KB
/
Inventory.cpp
File metadata and controls
120 lines (114 loc) · 2.75 KB
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
#include "Inventory.h"
/*template <class T>
inventorys<T>::inventorys(){
inventory = new T[capacity];
}
template <class T>
inventorys<T>::inventorys(unsigned int memory) :capacity(memory){
}
template <class T>
inventorys<T>::inventorys(const inventorys& vector2) : capacity(vector2.capacity){
num_elements = vector2.num_elements;
capacity = vector2.capacity;
inventory = new T[capacity];
for (unsigned int i = 0; i < num_elements; i++){
inventory[i] = vector2.inventory[i];
}
}
template <class T>
void inventorys<T>::Push_Back(T numb){
if (capacity == num_elements){
capacity += 1;
T* buffer2 = new T[capacity];
int count = 0;
for (count; count < num_elements; count++)
buffer2[count] = inventory[count];
buffer2[count] = numb;
num_elements++;
delete[] inventory;
inventory = buffer2;
}
else
inventory[num_elements++] = numb;
}
template <class T>
void inventorys<T>::Push_Front(T numb){
if (capacity == num_elements){
capacity += 1;
T* buffer2 = new T[capacity];
int count = 1;
buffer2[0] = numb;
for (count; count < num_elements + 1; count++)
buffer2[count] = inventory[count - 1];
num_elements++;
delete[] inventory;
inventory = buffer2;
}
else{
num_elements++;
inventory[0] = numb;
for (int i = 0; i < capacity; i++){
inventory[i + 1] = inventory[i];
}
}
}
template <class T>
int inventorys<T>::Pop_Back(){
int number = inventory[--num_elements];
T* buffer2 = new T[num_elements];
int count = 0;
for (count; count < num_elements; count++){
buffer2[count] = inventory[count];
}
delete[] inventory;
inventory = buffer2;
return number;
}
template <class T>
bool inventorys<T>::isempty(){
return(inventory[0] == '\0');
}
template <class T>
const String& inventorys<T>::Get_Name(int item_num){
switch (item_num){
case 0: return "glass"; break;
case 1: return "key"; break;
case 2: return "matchstick"; break;
case 3: return "sword"; break;
case 4: return "chest"; break;
case 5: return "+5-AttackCard"; break;
case 6: return "hammer"; break;
}
}
template <class T>
inventorys<String>* inventorys<T>::Tokenize(String input){
inventorys<String>* total_string = new inventorys<String>;
String* word = new String[input.length()];
uint i;
char separator = ' ';
for (i = 0; input.string[i] != '\0'; i++){
if (input.string[i] != separator){
if (isupper(input.string[i]))
tolower(input.string[i]);
if (!word->isempty()){
total_string->Push_Back(word);
word->empty();
}
else
word->string[i] = input.string[i];
}
}
return total_string;
}
template <class T>
T& inventorys<T>::operator[](int pos)const{
return inventory[pos];
}
template <class T>
T& inventorys<T>::operator[](int pos){
assert(pos < num_elements)
return inventory[pos];
}
template <class T>
inventorys<T>::~inventorys(){
}*/