简体   繁体   English

游戏不以java剪刀石头布游戏结尾

[英]game not ending in java rock paper scissors game

Edit: I have fixed my program so that it works, and I added the bracket. 编辑:我已经修复了程序,使其可以正常工作,并且添加了括号。 However, I ran into another error. 但是,我遇到了另一个错误。 My code does not end when the user wins the game. 当用户赢得游戏时,我的代码不会结束。 I want it to end, so please help me. 我希望它结束​​,所以请帮助我。 Here is my code below: 这是我的代码如下:

public void rockPaperScissors ()
{
System.out.println ("First one to 3 Points wins the battle!");
char again = 'y';
while (again == 'y'){
int rPoint = 0;
int uPoint = 0;
int game = 1;
System.out.println ("\nLET THE BATTLE BEGIN!");

while (uPoint < 3 || rPoint < 3) {
 String user = uChoice ();
 System.out.println (user + ", I choose you!");
 String rival = rChoice ();
 System.out.println ("Your rival has chosen " + rival + "!");
 String win = winner (rival, user);

 if (win == "r")
 {
  rPoint++;
  System.out.println ("\nYour rival has won the match.");
 }

 else if (win == "u")
 {
  uPoint++;
  System.out.println ("\nYou have won the match!");
 }

 else 
  System.out.println ("\nBoth Pokemon have fainted! It's a tie!");

 System.out.println ("Points: You " + uPoint + " Rival: " + rPoint);
 if (uPoint == 3) {
  System.out.println ("Congrats! You have beaten your rival!");
  break;
  }
 else if (rPoint == 3) {
  System.out.println ("Too bad! Your rival has beaten you!");
  again = IBIO.inputChar ("\nWant to try again? (y/n) ");
  uPoint = 0;
  rPoint = 0;
  }
 }
 }
 }


public boolean isValid (String c)
{
 if (c.equals ("Bulbasaur") || c.equals ("BULBASAUR") || c.equals ("bulbasaur") || c.equals ("B") || c.equals ("b") || c.equals ("Charmander") || c.equals ("CHARMANDER") || c.equals ("charmander") || c.equals ("c") || c.equals ("C") || c.equals ("CHARMANDER") || c.equals ("SQUIRTLE") || c.equals ("Squirtle") || c.equals ("squirtle") || c.equals ("s") || c.equals ("S"))
 return true;
 else
 return false;
}

public String uChoice ()
{
printSlow ("Pokemon: Bulbasaur, Charmander, Squirtle");
String c = IBIO.inputString ("Which Pokemon do you choose? ");

while (!isValid (c))
{
 System.out.println ("You don't have that Pokemon. Try again.");
 c = IBIO.inputString ("Which Pokemon do you choose? ");
}

if (c.equals ("Bulbasaur") || c.equals ("BULBASAUR") || c.equals ("bulbasaur") || c.equals ("b") || c.equals ("B"))
 return "Bulbasaur";
else if (c.equals ("Charmander") || c.equals ("CHARMANDER") || c.equals ("charmander") || c.equals ("c") || c.equals ("C"))
 return "Charmander";
else
 return "Squirtle";
}

public String rChoice ()
{
 int num = (int)(Math.random ()*3) + 1;

 if (num == 1)
  return "Bulbasaur";

 else if (num == 2)
  return "Charmander";

 else
  return "Squirtle";
}

public String winner (String rival, String user)
{
 if ((rival == "Bulbasaur" && user == "Squirtle") || (rival == "Charmander" && user == "Bulbasaur") || (rival == "Squirtle" && user == "Charmander"))
        return "r";
 else if ((user == "Bulbasaur" && rival == "Squirtle") || (user == "Charmander" && rival == "Bulbasaur") || (user == "Squirtle" && rival == "Charmander")) 
        return "u";
 else 
        return "b";
}
public void rockPaperScissors ()
{...
while (again == 'y')
{
...
} 
//HERE    
public boolean isValid (String c)
{...}

You are missing a } at my // comment. 您在我的//注释中缺少}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM