小编Cer*_*xes的帖子

C# Or 运算符问题

我很确定你们中有人可以帮助我解决这个问题。我没有找到也不理解解决方案。

if (hero.IsAlive || creature.IsAlive == false)
        {
            if (hero.IsAlive == true)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                EnemyHitInterface();
                Console.ForegroundColor = ConsoleColor.White;
                Thread.Sleep(1500);
                hero.Exp += 150;
                baseSetting.YouWin();
                hero.UpdateLvL();
                hero.CharacterInterface(hero);
                hero.PrintStatsHero();
                Console.ReadKey();
                CheckForItem();
                hero.PrintStatsHero();
                Console.ReadKey();
            }
            else if (creature.IsAlive == true)
            {
                Console.Clear();
                CenterText("You are dead. See you next time...", 15);
                Console.ReadKey();
                Environment.Exit(0);
            }
        }
Run Code Online (Sandbox Code Playgroud)

在我看来,如果操作很简单,一旦英雄或生物死亡,它就会被触发。如果生物死了,一切都很好,但如果英雄死了,就不会被触发。我认为什么是我不明白的?

对我来说就像:

当英雄或生物死亡时,进入 如果英雄还活着,则执行此操作 如果生物还活着,则执行此操作

但就像我说的,对于生物来说这是行不通的

c# if-statement operator-keyword

0
推荐指数
1
解决办法
80
查看次数

标签 统计

c# ×1

if-statement ×1

operator-keyword ×1