NoNameCracksInc

Java cmd game

Mar 27th, 2013
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.75 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class consoleGame{
  5.     public BufferedReader reader;
  6.     public String name;
  7.     public int gold;
  8.     public int dmg1;
  9.     public int dmg2;
  10.     public int win1;
  11.     public int win2;
  12.     public String again;
  13.     public String shop;
  14.     public String decision;
  15.     public int dmg;
  16.     public String weapon0;
  17.     public Random random;
  18.     public int axe;
  19.     public int mace;
  20.     public int axeObj;
  21.     public int maceObj;
  22.     public int decision0;
  23.        
  24.  public void game()throws IOException{
  25.      reader = new BufferedReader(new InputStreamReader(System.in));
  26.      random = new Random();
  27.      
  28.      System.out.print("Enter your name: ");
  29.      name = reader.readLine();
  30.      do{
  31.          
  32. /**//**//**//**//**//**//**//**//**//**//**//**/         
  33. /**//**//**//**//**//**//**//**//**//**//**//**/
  34. /**/         if(axe != 1 && mace != 1){     /**/  
  35. /**/             weapon0 = "Sword";}        /**/
  36. /**/                                        /**/
  37. /**/         else if(axe == 1){             /**/
  38. /**/             weapon0 = "Axe";}          /**/  
  39. /**/                                        /**/
  40. /**/         else if(mace ==1){             /**/
  41. /**/             weapon0 = "Mace";}         /**/  
  42. /**/                                        /**/
  43. /**//**//**//**//**//**//**//**//**//**//**//**/
  44. /**//**//**//**//**//**//**//**//**//**//**//**/
  45.  
  46.      for(int i=0; i<=10; i++) System.out.println();
  47.      System.out.println("--------------------");
  48.      System.out.println("     --OVERVIEW--");
  49.      System.out.println("Your name is: " + name);
  50.      System.out.println("Your weapon: " + weapon0);
  51.      System.out.println("Your health: 1/1");
  52.      System.out.println("Your gold: " + gold);
  53.      System.out.println("--------------------");
  54.      
  55.      System.out.print('\n' + "Press any key to start fight or [shop] to enter the shop:");
  56.      shop = reader.readLine();
  57.      
  58. /**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**/     
  59. /**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**/     
  60. /**/    if(shop.equals("shop")){                                                            /**/
  61. /**/     for (int i=0; i<=3; i++) System.out.println();                                     /**/
  62. /**/     System.out.println("+---------------SHOP-------------------+");                    /**/    
  63. /**/     System.out.println("|             FOR SALE                 |");                    /**/    
  64. /**/     System.out.println("| Axe-300g.                            |");                    /**/    
  65. /**/     System.out.println("| Mace-500g.                           |");                    /**/
  66. /**/     System.out.println("|                                      |");                    /**/
  67. /**/     System.out.print("|" + "Press [1] to buy axe, [2] to buy mace." + "|");            /**/    
  68. /**/                                                                                        /**/        
  69. /**/         decision = reader.readLine();                                                  /**/
  70. /**/         decision0 = Integer.parseInt(decision);                                        /**/
  71. /**/                                                                                        /**/
  72. /**/         if(decision0 == 1 && gold >= 300){                                             /**/
  73. /**/             axe = 1;                                                                   /**/
  74. /**/             mace = 0;                                                                  /**/
  75. /**/             System.out.println("You bought an axe!");                                  /**/
  76. /**/             System.out.println('\n' + "Press enter to leave shop...");                 /**/  
  77. /**/                 String leave = reader.readLine();                                      /**/
  78. /**/         }                                                                              /**/
  79. /**/         else if (decision0 == 2 && gold >=500){                                        /**/
  80. /**/             mace = 1;                                                                  /**/
  81. /**/             axe = 0;                                                                   /**/
  82. /**/             System.out.println("You bought a mace!");                                  /**/
  83. /**/                 System.out.println('\n' + "Press enter to leave shop...");             /**/  
  84. /**/                 String leave = reader.readLine();                                      /**/
  85. /**/         }                                                                              /**/
  86. /**/         else if ((decision0 == 1 && (gold != 300 || gold < 300))){                     /**/
  87. /**/             System.out.println("Not enough gold.");                                    /**/
  88. /**/             axe = 0;                                                                   /**/
  89. /**/             mace = 0;                                                                  /**/
  90. /**/         }                                                                              /**/
  91. /**/         else if ((decision0 == 2 && (gold != 500 || gold < 500))){                     /**/
  92. /**/             System.out.println("Not enough gold.");                                    /**/
  93. /**/             axe = 0;                                                                   /**/
  94. /**/             mace = 0;                                                                  /**/
  95. /**/         }                                                                              /**/                                    
  96. /**/     }                                                                                  /**/
  97. /**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**/
  98. /**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**/
  99.  
  100. if(axe !=1 && mace !=1){
  101.     dmg = 20;}   
  102. if(axe == 1){
  103.     dmg = 50;
  104.     axe = 1;}    
  105. if(mace == 1){
  106.     dmg = 80;
  107.     mace = 1;}
  108.      
  109. //////////////////////////////////////////////START OF FIGHT////////////////////////////////////////////////
  110.  
  111.      dmg1 = random.nextInt(dmg);
  112.      dmg2 = random.nextInt(20);
  113.      
  114.      for(int i=0; i<=2; i++) System.out.println();
  115.      System.out.println("Round one: ");
  116.      System.out.println(name + " " + dmg1 + " VS" + " " + dmg2 + " " + "CPU");
  117.      
  118.      if(dmg1 > dmg2){
  119.          System.out.println('\n' + name + " wins!");
  120.          gold = gold + 50;
  121.          win1 = 1;
  122.          win2 = 0;
  123.      }
  124.      else if(dmg1 < dmg2){
  125.          System.out.println('\n' + "CPU wins!");
  126.          gold = gold + 0;
  127.          win1 = 0;
  128.          win2 = 0;
  129.      }
  130.      else if (dmg1 == dmg2){
  131.          System.out.println('\n' + "Tie!");
  132.          gold = gold + 0;
  133.          win1 = 0;
  134.          win2 = 0;       
  135.      }
  136.      System.out.println("Press enter to proceed...");
  137.      again = reader.readLine();
  138.      }
  139.      while(!again.equals("n"));
  140.       }
  141.  ///////////////////////////////////////CALLING PROGRAM/////////////////////////////////////////////////////
  142.  
  143.       public static void main(String args[])throws IOException{
  144.           consoleGame x = new consoleGame();
  145.           x.game();
  146.          
  147.       }
  148. }
Advertisement
Add Comment
Please, Sign In to add comment