-2

私は最近 C# を学んでいますが、問題が発生しました。

public static void PlayGame(Kion Player1,Kion Player2)
    {
        bool Win = false;
        Console.WriteLine ("Let us begin then");
        Console.WriteLine ("Press Enter to roll the dice ");
        Console.ReadLine ();
        Console.WriteLine ();
        Console.WriteLine ();
        Random Dice = new Random();
        while (Win == false)
        {
            int DiceResult = Dice.Next (1,6);

            switch(DiceResult)   ***control cannot fall-through from one case label to another error message here***
            {
            case 1:
            case 4:
                Console.WriteLine ("The attribute being played is Strength");
                if ((Player1.Pride == "Kan") & (Player2.Pride == "Kan"))
                    Console.WriteLine ("You are both proud Kans, you match in combat and do not lose health");
                else
                    Console.WriteLine ("Those who belong to the 'Kan' pride unleashes their claws");
                    if (Player1.Pride == "Kan")
                {
                    Player2.LoseHealth();
                    int PlayerNumber = 2;
                    LoseHealthText(PlayerNumber, Player2);
                }
                    else
                    if (Player2.Pride == "Kan")
                {
                    Player1.LoseHealth ();
                    int PlayerNumber = 1;
                    LoseHealthText(PlayerNumber, Player1);
                }
                    else 
                    Console.WriteLine ("None belong to the Kan, you will all hide this turn");
                break;

            case 3:
            case 6:
                Console.WriteLine ("hello");
            }
        }
    }

上記のコードは、ステートメントcontrol cannot fall-through from case label to anotherがある行でコンパイラがエラーを報告するため、実行できません。switch(DiceResult)

誰かが私の間違いがどこにあるかを特定するのを手伝ってくれますか?

4

2 に答える 2

0

後に休憩を入れてみてください

Console.WriteLine ("The attribute being played is Strength");

だからあなたは持っています:

 switch(DiceResult) // **control cannot fall through case on this line**
            {
            case 1:
            case 4:
                Console.WriteLine ("The attribute being played is Strength");
            break;
            }
于 2014-06-04T13:46:32.680 に答える