-2

I'm recently learning C# but I've run into a problem.

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");
            }
        }
    }

The code above cannot execute because the compiler reports an error of control cannot fall-through from case label to another on the line where there is the switch(DiceResult) statement.

Can someone help my identify where my mistake is?

Nathaniel Ford
  • 20,545
  • 20
  • 91
  • 102
ParityB1t
  • 77
  • 4
  • 5
    It's not clear what you are asking. Please actually ask a question. – Faraday Jun 04 '14 at 13:43
  • 1
    Can you post the rest of your code? or at least a representative subset of it so we see the whole loop and what you do at the end of case 4, etc. ? – Tim Jun 04 '14 at 13:44
  • Please post the rest of the `switch` statement - it's difficult to diagnose the problem with half the code. – Chris Mantle Jun 04 '14 at 13:45
  • 1
    Are you aware, that you will never throw a 6, because the second argument of `Random.Next(int min, int max)` is "one greater than the greatest legal return value"? Use "`Dice.Next (1,7)`" instead. – EagleBeak Jun 04 '14 at 13:51

2 Answers2

0

try putting a break after

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

so you have:

 switch(DiceResult) // **control cannot fall through case on this line**
            {
            case 1:
            case 4:
                Console.WriteLine ("The attribute being played is Strength");
            break;
            }
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
surfsquid
  • 56
  • 7
0
case 3:
case 6:
    Console.WriteLine ("hello");

Here you need a break; statement, like this:

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

In C#, you can't create a case option without break;, return; or throw statement. Please refer MSDN| for more information.

VMAtm
  • 27,943
  • 17
  • 79
  • 125