有人可以用我的冒险代码帮助我吗?

时间:2014-11-03 03:11:36

标签: java netbeans adventure

问题:如何在第三个选项之后将程序修复到可以继续的位置?

我正在做一个简短的冒险游戏,似乎有一些问题。我是全新的,所以任何建议都很棒。

主要问题是当玩家点击“是”或

时为“否”
<i>Go into the abandon house?</i>
<i>1.I don't see why not.</i>
<i>2.I rather stay outside,</i>(user_name)<i> snickers.</i>

玩家做出选择后程序结束。该程序应该在玩家选择之后继续进行战斗,但是没有!

这是我的代码:

import java.util.Scanner;

public class NewAdventureProject {

public static void main(String[] args)
throws java.io.IOException{
      int MonsterHealth;
      int PlayerHealth ;
      int GhostHealth;
      char input='a';//The attack key for battles

        PlayerHealth=100;//Health of the player 
        MonsterHealth=100;//Health of the Monster
        GhostHealth=120;//Health of the ghost



   Scanner user_input=new Scanner(System.in);
   String user_name;
  System.out.println("Enter Your name or prefered nick name:");//player name option
  user_name=user_input.next();

  System.out.println(user_name+" you stepped into the light.");
  System.out.println("You see a house");
  System.out.println("It looks abandon. Do you want to investigate it?");
  System.out.println("1.Yes.");
  System.out.println("2.No.");
  Scanner scan = new Scanner(System.in);//Declares new scanner
  int a = scan.nextInt();//Helps me navigate around long if and while statements

    switch(a){
        case 1://outcome one
            System.out.println("As you get closer to the abandon house, you "
                    + "hear a random roar.");
            break;
        case 2://outcome two
            System.out.println("The clouds black out the sun.\nYour "
                    + "face is sprinkled with water"+". It's raining now.\nY"
                    + "ou shiver.");
            System.out.println("You hear a faint scream from the abandon "
                    + "house. Do you want to investigate?");
            break;
           }


  System.out.println("Go into the abandon house?");

     System.out.println("1.I don't see why not.");
     System.out.println("2.I rather stay outside,"+user_name+" snickers.");

     Scanner sc = new Scanner(System.in);//New scanner
     int b = sc.nextInt();//New int scanner 
     switch(b){

         case 1://if play goes into the abandon house 


       for(MonsterHealth=100; MonsterHealth<0;){//monster's health loop
          if(PlayerHealth>0){

      System.out.println("The house is dark and quiet.");
      System.out.println("A roar gets closer to you.");
      System.out.println("You get knocked back!\nYou're hurt!");
      PlayerHealth=PlayerHealth-6;
      System.out.println(user_name+"'s health is now"+PlayerHealth);
      System.out.println("You were attacked by a Green Monster!"+user_name
      +" take this!\n"+user_name+" obtained a shiny sword!");
      System.out.println("Press a to attack the Green Monster!");
        if(input=='a'){
            System.out.println("The Green Monster flinches.\nYou did 10 dam"
                    + "age to the monster!");
            MonsterHealth=MonsterHealth-15;
            System.out.println("The Green Monster lunges at you!\nYou lost"
                    + "5 health points!");
            System.out.println("your health is now"+PlayerHealth+"!");
        }else{
            PlayerHealth=PlayerHealth-5;
            System.out.println("The Green Monster lunges at you!\nYou lost"
                    + "5 health points!");
            input=(char)System.in.read();
        }
  }else{

  }
      if(MonsterHealth==0){
          System.out.println("The Green Monster makes an ear piercing growl."
                  + "The Green monster falls!\nYou win!");

      }else if(PlayerHealth==0){//if the player looses all of their health
          System.out.println("You see the light again"+user_name+"you have "
                  + "fallen.\nYou're dead.\nGameover");
            break;
      }
      }
     case 2://second option for switch
         for(GhostHealth=120; GhostHealth<0;){
          System.out.println("You get chills.\n The sky gets ominously dark.");
          System.out.println("You hear a screeching howl.\n You're pushed onto"
                  + " the ground!\nYou're hurt");
          PlayerHealth=PlayerHealth-5;

          System.out.println(user_name+"'s health is now"+PlayerHealth);
      System.out.println("You were attacked by a Ghost!");
      System.out.println("Press a ,followed by enter ,to attack the Ghost!");
        if(input=='a'){
            System.out.println("The Ghost howls!.\nYou did 15 damage to the"
                    + " Ghost!");
           GhostHealth=GhostHealth-15;
            System.out.println("The Ghost scratches you!\nYou lost"
                    + "10 health points!");
            PlayerHealth=PlayerHealth-10;
            System.out.println("your health is now"+PlayerHealth+"!");
        }else{
            PlayerHealth=PlayerHealth-5;
            System.out.println("The Ghost scratches you!\nYou lost"
                    + "10 health points!");
            input=(char)System.in.read();
        }

  }
      if(GhostHealth==0){
          System.out.println("The Ghost makes an ear piercing squeal."
                  + "The Ghost dissolves!The skies are now clear"
                  + "\nYou win!");

      }else if(PlayerHealth==0){
          System.out.println("You see the light again"+user_name+"you have "
                  + "fallen.\nYou're dead.\nGameover");


      }    
      }
      }
     }

1 个答案:

答案 0 :(得分:0)

通过这个spaghetticode很难看到,但是在第二个开关的情况下缺少了断裂。