RPG永远锁定胸部问题 [英] RPG Forever Locked Chest Problem

查看:69
本文介绍了RPG永远锁定胸部问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

***我设法解决了这个问题。我在static void Main(string [] args)中创建了一个名为RoomChallange_ItemNeeded的bool,并将其设置为false。然后在take-key的情况下,我将其设置为true,在drop-key的情况下,我将其设置为false。最后在使用的情况下,if语句是这样的:

***I have managed to fix this issue. I created a bool called RoomChallange_ItemNeeded in static void Main(string[] args), and set it to false. Then in the case "take-key" I set it to true, and in the case "drop-key" I set it to false. Finally in the case "use", the if statement is this:

if (currentRoom.RoomChallange != null && RoomChallange_ItemNeeded == true)
{
   Console.WriteLine("currentRoom.RoomChallange.SuccessText");
   playeritems.Remove(currentRoom.RoomChallange.ItemNeeded);
   currentRoom.RoomChallange = null;
}

***如果您有任何疑问,我会留下此字符串,因为我没有看到关于此主题的任何问题。好运编程。



您好,我正在尝试在控制台应用程序中为基于文本的RPG创建一个箱子。我的问题是,当你尝试解开胸部时,即使你有要求的规格,也不会触发它的访问权限。我已经在网上寻求帮助,但没有找到这样的帮助。我的问题是,为什么我的代码不能正常工作,如果我的工作根本不起作用,有没有办法撬开胸部?我没有收到任何错误消息,警告,我尝试了debuger无济于事。这是我的代码:

***I will leave this string if you have any questions, as I saw no questions on this subject. Good luck programming.

Hello, I am trying to create a chest for my text based rpg in a Console Application. My problem is that when you try to unlock the chest, even if you have the specifications asked for, the ability to access it will not trigger. I have looked online for help on this but have found no such help. My question is why is my code not working, and is there a way to impliment the chest if my will simply not work? I have recived no error messages, warnings and I have tryed the debuger to no avail. Here is my code:

#region challenge
class Challenge
{
    public Items ItemNeeded;
    public string ChallengeText;
    public string SuccessText;
    public string BlockedExits;

    public Challenge(string challenge, string success, Items needed, string blocked)
    {
        ChallengeText = challenge;
        SuccessText = success;
        ItemNeeded = needed;
        BlockedExits = blocked;
    }
}
#endregion challenge
#region class items
class Items
{
    public string Name;
    public string Description;
    public decimal Wieght;
    public Items (string name, string description, decimal wieght)
    {
        Name = name;
        Description = description;
        Wieght = wieght;
    }
}
#endregion class items
#region class room
class Room
{
    public string Title;
    public string Description;
    public string map_location;
    public Room Warn;
    public Room Dwarn;
    public Room Swarn;
    public Room Awarn;
    public Items RoomItem;
    public Items RoomItem2;
    public Items RoomItem3;
    public Challenge RoomChallange;

    public Room(string title, string description, string maplocation)
    {
        Title = title;
        Description = description;
        map_location = maplocation;
    }
}
#endregion class room



*此部分位于静态void Main(字符串) [] args);

*我已经初始化了接下来的三个块以允许特定选项,例如take-key而不是take。我不确定房间和房间是否必须在这里初始化。 :/


*This part is in the static void Main(string[] args);
*I have initialized these next three chunks to allow specific options such as "take-key" instead of just "take". I am not sure if the rooms and challange had to be initialized in here. :/

Items key = new Items("the Pit Boss Key", "This is the key for the pit boss chest.", 1);




Room darkcave32a45 = new Room("Dark Cave", "This is the treasure room. A large chest sits in the center with a lock on it. At the back you see an Elvish Axe, and a Bronze Hammer. Five orcics are at the edge of the chest, and ten are at your feet. You can go Swarn.", "You are underground, and cannot tell your location.");
Room darkcave32achest = new Room("Chest", "You have opened the chest, as you rummage around through it you find a sack of fifty Orcics, an iron dagger, and a frost staff. The chest vomits out ancient dust when you opened it. The chest has been plastered together to just stay in the condition that it is. What a strange paradox between the bandits wealth and items they house themselves with.", "There is no point in trying to find your location down here.");




Challenge Room_Challange = new Challenge("The chest is locked!", "The rusty key unlocks the chest.", key, "w");



*当我尝试测试使用选项时,不会出现成功文本或允许您打开胸部。


*When I attempt to test the "use" option the "success text" or allowing you to open the chest do not occur.

#region rooms
Room currentRoom = SetUpMap();
string userChoice = "";
List<Items> playeritems = new List<Items>();
while (userChoice != "quite")
{
    DescribeRoom(currentRoom);
    userChoice = Console.ReadLine().ToLower();
    switch (userChoice)
    {
        case "w":
            currentRoom = GoTo(currentRoom.Warn, currentRoom, userChoice, playeritems);
            break;
        case "take-key":
            if (currentRoom.RoomItem != null)
            {
                Console.WriteLine("You have taken the {0}.", key.Name);
                playeritems.Add(key);
                playerwieght = playerwieght + key.Wieght;
                key = null;
            }
            break;
        case "drop-key":
            if (currentRoom.RoomItem == null)
            {
                Console.WriteLine("You have droped {0}", key.Name);
                playeritems.Remove(key);
                playerwieght = playerwieght - key.Wieght;
            }
            break;
        case "use":
            if (currentRoom.RoomChallange != null && playeritems.Contains(currentRoom.RoomChallange.ItemNeeded))
            {
                Console.WriteLine(currentRoom.RoomChallange.SuccessText);
                playeritems.Remove(currentRoom.RoomChallange.ItemNeeded);
                currentRoom.RoomChallange = null;
            }
            break;
        default:
            Console.WriteLine("Sorry, but I don't understand that. Type in help for a list of commands.");
            break;
    }
}
#endregion rooms



*这是房间创建和链接在一起的地方。 46号房间来到45号房间。我犯了这个错误并让它看到它没有任何伤害。我把胸部变成了一个房间,因为我可以轻松地创造一个胸部的效果,而不必冒险做任何事情。我使用w命令作为占位符。


*This is where the rooms are created and linked together. Room 46 comes before Room 45. I had made that mistake and left it seeing as it did no harm. I had made the "chest" a room becuase I could easiy create the effect of a chest without having to do anything adventureaus. I used the "w" command as a placeholder.

Room darkcave32a46 = new Room("Dark Cave", "Welcome to the pit bosses thrown. He lifts his eyebrow questioning "Well?" .He sits on his large thrown chair barely about to buckle. The chair has a few rusted swords sticking out of it in an uneven curved pattern. Two guard stand in front of the sovereign, relaxed. A few stacks of ten Orcics lye in the back corner. You can go Warn and Dwarn.", "You are underground and cannot find your location");
Room darkcave32a45 = new Room("Dark Cave", "This is the treasure room. A large chest sits in the center with a lock on it. At the back you see an Elvish Axe, and a Bronze Hammer. Five orcics are at the edge of the chest, and ten are at your feet. You can go Swarn.", "You are underground and cannot find your location");
Room darkcave32achest = new Room("Chest", "You have opened the chest, as you rummage around through it you find a sack of fifty Orcics, an iron dagger, and a frost staff. The chest vomits out ancient dust when you opened it. The chest has been plastered together to just stay in the condition that it is. What a strange paradox between the bandits wealth and items they house themselves with.", "You are underground and cannot find your location");
Items Orcics_50 = new Items("50 Orcics", "A pile of 50 gold coins.", 5);
Items Iron_Dagger = new Items("Iron Dagger", "A sharp iron dagger. Short Blade, Strength 50, Damage 1-5", 3);
Items Frost_Staff = new Items("Frost Staff", "A frost staff. Staff, Strength 100, Frost Damage 10", 10);
Items key = new Items("Pit Boss Key", "This is the key to the Pit Boss's Chest.", 2);
Challenge Room_Challange = new Challenge("The chest is locked!", "You have unlocked the chest!", key, "w");
darkcave32a46.RoomItem = key;
darkcave32achest.RoomItem = Orcics_50;
darkcave32achest.RoomItem2 = Iron_Dagger;
darkcave32achest.RoomItem3 = Frost_Staff;
darkcave32a45.RoomChallange = Room_Challange;



*这就是告诉玩家他们不能以这种方式走路或者说门被锁定的原因。每当我尝试使用键输入并输入use命令时,都会显示挑战文本。


*This is what tells the player they cant go this way or that lets say a door is locked. The challange text is showed every time I try to enter with the key and entering the use command.

static Room GoTo(Room nextRoom, Room currentRoom, string direction, List<Items> playeritems)
{
    if (nextRoom != null)
    {
        if (currentRoom.RoomChallange != null && currentRoom.RoomChallange.BlockedExits.Contains(direction))
            Console.WriteLine(currentRoom.RoomChallange.ChallengeText);
        else
            currentRoom = nextRoom;

    }
    else
    {
        Console.WriteLine("There is no exit in that direction.");
    }
    return currentRoom;
}



感谢您提前回答并查看我的问题。非常感谢您的回答。


Thanks for answering and looking at my question in advance. Your answer is greatly appreciated.

推荐答案

这非常复杂。你的胸部应该是一个班级。它应该有一个属性,说明它是否被锁定。试图与它进行交互应该检查它是否被锁定,或者至少在它被锁定时表现不同。



您的房间应该有一系列物品,而不是固定的数。您的代码现在将项目限制在一个房间,这意味着您需要编写代码来处理每个项目,而不是迭代一个集合。
This is wildly complicated. Your chest should be a class. It should have a property that says if it's locked or not. Attempts to interact with it should check if it's locked, or at least behave differently if it's locked or not.

Your room should have an array of items, not a fixed number. Your code limits the items to a room right now, and means you need to write code to deal with each one, instead of iterating over a collection.


这篇关于RPG永远锁定胸部问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆