如何跟踪用户的物品?

时间:2019-09-24 13:32:00

标签: c#

我正在命令提示符下制作一个基于文本的冒险游戏,我需要添加一种方式来跟踪进入某个房间后收集到的所有硬币,以及如果他们捡起其中一个唯一的武器,迷宫。

如果他们有足够的硬币或武器,则可以完成游戏。如果他们不这样做,他们就会死。 我几乎快要结束游戏了,我只是不知道添加跟踪硬币的数量或是否在武器室的最佳方式。

static void Main(string[] args)
    {
        GameTitle();
        Start();
    }

    public static void GameTitle()
    {
        Console.WriteLine("Welcome to The Maze.");
        Console.WriteLine("Press 'Enter' to start.");
        Console.ReadLine();
        Console.Clear();
        Start();

    }
    public int coins = 0; // Keeps track of coins
    public bool weapon = false;

    public static void Start()
    {
        string choice;

        Console.WriteLine("You slowly wake up in an old, decrepit abandoned building. You get the immediate sense you're in an insane asylum.");
        Console.WriteLine("You look around and there are three doors directly in front of you in the eerily silent room.");
        Console.WriteLine("A sign on the wall reads:");
        Console.WriteLine("Choose carefully, once a door is opened, it will never open again.");
        Console.WriteLine("Which door do you choose");
        Console.WriteLine("1. The door to the left.");
        Console.WriteLine("2. The door to the right.");
        Console.WriteLine("3. The door in front of you.");
        Console.Write("Choice: ");
        choice = Console.ReadLine().ToLower();
        Console.Clear();

        switch (choice)
        {
            case "1":
            case "left":
                {

                    A();
                    break;
                }
            case "2":
            case "right":
                {

                    C();
                    break;
                }
            case "3":
            case "front":
                {
                    B();
                    break;
                }
        }
    }

2 个答案:

答案 0 :(得分:2)

只要他们找到硬币:

coins++;

如果他们进入房间:

weapon = true;

答案 1 :(得分:0)

您只需将硬币存储在coins变量中,然后使用weapons布尔值即可知道硬币是否已经在该房间中。

或者,如果您愿意,也可以使用JSON文件,这样看起来会更专业,但可以在用户端进行编辑。