Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 刽子手统计错误_Java - Fatal编程技术网

Java 刽子手统计错误

Java 刽子手统计错误,java,Java,我的代码没有显示我玩过的赢、输和游戏的数量 上个月我一直在努力修复它,但我哪儿也不去 import java.util.Random; import java.util.Scanner; public class HangmanP2 { public static void main(String[] args) { Scanner Input = new Scanner(System.in); String first, reverse = "

我的代码没有显示我玩过的赢、输和游戏的数量

上个月我一直在努力修复它,但我哪儿也不去

    import java.util.Random;
     import java.util.Scanner;

   public class HangmanP2 {


public static void main(String[] args) {

  Scanner Input = new Scanner(System.in);
       String first, reverse = "";
        String second, reverse2 = "";
        Scanner in = new Scanner(System.in);

   System.out.println("Welcome to Hangman!");
   System.out.println("Enter your first name.");
   first = in.nextLine();
   System.out.println("Enter your last name to play.");
   second = in.nextLine();

  int length = first.length();
  int length2 = second.length();
  for ( int i = length - 1 ; i >= 0 ; i-- )
     reverse = reverse + first.charAt(i);
     reverse = reverse.substring(0,1).toUpperCase() + reverse.substring(1).toLowerCase();
 for ( int i = length2 - 1 ; i >= 0 ; i-- )
     reverse2 = reverse2 + second.charAt(i);
     reverse2 = reverse2.substring(0,1).toUpperCase() + reverse2.substring(1).toLowerCase();

  System.out.println("Your name entered in reverse is: "+reverse+" "+reverse2);

   startGame(reverse,reverse2);
    }
    public static void startGame(String reverse,String reverse2){


            Random rnd = new Random ();
    Scanner user = new Scanner (System.in);
            String guess = "";
    String message = "";
    int count = 1;
    boolean quit = false;
    String fullWord = "";
    int wins=0;
            int loss=0;
            int numberOfGames=0;
    int guessC = 5;
    String usedLetters ="";
    String remainingLetters ="";
    String letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    int hinter = 0;
    int z  = rnd.nextInt(10);
    int k  = rnd.nextInt(2);

    String words[][] = {{"earth","stars","light",
    "world","about","again",
    "stars","light","music",
    "happy","water","amber",
    "apple","piano","green",
    "mouth","suger","stone",
    "japan","china","after","lemon",
    "grand",
    "lives","twice","print"},{"smile",
    "puppy","latin","vegan","phone","april",
    "south","house","hangs","woman",
    "power","today","india","night","candy",
    "forum","birth","other","chris","irish",
    "paste","queen","grace","crazy","plant",
    "knife","spike","darth","vader","eagle",
    "egypt","range","fists","fight","glory",
    "March","smart","magic","codes","rolls",
    "match","honor","glass","board","teams",
    "bully","zebra","under","mango","brain",
    "dirty","eight","zeros","train","cycle",
    "break","necks","terms","slide","large"},{"stake","guess","wrong","anime","stick","outer","input"},{ "thing","write","white","black"}};




    //Prints info of the game and topic that as been selected
    System.out.println("Welcome to Hangman"+" "+reverse+" "+reverse2);


    //This prints the '-' and spaces for the first run of the game only
    for(int index = 0; index < words[z][k].length();index++)
    {
        Character variableInt = words[z][k].charAt(index);
        if(variableInt != ' ')
        {
            message += "-";
        }
        else
        {
            message += " ";
        }
    }
    //Nothing will change, this prints information to the user about his current status in-game.
    System.out.println("Secret word: \t\t" +  message);
    System.out.println("Letters Remaining: " + letters);
    System.out.println("Letters Used: ");
    System.out.println("Guesses Remaining: " + guessC);
    //The loop that will continuously run the game, until the user fails or does not want to play again.
    do{
        //The following variable's make sure there is not stacking from previous data when the loop runs again.
        remainingLetters = "";
        count = 0;
            //Ask the user for a letter to guess

        System.out.println("\nEnter a letter to guess the word): ");
        guess = user.nextLine();
        //The following for-loop converts ASCII table [A-Z] to actually characters and if the player used a letter it will not show up or add to the string each run of the do-loop.
        for(int x = 65; x < 91;x++){
            Character current = new Character ((char)x);
            String current2 =  current.toString();
            if(!usedLetters.contains(current2)){
                remainingLetters += current;
            }       
        }
        //Converts the user's first character to a string which is converted into another character and again converted into a String (Seem's useless) but i used it this way cause i was getting an error.
        Character convert = new Character (guess.charAt(0));
        Character conv =  new Character (convert);
        String converted = convert.toString();
        //The letters the player uses will be added to a string, if it has not already been added and only if it is a letter.
        if(!usedLetters.contains(converted) && conv.isLetter(convert)){
        usedLetters+=guess.charAt(0);
        }
        //Inside this for-loop it turns our word into a String and the user's first character into a string.

        for(int index = 0; index < words[z][k].length();index++){
    //This is a helper 
            count++;
            //Conversion of variables
            Character current2 = new Character ( words[z][k].charAt(index));
            String current = current2.toString();
            Character current3 = new Character (guess.charAt(0));
            String current4 = current3.toString();
            String current5 = current4.toUpperCase();
            String current6 = words[z][k].toUpperCase();
            //If the players gets a letter correct, do the following.
            if(current4.equalsIgnoreCase(current))
            {
                //Add's on to the previous string from where the player got it correct and change it to the correct letter instead of a '-'.
                message = message.substring(0,index) + guess + message.substring(index + 1);
            }
            //If the player gets it wrong and the helper variable is equal to 1 (so that it does not follow the loop of the for-loop and it is not one of the special characters in the game('!' or '?').
            if(!current6.contains(current5) && count == 1 && guess.charAt(0) != '?' && guess.charAt(0) != '!'){
                guessC--;
            }
        }
//Prints information to the user of their current topic



        //The secret word the player has to guess
        System.out.println("Secret word: \t\t" + message.toUpperCase());
            //The letters in the alphabet that have not been used yet
        System.out.print("\nLetters remaining: ");
        System.out.print(remainingLetters.toUpperCase() + "\n\n");
        //This will print a message to the user, telling them information on using a hint or the hint itself.

        //Letters the user has used since the game session has been running
        System.out.print("\nLetters Used: ");
        System.out.print(usedLetters.toUpperCase() + "\n");
        //The amount of guesses the player has left
        System.out.println("\nGuesses Remaining: " +guessC );
        //If the player enters a '?' it will do the following.
        if(guess.charAt(0) == '?'){
            if(hinter <2){
                //Displays what is in the array and information about the delay, while losing guesses.
            hinter++;
            System.out.print("\nHint will appear after next guess! \n");
            guessC -=2;
            }
        }
        //If the user guesses the word correct
        if(message.equalsIgnoreCase(words[z][k])){
            System.out.println("YOU ARE CORRECT! " +  words[z][k] + " is correct!");
            wins++;
                            quit = true;
        }
        //If the user ask to guess the entire word it is stored in a separate variable and make quit equal to true.
        if(guess.charAt(0) == '!')
        { 
            System.out.print("\nEnter the secret word: ");
            fullWord = user.nextLine();
            //if the user guesses the word correct then it will tell the user they are correct and make quit equal to true.
            if(fullWord.equalsIgnoreCase(words[z][k])){
                System.out.println("YOU ARE CORRECT! " +  words[z][k] + " is correct!");
                wins++;
                                    quit = true;

            }
            //If the user does not get it right it will tell the user they are wrong and make quit equal to true.
            else{
                System.out.println("YOU ARE INCORRECT! the word is: " +  words[z][k] + " ");
                loss++;
                                    quit = true;
            }
        }
        //If the guesses counter equal 0 then it will tell them that they have lost and make quit equal to true.
        if(guessC == 0){
            System.out.println("GAME OVER! The secret word was [ " + words[z][k] + " ]!");
            loss++;
                            quit = true;
        }
        //This is what happens when quit eventually becomes true, the user is asked if they would like to play again.
        if(quit == true){
            System.out.println("\nWould you like to play again (Y or quit)? ");
                            System.out.println("\nOr type [stats] to check your work");
            guess = user.nextLine();
        //If they do want to play again, they will need to enter Y and if they do it will give them another word to guess and resets there information so that there will be no overlap.    
        if(guess.equalsIgnoreCase("Y")){
            quit = false;

                            z  = rnd.nextInt(10);
             k  = rnd.nextInt(2);
             guess = " ";
            guessC = 6;
             message = "";
             usedLetters = "";
             hinter = 0;



                for(int index = 0; index < words[z][k].length();index++)
                {
                    Character variableInt = words[z][k].charAt(index);
                    if(variableInt != ' ')
                    {
                        message += "-";
                    }
                    else
                    {
                        message += " ";
                    }
                }
                System.out.println("Secret word: \t\t" +  message);
                System.out.println("Letters Remaining: " + letters);

                System.out.println("Letters Used: ");
                System.out.println("Guesses Remaining: " + guessC);

                    }

        if(guess.equals("stats")){  
         printGameStats(wins,loss,numberOfGames);


                    }
                    else{
            //If the user enters 'N' then they will be told the following and the scanner will be closed.
            System.out.println("THANK YOU FOR PLAYING HAVE A GOOD DAY!");
            user.close();
        }
        }
    //end of the while loop which will only stop if quit equals true.
    }while(quit != true );

            }           

private static void printGameStats(int wins,int loss,int numberOfGames) {





    // Line
    System.out.print("+");
    printDashes(37);
    System.out.println("+");

    // Print titles
    System.out.printf("|  %6s  |  %6s  |  %12s  |\n",
            "WINS", "LOSSES", "GAMES PLAYED");

    // Line
    System.out.print("|");
    printDashes(10);
    System.out.print("+");
    printDashes(10);
    System.out.print("+");
    printDashes(10);
    System.out.print("+");
    printDashes(16);
    System.out.print("+");
    printDashes(18);
    System.out.println("|");

    // Print values
    System.out.printf("|  %6d  |  %6d  | %12d  |\n",
            wins, loss, numberOfGames);

    // Line
    System.out.print("+");
    printDashes(37);
    System.out.println("+");
}


private static void printDashes(int numberOfDashes) {
    for (int i = 0; i < numberOfDashes; i++) {
        System.out.print("-");
    }
}
}
import java.util.Random;
导入java.util.Scanner;
公共级刽子手2{
公共静态void main(字符串[]args){
扫描仪输入=新扫描仪(System.in);
第一个字符串,反向=”;
第二个字符串,reverse2=“”;
扫描仪输入=新扫描仪(系统输入);
System.out.println(“欢迎来到刽子手!”);
System.out.println(“输入您的名字”);
first=in.nextLine();
System.out.println(“输入要播放的姓氏”);
second=in.nextLine();
int length=first.length();
int length2=第二个.length();
对于(int i=length-1;i>=0;i--)
反向=反向+第一个字符(i);
reverse=reverse.substring(0,1).toUpperCase()+reverse.substring(1.toLowerCase();
对于(int i=length2-1;i>=0;i--)
reverse2=reverse2+秒字符(i);
reverse2=reverse2.substring(0,1).toUpperCase()+reverse2.substring(1.toLowerCase();
System.out.println(“您在背面输入的名称是:“+reverse+”+reverse2”);
开始名称(反向,反向2);
}
公共静态void startName(字符串反转,字符串反转2){
Random rnd=新的Random();
扫描仪用户=新扫描仪(System.in);
字符串猜测=”;
字符串消息=”;
整数计数=1;
布尔退出=假;
字符串fullWord=“”;
int=0;
整数损失=0;
int numberOfGames=0;
int=c=5;
字符串usedLetters=“”;
字符串remainingleters=“”;
字符串字母=“abcdefghijklmnopqrstuvxyz”;
int-hinter=0;
int z=rnd.nextInt(10);
int k=rnd.nextInt(2);
字符串字[][]={{{“地球”、“星星”、“光”,
“世界”,“关于”,“再次”,
“星星”、“光”、“音乐”,
“快乐”、“水”、“琥珀”,
“苹果”、“钢琴”、“绿色”,
“嘴”,“糖”,“石头”,
“日本”、“中国”、“柠檬”之后,
“大”,
“生活”,“两次”,“打印”},{“微笑”,
“小狗”、“拉丁语”、“素食主义者”、“电话”、“四月”,
“南方”、“房子”、“绞刑”、“女人”,
“力量”、“今天”、“印度”、“夜晚”、“糖果”,
“论坛”、“出生”、“其他”、“克里斯”、“爱尔兰”,
“粘贴”、“女王”、“优雅”、“疯狂”、“植物”,
“刀”、“刺”、“达斯”、“维德”、“鹰”,
“埃及”、“射程”、“拳头”、“战斗”、“荣耀”,
“三月”、“聪明”、“魔法”、“密码”、“掷骰子”,
“比赛”、“荣誉”、“玻璃”、“棋盘”、“团队”,
“欺负”、“斑马”、“下”、“芒果”、“大脑”,
“脏”、“八”、“零”、“火车”、“循环”,
“折断”、“脖子”、“术语”、“幻灯片”、“大”}、{“木桩”、“猜测”、“错误”、“动画”、“木棍”、“外部”、“输入”}、{“东西”、“书写”、“白色”、“黑色”};
//打印所选游戏和主题的信息
System.out.println(“欢迎来到刽子手”+“”+reverse+“”+reverse2);
//这只打印第一次运行游戏时的“-”和空格
对于(int index=0;index