Skip to content

Instantly share code, notes, and snippets.

@chancez
Created July 29, 2012 05:26
Show Gist options
  • Save chancez/3196227 to your computer and use it in GitHub Desktop.
Save chancez/3196227 to your computer and use it in GitHub Desktop.
int Apothecary::MakePotions()
{
//queue *orders;
//stack *shelf;
Potion currentPotion;
int count = 0;
//orders = new queue(sizeof(orders));
//shelf = new stack(sizeof(shelf));
// while there are orders on the queue
while(orders->peek(currentPotion))
{
// dequeue returns false if empty, breaks while loop
if(!orders->dequeue(currentPotion))
{
break; // conditional while prevents this scenario
}
else // dequeue dequeues potion, returns true and increments count
{
count++;
}
// push returns false if at capacity, prints error message
if(!shelf->push(currentPotion))
{
cout << "The shelf of potions is full. You can't make any more until somebody buys some." << endl;
}
else // push pushes the potion, returns true and couts a success message
{
cout << "Made a " << PotionTypeString(currentPotion.GetType()) << " potion." << endl;
}
}
return count;
// pseudocode:
// if the stack is full
// cout "The shelf of potions is full. You can't make any more until somebody buys some."
// break
// else
// dequeue potion
// push potion
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment