Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            //Create a Stack
            GameStack gameStack = new GameStack();

            //Push values
            gameStack.Push("Picking up an item.");
            gameStack.Push("Shooting weapon");
            gameStack.Push("Dropping an item");
            gameStack.Push("Healing self");
            gameStack.Push("Move back");
            gameStack.Push("Move forward");
            gameStack.Push("Move forward");
            gameStack.Push("Move forward");
            gameStack.Push("Move left");
            gameStack.Push("Move left");
            gameStack.Push("Die");

            //Get the top value
            for (int i = 0; i < gameStack.Count; i++)
            {
                Console.WriteLine(gameStack.Pop());
                Console.WriteLine();
            }

            Console.ReadLine();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            GameStack stack = new GameStack(15);

            stack.Push("Finish");
            stack.Push("Repeat");
            stack.Push("Rinse");
            stack.Push("Wake up");
            stack.Push("Go to bed");
            stack.Push("Drink liquid");
            stack.Push("Eat food");
            stack.Push("Kill me");
            stack.Push("Cry");
            stack.Push("Multiply by infinity");
            stack.Push("Throw error");
            stack.Push("Divide by 0");
            stack.Push("Subtract 2");
            stack.Push("Add 2");
            stack.Push("Start");

            while (stack.Count > 0)
            {
                Console.WriteLine(stack.Pop());
            }
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            //Create new GameStack object
            GameStack myStack = new GameStack();

            //Populate the Stack with 12 different strings
            myStack.Push("This line was added first.");                                                      //1
            myStack.Push("There will be twelve of these lines.");                                            //2
            myStack.Push("Even though this line is the third one,");                                         //3
            myStack.Push("It will be the third to last line printed out.");                                  //4
            myStack.Push("What you are reading right now is the lines");                                     //5
            myStack.Push("Being add in order and printed out the other way.");                               //6
            myStack.Push("This will probably be hard to read once it prints out,");                          //7
            myStack.Push("But that's the fundametals of how a stack works,");                                //8
            myStack.Push("Start at the top, and work your way down.");                                       //9
            myStack.Push("We're reaching the final line right about now.");                                  //10
            myStack.Push("Here's the penultimate line.");                                                    //11
            myStack.Push("Now this line was added last, but it's the first to be printed.");                 //12

            //Prints out the current number of items in the stack
            Console.WriteLine("MyStack Current Count : " + myStack.Count);
            Console.WriteLine();

            //Prints out each object in the stack until the stack is empty
            //Because of how stacks read from the top to bottom, the lines above will be presented in reverse order
            while (myStack.Count != 0)
            {
                //Once we write out the line, we remove the line from the stack and move to the next one
                Console.WriteLine(myStack.Pop());
            }
            Console.WriteLine();

            //Prints out the number of objects in the stack one more time
            Console.WriteLine("MyStack Current Count : " + myStack.Count);
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            GameStack playingStack = new GameStack(new string[0]);

            for (int i = 0; i < 10; i++)
            {
                playingStack.Push("Shooting weapon" + i);
            }
            Console.WriteLine(playingStack.Peek());
            string read    = "";
            bool   isEmpty = false;

            while (isEmpty == false)
            {
                read = Console.ReadLine();
                if (read == "push")
                {
                    Console.WriteLine("What command you'd like to push");
                    read = Console.ReadLine();
                    playingStack.Push(read);
                }
                else if (read == "pop")
                {
                    Console.WriteLine(playingStack.Pop());
                }
                else if (read == "list")
                {
                    foreach (var item in playingStack.Array())
                    {
                        Console.WriteLine(item);
                    }
                }

                if (playingStack.IsEmpty == true)
                {
                    isEmpty = true;
                }
            }
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            string    command; // String value for stack commands
            GameStack gameStack = new GameStack();

            // Populate stack with commands
            gameStack.Push("Move forward");
            gameStack.Push("Picking up an item");
            gameStack.Push("Shooting weapon");
            gameStack.Push("Move forward");
            gameStack.Push("Move forward");
            gameStack.Push("Move forward");
            gameStack.Push("Healing self");
            gameStack.Push("Move left");
            gameStack.Push("Move left");
            gameStack.Push("Picking up an item");

            while (gameStack.IsEmpty == false) // Pull commands off gameStack until count is zero
            {
                command = gameStack.Pop();
                Console.WriteLine(command);
            }
        }