*This class is not used in the game at all anymore. It was initially, but I've since removed it. Stacks are still a really important concept to understand so I'm keeping it in. You can safely skip this section if you want.
A stack is a data structure that we'll make good use of in our game. It's good to understand stacks because you'll probably use them in a lot of different kind of games. The concept of a stack is simple to understand. Imagine that you have a stack of CDs on a spindle, like in the picture to the right. Because of the spindle, you can't just remove any CD. You can only remove the CD on the top. If you want to add a CD to the stack, then you can only place it on the top.
If, however, you really want to add or remove a CD from somewhere in the middle, then you first have to remove all of the CDs until you get to the location you want to add or remove a CD. Then you can place the new CD on the stack, but then you'll have to replace all of the previous CDs you just removed.
The following will help you understand some stack terminology:
That's all a stack really is, nothing too hard there right? Since we're using Python we'll use a list to represent a stack. A list is just a collection of items. We'll define the top of the stack as the end of the list. A stack is known as a LIFO which stands for Last In First Out. That just means if you have a bunch of things you need to add to the stack, the last item you add will be the first item removed. Conversely, the first item you add to the stack will be the last item removed from the stack. So I guess a stack is also a FILO (First In, Last Out). Was Jesus talking about stacks when he said "...the last will be first, and the first will be last"? I guess Jesus was just a misunderstood programmer.
In the same directory as the Vector class create the Stack class in a file called stack.py. As you can see a stack is really just a list of items, but we only add and remove items from one end of the list.
The 'isEmpty' method just checks to see if the list is empty and returns true or false.
The 'clear' method just clears out the list.
The 'push' method adds items to the end of the list.
The 'pop' method removes an item from the end of the list.
The 'peek' method just returns the item at the end of the list without modifying the stack. Unlike the pop method we don't remove anything.