need help in Power ups using Stack code
![Post Post](styles/prosilver/imageset/icon_post_target.gif)
hello, i understand the code for stack, but i want to implement it in a game that can use power ups, let's say my actor grab a shield power ups, it store in the inventory with 3 slots. so i will also need an actor which is shield, when pressing a key the shield will shows ups and used, so how do i implement the function in this code below? where do i place the power ups, and the key and used the power ups, also the function that grab and store into the inventory when the actor got and power ups?
need some experts' suggestion, would appreciate your help , thank you.
need some experts' suggestion, would appreciate your help , thank you.
- Code: Select all
#define MAX 100
int stack[MAX];
int top = 0; // first empty place
// add an element
int push (int x) {
if (top == MAX) return 0; // stack is full, operation failed
stack[top++] = x;
return 1; // operation succeeded
}
// take an element
int pop () {
int x;
if (top == 0) return -1; // stack is empty, operation failed (return -1, or any other negative number,
// or 0, if stack contains natural numbers)
x = stack[--top];
return x;
}
// read the top, without removing the element
int read() {
int x;
if (top == 0) return -1; // stack is empty, operation failed
x = stack[top];
return x;
}
// is stack empty
int empty() {
if (top == 0) return 1;
else return 0;
}
// is stack full
int full() {
if (top == MAX) return 1;
else return 0;
}