C# 先调用HealAlly()方法,然后返回到后面的那一行--我不知道如何让它跳过所有这些,直接转到计算机。我尝试在末尾添加EndTurn()方法,但仍然返回到PlayerTurn()方法中HealAlly()下面的一行。我可以继续努力找出答案,但我想我会看看

C# 先调用HealAlly()方法,然后返回到后面的那一行--我不知道如何让它跳过所有这些,直接转到计算机。我尝试在末尾添加EndTurn()方法,但仍然返回到PlayerTurn()方法中HealAlly()下面的一行。我可以继续努力找出答案,但我想我会看看,c#,C#,先调用HealAlly()方法,然后返回到后面的那一行--我不知道如何让它跳过所有这些,直接转到计算机。我尝试在末尾添加EndTurn()方法,但仍然返回到PlayerTurn()方法中HealAlly()下面的一行。我可以继续努力找出答案,但我想我会看看是否有人知道我做错了什么。如果你想从Stack Overflow社区得到帮助,像这样的问题的一个要求是花时间在你的问题中生成一个并发布,而不是从你的实际程序中提取片段。上面有太多不相关的代码,但是上面的代码无法编译和运行来重现您的问题。请修正你


先调用HealAlly()方法,然后返回到后面的那一行--我不知道如何让它跳过所有这些,直接转到计算机。我尝试在末尾添加EndTurn()方法,但仍然返回到PlayerTurn()方法中HealAlly()下面的一行。我可以继续努力找出答案,但我想我会看看是否有人知道我做错了什么。如果你想从Stack Overflow社区得到帮助,像这样的问题的一个要求是花时间在你的问题中生成一个并发布,而不是从你的实际程序中提取片段。上面有太多不相关的代码,但是上面的代码无法编译和运行来重现您的问题。请修正你的问题。
public bool Update()
        {
            // clears console for a fresh start
            Console.Clear();
           

            //branch who's turn it is and add a line indicating so
            if (playerTurn)
            {
                //print that it's the player's turn
                Console.WriteLine("It's Your Turn to Attack!");
              

  
                //run the player turn
                PlayerTurn();

            }
            else 
            {
                //print the rivals turn label
                Console.WriteLine("It's the Enemy's Turn to Attack!");
             
            }


            //run the rivals turn
             RivalsTurn();

            {
            }
        

            //end game check
            return EndTurn();
        }
 void PlayerTurn()
        {
            // print instructions to select an attacker
            Console.WriteLine($"Select which character will attack!\n(1) To Select {playerArray[0].Name()}\n(2) To Select {playerArray[1].Name()}\n(3) To Select {playerArray[2].Name()}\n(4) to view your teams current status\n(5) To Heal An Ally");
            // Loop until an attacker is chosen
          
            while (Attacker == null)
            {
                // use num 1-3 to select player party member that is the attacker
                ConsoleKeyInfo k = Console.ReadKey();
                if (k.KeyChar == '1')
                {
                    Attacker = playerArray[0];
                    Console.WriteLine($"\nYou've chosen to attack with {Attacker.Name()}");

          


                }
                else if (k.KeyChar == '2')
                {
                    Attacker = playerArray[1];
                    Console.WriteLine($"You've chosen to attack with {Attacker.Name()}");
             
                    
                 

                }
                else if (k.KeyChar == '3')
                {
                    Attacker = playerArray[2];
                    Console.WriteLine($"You've chosen to attack with {Attacker.Name()}");

                }
                else if(k.KeyChar == '4')
                {
                    PrintParties();
                    continue;

                } else if (k.KeyChar == '5') {
                    HealAlly();
                    break;
                }


               

                // start a new line after user input
                Console.WriteLine();
              
                // Data Validation: make sure the key typed is a valid key
                if (k.KeyChar < '1' || k.KeyChar > '5')
                {
                    Console.WriteLine("Please Enter (1), (2), or (3) to select your attacking character. Press (4) to view your stats, and (5) to Heal an Ally");
                    continue;
                } 
                else // convert from key input (1-3) to array element space (0-2)
                    curSelection = int.Parse(k.KeyChar.ToString()) - 1;
                {
                    
                }


              if (Attacker.GetHP() <= 0)
                {
                //check to make sure the selected character is alive HP > 0
                   //print the attackers name
                    //character's dead choose again
                    Console.WriteLine($"{Attacker.Name()} is dead! Choose someone who is alive!");
                    Console.WriteLine("Please Enter (1), (2), or (3) to select your attacking character. Press (4) to view your stats, and (5) to Heal an Ally");
                    Attacker = null;
             
                } 
                
                else
                {
                    Console.WriteLine($"{Attacker.Name()} will attack!");
                    Thread.Sleep(1000);
                }
           
            }

 
    

            //print instructions for choosing a rival.
            Console.WriteLine($"Select which enemy to attack!\n(1) To Attack {enemyArray[0].Name()}\n(2) To Attack {enemyArray[1].Name()}\n(3) To Attack {enemyArray[2].Name()}\n(4) To see the Enemies Current Stats.");

            //loop until a defender is choosen
            while (Defender == null)
            {
                // use 1-3 to select player party member that is the attacker
                ConsoleKeyInfo k = Console.ReadKey();
                if (k.KeyChar == '1')
                {
                    Defender = enemyArray[0];
                    Console.WriteLine($"\nYou will attack {Defender.Name()}");

                } else if(k.KeyChar == '2') {
                    Defender = enemyArray[1];
                    Console.WriteLine($"\nYou will attack {Defender.Name()}");
                }
                else if (k.KeyChar == '3')
                {
                    Defender = enemyArray[2];
                    Console.WriteLine($"\nYou will attack {Defender.Name()}");
                } else if (k.KeyChar == '4')
                {
                    playerTurn = false;
                    PrintParties();
                    playerTurn = true;
                }
                { }
                //add a new line aft er the user input
                Console.WriteLine();

                // Data Validation: make sure the key typed is a valid key
                if (k.KeyChar < '1' || k.KeyChar > '3')
                {
                    // repeat instructions
                    Console.WriteLine("Select an enemy to attack by pressing either 1, 2, or 3.\n");
                    // loop again
                    continue;
                }
                else // convert from key input (1-3) to array element space (0-2)
                    curSelection = int.Parse(k.KeyChar.ToString()) - 1; //minus one to use as index
                //check to make sure the selected character is alive HP > 0
                    //print the defenders name
                    //assign the selected character as the defender
                if (Defender.GetHP() <= 0)
                {
                    //print instructions again        
                    Console.WriteLine($"{Defender.Name()} is already dead! Pick another enemy!");
                    Console.WriteLine("Select an enemy to attack by pressing either 1, 2, or 3.\n");
                    Defender = null;
                } else
                {
                    Console.WriteLine($"{Attacker.Name()} attacks {Defender.Name()}!");
                    Thread.Sleep(2000);
                 

                }
            }

            //damage the defender by the attacker's Strength value
            Defender.ApplyDamage(Attacker.GetStrength());
          


            //change color for rival team
            Console.BackgroundColor = Attacker.GetTeamColor();
            //print the new rival's health
            Console.WriteLine($"{Defender.Name()} was hit by {Attacker.Name()}! {Defender.Name()} now only has {Defender.GetHP()} HP!");
       

            EndTurn();

            //change color back for normal
            Console.BackgroundColor = ConsoleColor.Black;
            //pause for 2 seconds
            Thread.Sleep(2000);

            //reset attacker/defender for next attack
            Attacker = null;
            Defender = null;
        }
 void HealAlly()
        {
            float healing = 3;
          
    
                while (Healee == null)
                {
                    Console.WriteLine("\nWhich Ally Do You Want To Heal?");
                    Console.WriteLine($"(1) for {playerArray[0].Name()}\n(2) for {playerArray[1].Name()}\n(3) for {playerArray[2].Name()}");
                    // use 1-3 to select player party member that is being healed
                    ConsoleKeyInfo k = Console.ReadKey();
                    if (k.KeyChar == '1')
                    {
                        Healee = playerArray[0];
                        Console.WriteLine($"\nYou will heal {Healee.Name()}");
                        Console.WriteLine("Healing...");


                    }
                    else if (k.KeyChar == '2')
                    {
                        Healee = playerArray[1];
                        Console.WriteLine($"\nYou will heal {Healee.Name()}");
                        Console.WriteLine("Healing...");

                    }
                    else if (k.KeyChar == '3')
                    {
                        Healee = playerArray[2];
                        Console.WriteLine($"\nYou will heal {Healee.Name()}");
                        Thread.Sleep(1000);
                        Console.WriteLine("Healing...");


                    }
                    else if (k.KeyChar > 3 || k.KeyChar < 1)
                    {
                        Console.WriteLine("Choose which character you want to heal!");
                        continue;
                    }

                    if (Healee.GetHP() >= 12)
                    {
                        Thread.Sleep(1000);
                        Console.WriteLine($"{Healee.Name()} has full health! You can't heal them!");
                    EndTurn();

                }
                    else if (Healee.GetHP() <= 0)
                    {
                        Thread.Sleep(1000);
                        Console.WriteLine($"{Healee.Name()} is dead! You can't heal them!");
                    EndTurn();
                   
                }
                    else
                    {
                        Healee.ApplyHealing(healing);
                        Thread.Sleep(2000);
                        Console.WriteLine($"{Healee.Name()} has been healed, and now has {Healee.GetHP()} HP!");
                    EndTurn();
                 
                }
  bool EndTurn()
        {
            //switch turns for next loop
            playerTurn = !playerTurn;

            // loop through players to see if they're alive and store in a variable counting if they're alive or not
    

            bool playersAlive = true;

            for (int i = 0; i < playerArray.Length; i++)
            {
                if (playerArray[0].GetHP() <= 0 && playerArray[1].GetHP() <= 0 && playerArray[2].GetHP() <= 0)
                {
                    playersAlive = false;
                }

            }

            // same for rivals
            bool rivalsAlive = true;

            for (int i = 0; i < enemyArray.Length; i++)
            {
                if (enemyArray[0].GetHP() <= 0 && enemyArray[1].GetHP() <= 0 && enemyArray[2].GetHP() <= 0)
                {
                    rivalsAlive = false;
                }

            }
            // if both have things alive start the next round, pause the game, and return true to continue playing
            if (playersAlive && rivalsAlive)
            {
                Console.WriteLine("Next Round Starts in 5 seconds");
                Thread.Sleep(5000);
             
                return true;
            } // if only the players have members alive you win
            else if (playersAlive)
            {
                //clear screen for results
                Console.Clear();
                //print you've won and parties
                Console.WriteLine("Congrats you win! Final Standings:");
                playerTurn = false;
                PrintParties();
                playerTurn = true;
                PrintParties();
                Thread.Sleep(5000);
                Console.WriteLine("Thanks For Playing!");
                Console.WriteLine("Press Any Key to Play Again");
                Console.ReadKey();
                Console.Clear();
                Init();
                return false;
             
            } // only rival members are alive
            else
            {
                //clear screen for results
                Console.Clear();
                //Print you've lost and parties
                Console.WriteLine("You Lose :( Final Standings:");
                playerTurn = false;
                PrintParties();
                playerTurn = true;
                PrintParties();
                Thread.Sleep(5000);
                Console.WriteLine("Thanks For Playing!");
                Console.WriteLine("Press Any Key to Play Again");
                Console.ReadKey();
                Console.Clear();
                Init();
                return false;
            }
        }
 void PlayerTurn()
 {
    // ...
    while (Attacker == null)
    {
         // ...
         if (k.KeyChar == '5') {
                HealAlly();
                break;
            }
    }

    // ...code that depends on Attacker...
 }