コード例 #1
0
        /// <summary>
        /// Update the interface. This is called every time a command is entered,
        /// so the command parser and GUI code go here.
        /// </summary>
        public void Update(string _input)
        {
            if (_input != "")
            {
                messages.Add(new Message("Input: " + _input));
                messages[messages.Count - 1].Foreground = ConsoleColor.Cyan;
                Command newCommand = parser.Parse(_input);
                if (resetScroll)
                {
                    gui.MainScroll = 0;
                }
                else
                {
                    resetScroll = true;
                }

                //Catch special commands outside of actual parsing
                //These commands do not advance the game
                if (newCommand.Text.ToLower() == "expand inventory")
                {
                    if (gui.InventorySize < 10)
                    {
                        gui.InventorySize++;
                    }
                }
                else if (newCommand.Text.ToLower() == "shrink inventory")
                {
                    if (gui.InventorySize > 1)
                    {
                        gui.InventorySize--;
                    }
                }
                else if (newCommand.Text.ToLower() == "open inventory")
                {
                    gui.InventorySize = 6;
                }
                else if (newCommand.Text.ToLower() == "close inventory")
                {
                    gui.InventorySize = 1;
                }
                else if (newCommand.Text.ToLower() == "scroll down" || newCommand.Text.ToLower() == "sd")
                {
                    //int maxScroll = 100;
                    //if (gui.MainScroll < maxScroll) { gui.MainScroll += Math.Min(maxScroll - gui.MainScroll, 4); }
                    gui.MainScroll += gui.Height / 2;
                    resetScroll     = false;
                }
                else if (newCommand.Text.ToLower() == "scroll up" || newCommand.Text.ToLower() == "su")
                {
                    if (gui.MainScroll > 0)
                    {
                        gui.MainScroll -= Math.Min(gui.MainScroll, Math.Max(1, (gui.Height / 2) - 5));
                    }
                    resetScroll = false;
                }
                else if (newCommand.Text.ToLower() == "help")
                {
                    if (!showingHelp)
                    {
                        showingHelp   = true;
                        underHelpText = gui.MainText;
                        gui.MainText  = helpText;
                    }
                    else
                    {
                        showingHelp  = false;
                        gui.MainText = underHelpText;
                    }
                }
                else if (newCommand.Text.ToLower() == "examine room" || newCommand.Text.ToLower() == "er")
                {
                    gui.MainText  = dungeon.CurrentRoom.ExtraDescript;
                    gui.MainText += "\n\n";
                    gui.MainText += dungeon.CurrentRoom.GetContentsDescription();
                    gui.MainText += "\n\n";
                    gui.MainText += dungeon.CurrentRoom.GetDoorsDescription();
                }
                else if (newCommand.Text.ToLower() == "examine all")
                {
                    gui.MainText  = dungeon.CurrentRoom.ExtraDescript;
                    gui.MainText += "\n\n";
                    gui.MainText += dungeon.CurrentRoom.GetContentsDescription();
                    gui.MainText += "\n\n";
                    gui.MainText += dungeon.CurrentRoom.GetDoorsDescription();
                    gui.MainText += "\n\n";
                    gui.MainText += player.ToString();
                }
                else if (newCommand.Text.ToLower() == "examine self")
                {
                    gui.MainText = player.ToString();
                }
                else if (newCommand.Text.ToLower() == "go north")
                {
                    if (dungeon.GoNorth() > 0)
                    {
                        gui.MainText = dungeon.CurrentRoom.Description;
                    }
                    else if (dungeon.GoNorth() == -2)
                    {
                        gui.MainText = "The monsters block your exit.\n" + dungeon.CurrentRoom.ExtraDescript;
                    }
                    else
                    {
                        gui.MainText = "You cannot go that way.\n" + dungeon.CurrentRoom.ExtraDescript;
                    }
                }
                else if (newCommand.Text.ToLower() == "go south")
                {
                    if (dungeon.GoSouth() > 0)
                    {
                        gui.MainText = dungeon.CurrentRoom.Description;
                    }
                    else if (dungeon.GoSouth() == -2)
                    {
                        gui.MainText = "The monsters block your exit.\n" + dungeon.CurrentRoom.ExtraDescript;
                    }
                    else
                    {
                        gui.MainText = "You cannot go that way.\n" + dungeon.CurrentRoom.ExtraDescript;
                    }
                }
                else if (newCommand.Text.ToLower() == "go east")
                {
                    if (dungeon.GoEast() > 0)
                    {
                        gui.MainText = dungeon.CurrentRoom.Description;
                    }
                    else if (dungeon.GoEast() == -2)
                    {
                        gui.MainText = "The monsters block your exit.\n" + dungeon.CurrentRoom.ExtraDescript;
                    }
                    else
                    {
                        gui.MainText = "You cannot go that way.\n" + dungeon.CurrentRoom.ExtraDescript;
                    }
                }
                else if (newCommand.Text.ToLower() == "go west")
                {
                    if (dungeon.GoWest() > 0)
                    {
                        gui.MainText = dungeon.CurrentRoom.Description;
                    }
                    else if (dungeon.GoWest() == -2)
                    {
                        gui.MainText = "The monsters block your exit.\n" + dungeon.CurrentRoom.ExtraDescript;
                    }
                    else
                    {
                        gui.MainText = "You cannot go that way.\n" + dungeon.CurrentRoom.ExtraDescript;
                    }
                }
                else
                {
                    if (newCommand.Pattern != "")
                    {
                        bool turnConsumed = false;
                        messages.Add(new Message("Pattern: " + newCommand.Pattern));//For debugging. Remove later!
                        messages[messages.Count - 1].Foreground = ConsoleColor.DarkGray;

                        if (newCommand.Tokens[0].Value == 1)//If the command starts with a verb
                        {
                            if (newCommand.Tokens[0].Text == "take")
                            {
                                gui.MainText = dungeon.CurrentRoom.Contents.Take(newCommand.Tokens, player.Contents);
                                turnConsumed = true;
                            }

                            if (newCommand.Tokens[0].Text == "drop")
                            {
                                gui.MainText = dungeon.CurrentRoom.Contents.Drop(newCommand.Tokens, player.Contents);
                                turnConsumed = true;
                            }

                            if (newCommand.Tokens[0].Text == "examine")
                            {
                                if (player.Contents.Find(newCommand.Tokens) != null)
                                {
                                    gui.MainText = player.Contents.Find(newCommand.Tokens).ToString();
                                }
                                else if (dungeon.CurrentRoom.Contents.Find(newCommand.Tokens) != null)
                                {
                                    gui.MainText = dungeon.CurrentRoom.Contents.Find(newCommand.Tokens).ToString();
                                }
                                else
                                {
                                    gui.MainText = "There is nothing like that to examine here.";
                                }
                            }

                            if (newCommand.Tokens.Count >= 3 && newCommand.Tokens[0].Text == "attack" && newCommand.Tokens[2].Text == "with")
                            {
                                if (dungeon.CurrentRoom.Contents.Find(newCommand.Tokens[1].Text) != null &&
                                    player.Contents.Find(newCommand.Tokens[3].Text) != null)
                                {
                                    try
                                    {
                                        gui.MainText = GameRules.PlayerAttacksMonster(this, (Weapon)player.Contents.Find(newCommand.Tokens[3].Text), player.Buffs + player.Contents, (Monster)dungeon.CurrentRoom.Contents.Find(newCommand.Tokens[1].Text), (int)DateTime.Now.Ticks & 0x0000FFFF);
                                        turnConsumed = true;
                                    }
                                    catch
                                    {
                                        gui.MainText = "You cannot do that.";
                                    }
                                }
                            }
                        }

                        if (turnConsumed)
                        {
                            Step(); //The player has issued an action. Advance the game one step.
                        }

                        gui.MainText += "\n--------------------------------\n";
                        gui.MainText += dungeon.CurrentRoom.ExtraDescript;
                        gui.MainText += "\n\n";
                        gui.MainText += dungeon.CurrentRoom.GetContentsDescription();
                        gui.MainText += "\n\n";
                        gui.MainText += dungeon.CurrentRoom.GetDoorsDescription();
                    }
                    else
                    {
                        messages.Add(new Message("I did not understand any of that."));
                    }
                }
            }

            gui.Render(this);
        }