Advertisement
Guest User

Java game Colin

a guest
Dec 3rd, 2014
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 30.29 KB | None | 0 0
  1.    
  2.  
  3.     import javax.swing.*;
  4.  
  5.  
  6.      
  7.      
  8.     public class lel {
  9.            
  10.             static int health = 100;
  11.             static int gold = 0;
  12.             static int exp = 0;
  13.             static int playerChosenDirection;
  14.             static int battleChoice;
  15.             static int monsterAt;
  16.             static int chestAt;
  17.             static int enemyHealth;
  18.             static int potion = 3;
  19.             static int amount;
  20.             static char userInput = 0;
  21.             static String uncheckedInput;
  22.             static boolean die = false;
  23.             static boolean chest;
  24.             static int chestLoot;
  25.             static int chestGold;
  26.             static int chestPotion;
  27.             static int chestTrap;
  28.             static int chestNothing;
  29.             static int level = 1;
  30.             static int amountNorth = 0;
  31.             static int amountEast = 0;
  32.             static int amountStep = 0;
  33.             static boolean leave;
  34.             static int shopAt;
  35.  
  36.             public static void main(String[] args) {
  37.                    
  38.      
  39.                     JOptionPane.showMessageDialog(null, "WELCOME.");
  40.                     JOptionPane.showMessageDialog(null, "You are in a dungeon and slowly bleeding out every step. You have 3 health potions.");
  41.                     JOptionPane.showMessageDialog(null, "You have the choice of going (N)orth, (E)ast, (S)outh, (W)est or (P)otion");
  42.                     JOptionPane.showMessageDialog(null, "Good luck! Monsters have a chance of spawning and a chance of dropping a health potion and give exp and gold. You may also find a chest with loot or a shop.");
  43.                
  44.                    while(health > 0){
  45.                                    
  46.      
  47.                             do{
  48.                                    
  49.                                     uncheckedInput = (JOptionPane.showInputDialog("Which way do you go, (N) (E) (S) (W) or (P)? " + "You have "+ health + " health."));
  50.                                     if(!uncheckedInput.equals("")) {
  51.                                             userInput = Character.toUpperCase(uncheckedInput.charAt(0));
  52.                                     }
  53.                             }
  54.             while(userInput != 'N' && userInput != 'S'&& userInput != 'E'&& userInput != 'W' && userInput != 'P');
  55.                             health--;
  56.                     System.out.println("You have "+health+ " left.");
  57.            
  58.                     playerChosenDirection = Move (userInput);
  59.                     monsterAt = (int)Math.floor(Math.random() * 4); //generates the monster at one of the random directions therefore 25% chance at encountering it.
  60.            
  61.                     if (playerChosenDirection == monsterAt) {
  62.                             //battle
  63.                          System.out.println("Battle!");
  64.                             JOptionPane.showMessageDialog(null, "You have encountered an enemy!");
  65.                            
  66.                             //JOptionPane.showMessageDialog(null, "It has " +enemyHealth+ " health."); // again, i need to make enemyhealth usable from multiple parts of code
  67.                             enemyHealth = (int)((Math.random()*10) + 10); //generate monster spawn
  68.                             battle(); //start battle
  69.                     }
  70.                     else
  71.                     {
  72.                    
  73.                            // WOW THERE WAS A LINE HERE,  playerChosenDirection = Move (userInput); THAT I DIDNT NEED THAT WAS THE DOUBLE PRINTING BUG WOWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
  74.                            
  75.                            chestAt = (int)Math.floor(Math.random() * 8); //generates the chest at one of the random directions therefore 20% chance at encountering it.
  76.                    
  77.                             if (playerChosenDirection == chestAt) {
  78.                             System.out.println("You found a chest.");
  79.                             JOptionPane.showMessageDialog(null, "You have found a chest!");                            
  80.                             JOptionPane.showMessageDialog(null, "It looks like it could be trapped, do you want to (o)pen it or (l)eave it?");
  81.                             chest();
  82.                             }
  83.                             else if(amountStep>25){
  84.                                 int exit = (int)Math.floor(Math.random() * 16); //exit 1/16 chance after 25 moves
  85.                                 if (playerChosenDirection == exit)        {  
  86.                                 System.out.println("You have found an exit!"); 
  87.                                 JOptionPane.showMessageDialog(null, "You have found an exit!");
  88.                                 JOptionPane.showMessageDialog(null, "Do you want to leave now?");
  89.                                 leave();
  90.                             }
  91.                             else if(gold>10)
  92.                                 {
  93.                             shopAt  = (int)Math.floor(Math.random() * 10);
  94.                             if (playerChosenDirection == shopAt) {
  95.                                 System.out.println("You found a shop.");
  96.                                 JOptionPane.showMessageDialog(null, "You have found a shop!");                            
  97.                                 JOptionPane.showMessageDialog(null, "Do you buy a potion for 10 gold?");
  98.                             shop();
  99.                             }
  100.                             else{
  101.                                
  102.                             }
  103.                             }
  104.                             }
  105.                             }
  106.                             }
  107.                             }
  108.  
  109.             public static void chest(){
  110.                    
  111.                            
  112.                 uncheckedInput = JOptionPane.showInputDialog("What do you do?");
  113.                 if (!uncheckedInput.equals("")) {
  114.                         userInput = Character.toUpperCase(uncheckedInput.charAt(0));
  115.                 } else{
  116.                
  117.                 }
  118.                
  119.                 switch(userInput) {
  120.                         case 'O':
  121.                                 chest = true;
  122.                                 break;
  123.                         case 'L':
  124.                                 chest = false;
  125.                                 break;
  126.                         default:
  127.                             //chest(); fixed by removing
  128.                                 break;
  129.                                 }
  130.                
  131.                     if(chest == false){
  132.                    
  133.                     }
  134.                
  135.                     else if(chest == true){
  136.                            
  137.                    
  138.                     int loot = (int) (Math.random() * 4);
  139.                            
  140.                             switch(loot) {                      
  141.                          
  142.                             case 1:
  143.                             if(loot == 0){
  144.                                     gold +=  (int)(Math.random()*6 + 5);
  145.                                     System.out.println("You found some gold! You now have " + gold + " gold.");
  146.                                     JOptionPane.showMessageDialog(null, "You found some gold! You now have " + gold + " gold.");
  147.                                    
  148.                             break;
  149.                             }
  150.                             case 2:
  151.                             if (loot == 1){
  152.                                     potion++;
  153.                                     System.out.println("You found a potion!");
  154.                                     JOptionPane.showMessageDialog(null, "You found a potion! You now have " + potion + " potions.");
  155.                                                  
  156.                             break;  }
  157.                            
  158.                             case 3:
  159.                         if (loot == 2){
  160.                             health -=  (int)(Math.random()*16 + 10);
  161.                             System.out.println("Oh no! The chest was trapped. You took some damage...");
  162.                             JOptionPane.showMessageDialog(null, "Oh no! The chest was trapped. You now have " + health + " health.");
  163.                            
  164.                         break;
  165.                         }
  166.                        
  167.                             case 4:                  
  168.                       if (loot ==3) {
  169.                             System.out.println("No loot from that chest.");
  170.                         JOptionPane.showMessageDialog(null, "You found nothing...");
  171.      
  172.                         break;  
  173.                         }    
  174.                            
  175.                             case 5:                  
  176.                                 if (loot == 4 ) {
  177.                                     System.out.println("No loot from that chest.");
  178.                                   JOptionPane.showMessageDialog(null, "You found nothing...");
  179.                
  180.                                   break;  
  181.                                   }    
  182.                             }
  183.                             }
  184.                            
  185.                            
  186.                             }
  187.            
  188.                    
  189.              
  190.                    
  191.          
  192.     public static int Move (char direction)  // receives user input and gives you an integer coord in exchange
  193.      
  194.     {
  195.      
  196.     switch (direction){
  197.             case 'N':
  198.                     System.out.println("You went north.");  
  199.                     amountStep++;
  200.                     amountNorth++;
  201.                     if(amountNorth>0 && amountEast>0){
  202.                     System.out.println("You are at North " + amountNorth + " and East " + amountEast);
  203.                     } else if(amountNorth<0 && amountEast<0) {                    
  204.                     System.out.println("You are at South " + amountNorth*-1 + " and West " + amountEast*-1);
  205.                     }
  206.                     else if(amountNorth>0 && amountEast<0){
  207.                         System.out.println("You are at North " + amountNorth + " and West " + amountEast*-1);  
  208.                     }
  209.                     else if(amountNorth<0 && amountEast>0){
  210.                         System.out.println("You are at South " + amountNorth*-1 + " and East " + amountEast);  
  211.                     }
  212.                     else if(amountNorth==0 && amountEast==0){
  213.                         System.out.println("You are in between North and South and East and West");    
  214.                     }
  215.                     else if(amountNorth==0 && amountEast<0){
  216.                     System.out.println("You are inbetween North and South and at West " + amountEast*-1);  
  217.                     }
  218.                     else if(amountNorth<0 && amountEast==0){
  219.                         System.out.println("You are at South " + amountNorth*-1 + " and in between East and West");
  220.                         }
  221.                     else if(amountNorth==0 && amountEast>0){
  222.                         System.out.println("You are inbetween North and South and at East " + amountEast); 
  223.                         }
  224.                     else if(amountNorth>0 && amountEast==0){
  225.                         System.out.println("You are at North " + amountNorth + " and in between East and West");   
  226.                         }
  227.                     return 0;
  228.             case 'E':
  229.                     System.out.println("You went east.");
  230.                     amountStep++;
  231.                     amountEast++;                    
  232.                    
  233.                           if(amountNorth>0 && amountEast>0){
  234.                               System.out.println("You are at North " + amountNorth + " and East " + amountEast);
  235.                             } else if(amountNorth<0 && amountEast<0) {                    
  236.                             System.out.println("You are at South " + amountNorth*-1 + " and West " + amountEast*-1);
  237.                             }
  238.                             else if(amountNorth>0 && amountEast<0){
  239.                                 System.out.println("You are at North " + amountNorth + " and West " + amountEast*-1);  
  240.                             }
  241.                             else if(amountNorth<0 && amountEast>0){
  242.                                 System.out.println("You are at South " + amountNorth*-1 + " and East " + amountEast);  
  243.                             }
  244.                             else if(amountNorth==0 && amountEast==0){
  245.                                 System.out.println("You are in between North and South and East and West");    
  246.                             }
  247.                             else if(amountNorth==0 && amountEast<0){
  248.                             System.out.println("You are inbetween North and South and at West " + amountEast*-1);  
  249.                             }
  250.                             else if(amountNorth<0 && amountEast==0){
  251.                                 System.out.println("You are at South " + amountNorth*-1 + " and in between East and West");
  252.                                 }
  253.                             else if(amountNorth==0 && amountEast>0){
  254.                                 System.out.println("You are inbetween North and South and at East " + amountEast); 
  255.                                 }
  256.                             else if(amountNorth>0 && amountEast==0){
  257.                                 System.out.println("You are at North " + amountNorth + " and in between East and West");   
  258.                                 }
  259.                    
  260.                     return 1;                  
  261.             case 'S':
  262.                     System.out.println("You went south.");
  263.                     amountStep++;
  264.                     amountNorth--;
  265.                     if(amountNorth>0 && amountEast>0){
  266.                         System.out.println("You are at North " + amountNorth + " and East " + amountEast);
  267.                         } else if(amountNorth<0 && amountEast<0) {                    
  268.                         System.out.println("You are at South " + amountNorth*-1 + " and West " + amountEast*-1);
  269.                         }
  270.                         else if(amountNorth>0 && amountEast<0){
  271.                             System.out.println("You are at North " + amountNorth + " and West " + amountEast*-1);  
  272.                         }
  273.                         else if(amountNorth<0 && amountEast>0){
  274.                             System.out.println("You are at South " + amountNorth*-1 + " and East " + amountEast);  
  275.                         }
  276.                         else if(amountNorth==0 && amountEast==0){
  277.                             System.out.println("You are in between North and South and East and West");    
  278.                         }
  279.                         else if(amountNorth==0 && amountEast<0){
  280.                         System.out.println("You are inbetween North and South and at West " + amountEast*-1);  
  281.                         }
  282.                         else if(amountNorth<0 && amountEast==0){
  283.                             System.out.println("You are at South " + amountNorth*-1 + " and in between East and West");
  284.                             }
  285.                         else if(amountNorth==0 && amountEast>0){
  286.                             System.out.println("You are inbetween North and South and at East " + amountEast); 
  287.                             }
  288.                         else if(amountNorth>0 && amountEast==0){
  289.                             System.out.println("You are at North " + amountNorth + " and in between East and West");   
  290.                             }
  291.                     return 2;
  292.             case 'W':
  293.                     System.out.println("You went west.");  
  294.                     amountStep++;
  295.                     amountEast--;
  296.                     if(amountNorth>0 && amountEast>0){
  297.                         System.out.println("You are at North " + amountNorth + " and East " + amountEast);
  298.                         } else if(amountNorth<0 && amountEast<0) {                    
  299.                         System.out.println("You are at South " + amountNorth*-1 + " and West " + amountEast*-1);
  300.                         }
  301.                         else if(amountNorth>0 && amountEast<0){
  302.                             System.out.println("You are at North " + amountNorth + " and West " + amountEast*-1);  
  303.                         }
  304.                         else if(amountNorth<0 && amountEast>0){
  305.                             System.out.println("You are at South " + amountNorth*-1 + " and East " + amountEast);  
  306.                         }
  307.                         else if(amountNorth==0 && amountEast==0){
  308.                             System.out.println("You are in between North and South and East and West");    
  309.                         }
  310.                         else if(amountNorth==0 && amountEast<0){
  311.                         System.out.println("You are inbetween North and South and at West " + amountEast*-1);  
  312.                         }
  313.                         else if(amountNorth<0 && amountEast==0){
  314.                             System.out.println("You are at South " + amountNorth*-1 + " and in between East and West");
  315.                             }
  316.                         else if(amountNorth==0 && amountEast>0){
  317.                             System.out.println("You are inbetween North and South and at East " + amountEast); 
  318.                             }
  319.                         else if(amountNorth>0 && amountEast==0){
  320.                             System.out.println("You are at North " + amountNorth + " and in between East and West");   
  321.                             }
  322.                     return 3;
  323.             case 'P':
  324.                 if (potion > 0) {
  325.                     potion--; //remove 1 potion
  326.                     health++;
  327.                     amount = (int)((Math.random() * 11) + 10); //generate random heal amount between 10-20
  328.                
  329.                     health += amount; //heal from potion
  330.                     if (health > 100) {
  331.                         health = 100;
  332.                    
  333.                     System.out.println("You drink a potion.");
  334.                     System.out.println("You healed " + amount + " health! you now have " + health + " health.");
  335.                     System.out.println("You have " + potion + " potions left.");
  336.                     }
  337.                 } else {
  338.                     System.out.println("You have 0 potions to drink.");
  339.                     JOptionPane.showMessageDialog(null, "You have no potions to drink.");
  340.                 }
  341.            
  342.                 return 5;
  343.                
  344.                        
  345.             default:
  346.                
  347.                     return 6;
  348.                    
  349.                    
  350.     }
  351.      
  352.      
  353.     }
  354.      
  355.     public static void battle ()
  356.            
  357.     {
  358.             if (health > 0) { //check you're alive.
  359.                     uncheckedInput = JOptionPane.showInputDialog(null, "What do you do, (A)ttack (D)efend (P)otion or (R)un?"); //take input string
  360.                     if (!uncheckedInput.equals("")) { //check there actually is a character at (0) to stop game crashing
  361.                             battleChoice = Character.toUpperCase(uncheckedInput.charAt(0)); //set the battlechoice variable to the Char at 0, and capitalise it.
  362.                     } else {
  363.                     //FDNAFUIGRUI THIS LINE WAS THE PROBLEM >>  //battle(); re-call the battle method to ask question again because user entered nothing
  364.                     }
  365.  
  366.                  
  367.                     int hit;        
  368.                     int runChance;
  369.                    
  370.                     switch (battleChoice){
  371.                             case 'A':
  372.                                     hit = (int)(Math.random() * 6 *.5 * level + 2); //your damage
  373.                                     enemyHealth -= hit;
  374.                                    
  375.                                     if(hit >= enemyHealth) { //hit high enough to kill the enemy
  376.                                         System.out.println("You hit " + hit + " damage and kill the enemy!");
  377.                                                 JOptionPane.showMessageDialog(null, "You hit " + hit + " damage and kill the enemy!");
  378.                                              
  379.                                             gold += (int)((Math.random() * 10) + 1); //gives player gold between 1-10.
  380.                                             exp += (int) ((Math.random() * 10) + 1); //gives player exp;
  381.                                             System.out.println("You now have " +exp+ " exp and " +gold+ " gold.");
  382.                                             JOptionPane.showMessageDialog(null, "You now have " +exp+ " exp and " +gold+ " gold.");
  383.                                             int potionDrop = (int) (Math.random() * 10);
  384.                                             if (potionDrop == 0) {
  385.                                                 potion ++;
  386.                                                 System.out.println("You have gained a potion! You now have " + potion + " potions.");
  387.                                                 JOptionPane.showMessageDialog(null, "You have gained a potion! You now have " + potion + " potions.");        
  388.                                             }
  389.                                             level();
  390.                                             break;
  391.                                     } else {
  392.                                         System.out.println("you hit " + hit + " damage. The enemy now has " + enemyHealth + " health.");
  393.                                              JOptionPane.showMessageDialog(null, "You hit " + hit + " damage. The enemy now has " + enemyHealth + " health.");    
  394.                                            
  395.                                             hit = (int)((Math.random() * 8) + 2);
  396.                                             health -= hit; //enemy hits you back
  397.                                             System.out.println("The enemy retaliates with " + hit + " damage. Your health is now " + health + ".");
  398.                                             JOptionPane.showMessageDialog(null, "The enemy retaliates with a " + hit + ". Your health is now " + health + ".");
  399.                                            
  400.                                             battle(); //battle isn't over cos both alive so make it ask you what to do next in battle.
  401.                                            break;
  402.                                     }
  403.                                    
  404.                             case 'D':
  405.                                     hit = (int)((Math.random() * 5)); //enemy hits half of normal because defending mode.
  406.                                     health -= hit;
  407.                                     System.out.println("You took " +hit+ " damage! Your health is now " + health);
  408.                                     JOptionPane.showMessageDialog(null, "You took " +hit+ " damage! Your health is now " + health);
  409.                                    
  410.                                     battle(); // battle continues
  411.                                     break;
  412.                             case 'P':
  413.                                     if (potion > 0) {
  414.                                             potion--; //remove 1 potion
  415.                                             amount = (int)((Math.random() * 11) + 10); //generate random heal amount between 10-20
  416.                                        
  417.                                             health += amount; //heal from potion
  418.                                             if (health > 100) {
  419.                                                 health = 100;
  420.                                             }
  421.                                             System.out.println("You healed " + amount + " health! you now have " + health + " health.");
  422.                                             System.out.println("You have " + potion + " potions left.");
  423.                                             JOptionPane.showMessageDialog(null, "You drink a potion.");
  424.                                             JOptionPane.showMessageDialog(null, "You healed " + amount + " health! you now have " + health + " health.");
  425.                                             JOptionPane.showMessageDialog(null, "You have " + potion + " potions left.");
  426.                                            
  427.                                             hit = (int)((Math.random() * 6 + 2)); //enemy hit on you after potion
  428.                                             health -= hit; //enemy hits you back
  429.                                             System.out.println("enemy hits you with a " + hit + ". Your health is now " + health);
  430.                                             JOptionPane.showMessageDialog(null, "enemy hits you with a " + hit + ". Your health is now " + health);
  431.                                            
  432.                                            
  433.                                     } else {
  434.                                         System.out.println("You have 0 potions to drink.");
  435.                                             JOptionPane.showMessageDialog(null, "You have no potions to drink.");
  436.                                            
  437.                                     }
  438.                                     battle();
  439.                                     break;
  440.                             case 'R':
  441.                                     runChance = (int) (Math.random() * 2); //50/50 chance of escape
  442.                                     if (runChance == 0) {
  443.                                             //successful escape, battle over and continues adventure
  444.                                         System.out.println("You successfully escape!");
  445.                                             JOptionPane.showMessageDialog(null, "You successfully escape!");
  446.                                            
  447.                                             break;
  448.                                     } else {
  449.                                             //unsuccessful escape
  450.                                             hit = (int)((Math.random() * 11) + 6); //enemy hit between 10-20
  451.                                             health -= hit; //so you get hit
  452.                                             System.out.println("You try to escape but are too slow and the enemy hits you for a " + hit +" . You now have " + health + " health.");
  453.                                             JOptionPane.showMessageDialog(null, "You try to escape but are too slow and the enemy hits you for a " + hit +" . You now have " + health + " health.");
  454.                                            
  455.                                             battle(); //battle continues
  456.                                             break;
  457.                                     }
  458.                             default:
  459.                                     battle(); //user didn't enter any of the battle options, so we ask them again
  460.                                     break;
  461.                     }
  462.                    
  463.                            
  464.                            
  465.             } else if(health < 1) {
  466.                
  467.                     die = true; //dead
  468.                     if (health < 0) {
  469.                         health = 0;
  470.                     }
  471.                     System.out.println("Oh dear, you are dead!");
  472.                     JOptionPane.showMessageDialog(null, "Oh dear, you are dead!");
  473.                     System.out.println("You die with " +exp+ " exp and " +gold+ " gold.");
  474.                     JOptionPane.showMessageDialog(null, "You die with " +exp+ " exp and " +gold+ " gold.");
  475.                     System.out.println("You die at " + amountNorth +"and " +amountEast+ " East.");
  476.                     JOptionPane.showMessageDialog(null, "You die at North " + amountNorth + " and East " + amountEast);
  477.                     System.exit(0);
  478.                    
  479.             }
  480.     }
  481.    
  482.     public static void level ()
  483.     {
  484.                     switch (level)
  485.                     {
  486.      
  487.      case 0:
  488.             if(exp<20)                
  489.             JOptionPane.showMessageDialog(null, "You are level " + level + ".");
  490.             System.out.println("Level "+ level+ ".");  
  491.             break;                    
  492.             case 1:
  493.                     if(exp>=20)                
  494.                     level++;
  495.                     JOptionPane.showMessageDialog(null, "You are level " + level + ".");
  496.                     System.out.println("Level "+ level+ ".");  
  497.                     break;                  
  498.                     case 2:
  499.                         if(exp>=40)                
  500.                         level++;
  501.                         JOptionPane.showMessageDialog(null, "You are level " + level + ".");
  502.                         System.out.println("Level "+ level+ ".");  
  503.                         break;
  504.                         case 3:
  505.                             if(exp>=80)                
  506.                             level++;
  507.                             JOptionPane.showMessageDialog(null, "You are level " + level + ".");
  508.                             System.out.println("Level "+ level+ ".");  
  509.                             break;
  510.                             case 4:
  511.                                 if(exp>=160)              
  512.                                 level++;
  513.                                 JOptionPane.showMessageDialog(null, "You are level " + level + ".");
  514.                                 System.out.println("Level "+ level+ ".");  
  515.                                 break;
  516.                                 case 5:
  517.                                     if(exp>=320)                  
  518.                                     level++;
  519.                                     JOptionPane.showMessageDialog(null, "You are level " + level + ".");
  520.                                     System.out.println("Level "+ level+ ".");      
  521.                                     break;
  522.              
  523.                                 default:
  524.                                     break;
  525.             }
  526.     }
  527.    
  528.    
  529.     public static void leave(){
  530.        
  531.        
  532.         uncheckedInput = JOptionPane.showInputDialog("Do you leave, (Y)es or (N)o?");
  533.         if (!uncheckedInput.equals("")) {
  534.                 userInput = Character.toUpperCase(uncheckedInput.charAt(0));
  535.         }
  536.        
  537.         switch(userInput) {
  538.         case 'Y':
  539.             leave = true;
  540.             System.out.println("You leave with " +exp+ " exp and " +gold+ " gold.");
  541.             JOptionPane.showMessageDialog(null, "You leave with " +exp+ " exp and " +gold+ " gold.");
  542.      
  543.             System.out.println("Your exit was at " + amountNorth + amountEast);
  544.             JOptionPane.showMessageDialog(null, "Your exit was at at North " + amountNorth + " and East " + amountEast);
  545.             System.exit(0);
  546.     case 'N':
  547.             leave = false;
  548.             break;
  549.     default:
  550.             leave();
  551.             break;
  552.             }
  553.  
  554. }
  555.    
  556.  public static void shop(){
  557.      @SuppressWarnings("unused")
  558.     boolean potionBuy;
  559.         uncheckedInput = JOptionPane.showInputDialog("Do you buy a potion, (Y)es or (N)o?");
  560.         if (!uncheckedInput.equals("")) {
  561.                 userInput = Character.toUpperCase(uncheckedInput.charAt(0));
  562.         }
  563.         switch(userInput){
  564.        
  565.  case 'Y':
  566.      potionBuy = true;
  567.      gold -= 10;
  568.      potion++;
  569.      System.out.println("You buy a potion.");
  570.      JOptionPane.showMessageDialog(null, "You buy a potion; you now have "+potion+ " potions and "+gold+ " gold left.");
  571. case 'N':
  572.      potionBuy = false;
  573.      break;
  574. default:
  575.      break;
  576.  }
  577.  }
  578.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement