Exemplo n.º 1
0
 public Llatext.Instructions.Instruction Use(string[] items)
 {
     if (items.Contains("BEGGAR") && beggerThere)
     {
         if (items.Contains("BANKNOTE"))
         {
             if (InventoryHandling.HasItem("banknote"))
             {
                 InevitableGUI.Output("You hand the beggar the cash. He smiles at you and hands you a Get Out Of Death Free card. He then disappears in a puff of smoke");
                 InventoryHandling.AddGODFC();
                 InventoryHandling.RemoveItem("banknote");
                 beggerThere = false;
             }
             else
             {
                 InevitableGUI.Output("You don't have that item");
             }
         }
         else if (items.Contains("HAMMERDRIVER"))
         {
             if (InventoryHandling.HasItem("hammerdriver"))
             {
                 InevitableGUI.Output("You whack the beggar with your hammer driver. He runs away screaming");
                 InevitableGUI.Output("You chase him but eventually give up.");
                 beggerThere = false;
             }
             else
             {
                 InevitableGUI.Output("You don't have that item");
             }
         }
         else
         {
             InevitableGUI.Output("You don't have that item");
         }
     }
     else
     {
         InevitableGUI.Output("You can't use those two together");
     }
     return(new Instruction());
 }
Exemplo n.º 2
0
        public static void ProcessTerm(string term)
        {
            Instruction returnInstruction = new Instruction(InstructionType.UNKNOWN, "");

            term = term.ToUpper();

            if (term.Contains("QUIT") || (term.Contains("EXIT")))
            {
                InevitableGUI.Output("Bye");
                System.Environment.Exit(0);
            }

            if (hasWon)
            {
                List <string> replies = new List <string>();

                replies.Add("You won already");
                replies.Add("You've already won.. what else do you want?");
                replies.Add("We've got a winner here");
                replies.Add("Yeah you won. You can stop now");
                replies.Add("A winnar is you!");
                replies.Add("Why are you still playing? You're a winner. Do something else");

                InevitableGUI.Output(PickReplyFromList(replies));
                return;
            }

            if (!(term.Contains("START")) && (!hasStarted))
            {
                InevitableGUI.Output("\"Start Easy\" or \"Start Hard\" to start");
                return;
            }
            #region 0 parameters

            if (term.Contains("ABOUT"))
            {
                InevitableGUI.Output("Inevitable, and the LLatext Engine was written by Llama");
                InevitableGUI.Output("Dedicated to the Missus - who hates these sorts of games");
                InevitableGUI.Output("Feel free to redistribute, break, rewrite and not sell");
                InevitableGUI.Output("Please credit accordingly if you do");

                return;
            }

            if (term.Contains("LOOK"))
            {
                returnInstruction = currentRoom.Look();
            }
            else if (term.Contains("INVENTORY"))
            {
                string inventoryOutput = InventoryHandling.ListInventory();

                //split its linebreaks

                var inventorySplit = inventoryOutput.Split('\n');

                InevitableGUI.Output("Your inventory contains : " + inventorySplit[0]);

                for (int i = 1; i < inventorySplit.Count(); i++)
                {
                    InevitableGUI.Output(inventorySplit[i]);
                }
            }
            else if (term.Contains("HELP"))
            {
                InevitableGUI.Output("Help:");
                InevitableGUI.Output("Start - Starts the Game");
                InevitableGUI.Output("Quit - Quits the game");
                InevitableGUI.Output("Look - Looks around the room");
                InevitableGUI.Output("Inventory - Shows your inventory");
                InevitableGUI.Output("Help - Helps you.");
                InevitableGUI.Output("Remove X - Removes X");
                InevitableGUI.Output("Examine X - Examines a particular X in the room or your inventory");
                InevitableGUI.Output("Take X - Adds X to your inventory");
                InevitableGUI.Output("Open X - Opens X");
                InevitableGUI.Output("Go X - Go to a cardinal direction North/South/East/West");
                InevitableGUI.Output("Use X - Uses an item belonging in the room or in the inventory");
                InevitableGUI.Output("Use X with Y - Uses two items together");
                InevitableGUI.Output("About - Displays some about information");
                InevitableGUI.Output("Load X - Loads a savegame with filename x.isg");
                InevitableGUI.Output("End Help");
            }

            #endregion

            #region 1 parameters
            else
            if (term.Contains("EXAMINE"))
            {
                //we want the next word after it

                string nextWord = GetNextWord("EXAMINE", term);

                if (nextWord == null)
                {
                    InevitableGUI.Output("Error in Command - Examine what?");
                }
                else
                {
                    //check if its in the inventory
                    string invDesc = Inventory.InventoryHandling.DescribeItem(nextWord);

                    if (invDesc != "")
                    {
                        InevitableGUI.Output(invDesc);
                    }
                    else
                    {
                        //Check if its in the room
                        returnInstruction = currentRoom.Examine(nextWord);
                    }
                }
            }
            else if (term.Contains("START"))
            {
                string nextWord;

                if ((nextWord = GetNextWord("START", term)) == null || !((nextWord.Contains("EASY") || (nextWord.Contains("HARD")))))
                {
                    InevitableGUI.Output("Start Easy or Hard?");
                }
                else
                {
                    if (nextWord.Contains("EASY"))
                    {
                        InventoryHandling.AddGODFC();
                    }
                    else if (nextWord.Contains("HARD"))
                    {
                        //no GODFC
                    }
                    else
                    {
                    }


                    if (!hasStarted)
                    {
                        hasStarted = true;
                        InevitableGUI.Output("This is a game about death.");
                        InevitableGUI.Output("Regardless of what you do, it is Inevitable");
                        InevitableGUI.Output("How long can you survive?");
                        InevitableGUI.Output("---Starting Game---");

                        InevitableGUI.Output("You open your eyes and see only darkness. You are wearing a blindfold");
                        startTime = DateTime.Now;
                    }
                    else
                    {
                        InevitableGUI.Output("((The Game has started already. Focus!))");
                    }
                }
            }
            else if (term.Contains("TAKE"))
            {
                //we want the next word after it

                if (GetNextWord("TAKE", term) == null)
                {
                    InevitableGUI.Output("Error in command. Take what?");
                }
                else
                {
                    returnInstruction = currentRoom.Take(GetNextWord("TAKE", term));
                }
            }
            else if (term.Contains("OPEN"))
            {
                if (GetNextWord("OPEN", term) == null)
                {
                    InevitableGUI.Output("Error in command. Open what?");
                }
                else
                {
                    returnInstruction = currentRoom.Open(GetNextWord("OPEN", term));
                }
            }
            else if (term.Contains("GO"))
            {
                if (GetNextWord("GO", term) == null)
                {
                    InevitableGUI.Output("Error in command. Go where?");
                }
                else
                {
                    returnInstruction = currentRoom.Go(GetNextWord("GO", term));
                }
            }
            else if (term.Contains("USE") && !term.Contains("WITH"))
            {
                if (GetNextWord("USE", term) == null)
                {
                    InevitableGUI.Output("Error in command. Use what?");
                }
                else
                {
                    returnInstruction = currentRoom.Use(GetNextWord("USE", term));
                }
            }
            else if (term.Contains("LOAD") && !(term.Contains("CHEATLOAD")))
            {
                if (GetNextWord("LOAD", term) == null)
                {
                    InevitableGUI.Output("Error in command. Which file do you want to load?");
                }
                else
                {
                    returnInstruction = LoadSavedGame(GetNextWord("LOAD", term));
                }
            }

            #region cheats
            else if (term.Contains("CHEATLOAD"))         //loads the map
            {
                returnInstruction = new Instruction(InstructionType.LOAD, GetNextWord("CHEATLOAD", term.ToLower()));
            }
            else if (term.Contains("CHEATADD"))         //adds something to the inventory
            {
                Inventory.InventoryHandling.AddItem(new InventoryItem(GetNextWord("CHEATADD", term)));
            }
            else if (term.Contains("IDONTWANTTODIE"))         //adds a GOODFC
            {
                InventoryHandling.AddGODFC();
            }


            #endregion

            #endregion

            #region 2

            else if (term.Contains("USE") && term.Contains("WITH"))
            {
                if (GetNextWord("USE", term) == null)
                {
                    InevitableGUI.Output("Error in command. Use what?");
                }
                else
                {
                    if (GetNextWord("WITH", term) == null)
                    {
                        InevitableGUI.Output("Error in command. What do you want to use it with?");
                    }
                    else
                    {
                        string[] items = new string[] { GetNextWord("USE", term), GetNextWord("WITH", term) };

                        returnInstruction = currentRoom.Use(items);
                    }
                }
            }


            #endregion

            else
            {
                List <string> bogusReplies = new List <string>();
                bogusReplies.Add("Unknown Command");
                bogusReplies.Add("Pardon?");
                bogusReplies.Add("Come again?");
                bogusReplies.Add("I don't know how to do that");
                bogusReplies.Add("Command not understood");
                bogusReplies.Add("Uh what?");
                bogusReplies.Add("No idea what you want");
                bogusReplies.Add("What do you want?");

                InevitableGUI.Output(PickReplyFromList(bogusReplies));
            }

            #region Instruction Handling

            if (returnInstruction == null)
            {
                return;
            }

            if (returnInstruction.inst == InstructionType.LOAD)
            {
                try
                {
                    currentRoom       = rooms[returnInstruction.detail];
                    returnInstruction = currentRoom.Introduction(); //change return instruction
                }
                catch (Exception ex)
                {
                    InevitableGUI.Output("Something went wrong when loading the next room : " + ex.Message);
                }
            }
            if (returnInstruction.inst == InstructionType.WIN)
            {
                InevitableGUI.Output("------END OF ADVENTURE------");
                TimeSpan span = DateTime.Now - startTime;

                InevitableGUI.Output("It has taken you : " + span.TotalSeconds + " to finish this adventure!");

                hasWon = true;
            }
            if (returnInstruction.inst == InstructionType.DEATH)
            {
                try
                {
                    //Can he be saved?
                    if (InventoryHandling.ConsumeGOODFC())
                    {
                        InevitableGUI.Output("One of your Get Out Of Death Free cards disappears in a powerful light. You don't feel so dead anymore. Weird.");
                    }
                    else
                    {
                        //take it to the other place
                        currentRoom = rooms["otherside"];
                        currentRoom.Introduction();

                        //Rather dirty - but assign the cause of death
                        IEndRoom endRoom = (IEndRoom)currentRoom;
                        endRoom.SetCauseOfDeath(returnInstruction.detail);
                    }
                }
                catch (Exception ex)
                {
                    InevitableGUI.Output("Something went wrong when loading your death :( Sorry. Exception was : " + ex.Message + " Please tell me");
                }
            }
            if (returnInstruction.inst == InstructionType.SAVE)
            {
                //save the game
                InevitableGUI.Output("Your game has been saved. To be able to continue, use LOAD " + Save(Convert.ToInt32(returnInstruction.detail)));
            }

            #endregion
        }