Results 1 to 6 of 6
  1. #1
    WolfDesigns is offline Member
    Join Date
    Jan 2017
    Posts
    5
    Rep Power
    0

    Question Need help with java

    This section of my code doesn't function and I don't have a clue why... \

    I can't get the hp and the menu doesn't show

    Java Code:
    if (rand.nextInt(100) > hpDrop ){ //randomizes hp drop
                     mxHPotions++;
                     System.out.println(" # The " + enemy + " has dropped a health potion! #");
                     System.out.println(" # You have" + mxHPotions + " potion(s)! #");
                 
                     System.out.println("---------------------------------------------------");
                     int input1 = in.nextInt(); //After Enemy Death menu
                     System.out.println("What now?");
                     System.out.println("1. Continue this maze of death untill you die...");
                     System.out.println("2. Realize that you have better things to do and quit!");
                     switch (input1){
                         case 1: System.out.println("So you choose death, eh... good luck on massacre of mystical creatures."); break;
                         case 2: System.out.println("So you choose life, eh... good luck on actual things you have to do."); break;
    Last edited by WolfDesigns; 01-15-2017 at 05:02 AM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Need help with java

    Can you post the contents of the command prompt window from when you execute the code to show what you are asking about?
    Add some comments that describe what the problem is and show the desired output.

    Java Code:
    if (rand.nextInt(100) > hpDrop )
    What is the value of hpDrop when that statement is executed?
    Check the API doc for the nextInt() method to see the max value it returns.

    NOTE: The code's formatting needs some work. Logically nested statements should be indented.
    There should not be any }s one above the other in the same column. The } should be in the same column as the start of the line with the matching {
    Last edited by Norm; 01-15-2017 at 04:03 AM.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    WolfDesigns is offline Member
    Join Date
    Jan 2017
    Posts
    5
    Rep Power
    0

    Default Re: Need help with java

    There's nothing wrong with the code while executing, its more of that it skips those parts.

    After the enemy dies the code prints out that it died only and does not tell the player that they've gained a new potion from it and doesn't show the after death menu which asks if the player wants to continue or not.
    It could be found in line 42 from the full code

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Need help with java

    You skipped over this part:
    What is the value of hpDrop when that statement is executed?
    Check the API doc for the nextInt() method to see the max value it returns.
    the code prints out that it died only and does not tell the player that they've gained a new potion from it and doesn't show the after death menu which asks if the player wants to continue or not.
    Please copy the console contents that shows that and add some annotated comments explaining what is wrong and show what you expect the output to be.
    Last edited by Norm; 01-15-2017 at 04:10 AM.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    WolfDesigns is offline Member
    Join Date
    Jan 2017
    Posts
    5
    Rep Power
    0

    Default Re: Need help with java

    [QUOTE=Norm;416147]Can you post the contents of the command prompt window from when you execute the code to show what you are asking about?
    Add some comments that describe what the problem is and show the desired output.

    Java Code:
    if (rand.nextInt(100) > hpDrop )
    Thanks I realized that I confused the hpDrop which is the percentage that makes it so the player can't get a drop and not the percentage of a drop.

    now
    Java Code:
    int input1 = in.nextInt(); //After Enemy Death menu; I want it to print this part out and have the "player" can choose what to do next after killing the enemy                
                     System.out.println("What now?");
                     System.out.println("1. Continue this maze of death untill you die...");
                     System.out.println("2. Realize that you have better things to do and quit!");
                     switch (input1){
                         case 1: System.out.println("So you choose death, eh... good luck on massacre of mystical creatures."); break;
                         case 2: System.out.println("So you choose life, eh... good luck on actual things you have to do.");  break;
                         default:
                             System.out.println("---------------------------------------------------");
                             System.out.println("Invalid Command");
                             System.out.println("---------------------------------------------------");
                             break;

  6. #6
    WolfDesigns is offline Member
    Join Date
    Jan 2017
    Posts
    5
    Rep Power
    0

    Default Re: Need help with java

    I've figured it out, Thanks to you. :D

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •