且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C#布尔以外的方法不会阅读

更新时间:2022-11-08 17:44:58

试试这个:

  //使这个静态的,所以它是你的ApplyRules()方法进行访问。
公共静态布尔solvedp1 = FALSE;公共静态无效ApplyRules()
{
    如果(Level.Rooms [0,0] .GetItem(红宝石)!= NULL
        &安培; Level.Rooms [1,0] .GetItem(蓝色宝石)!= NULL
        &安培; solvedp1 == FALSE)
    {
        Console.Clear();
        Console.WriteLine(你把宝石在正确的地方。只要创业板位置,你觉得一哆嗦和温暖的感觉进入你的脚趾,并穿过你的整个身体,在房间里的异样的感觉消失了。你听到锁开锁的门尖叫,因为它打开。);
        Console.WriteLine(preSS回车键继续);
        Console.ReadKey();
        solvedp1 = TRUE;
    }
}

I have a question, which might be very nooby, but I have been stuck on it for the last 3 days. I have a method called ApplyRules, which is used very frequently so I can't define a bool inside of it, but when I try to define it outside of the method, it doesn't read it. Here is my code:

public bool solvedp1 = false;

    public static void ApplyRules()
    {

        if (Level.Rooms[0, 0].GetItem("Red Gem") != null
            & Level.Rooms[1, 0].GetItem("Blue Gem") != null
            & solvedp1 == false)
        {
            Console.Clear();
            Console.WriteLine("You put the gem in its correct place. As soon as the gem is in position, you feel a shiver and a warm feeling enters your toes and passes through your whole body. The strange feeling in the room is gone. You hear a lock unlocking and a door shrieking as it opens..");
            Console.WriteLine("Press enter to continue");
            Console.ReadKey();
            solvedp1 = true;
        }

Try this:

//Make this static so it is accessible to your ApplyRules() method.
public static bool solvedp1 = false;

public static void ApplyRules()
{
    if (Level.Rooms[0, 0].GetItem("Red Gem") != null
        & Level.Rooms[1, 0].GetItem("Blue Gem") != null
        & solvedp1 == false)
    {
        Console.Clear();
        Console.WriteLine("You put the gem in its correct place. As soon as the gem is in position, you feel a shiver and a warm feeling enters your toes and passes through your whole body. The strange feeling in the room is gone. You hear a lock unlocking and a door shrieking as it opens..");
        Console.WriteLine("Press enter to continue");
        Console.ReadKey();
        solvedp1 = true;
    }
}