Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.12 KB | None | 0 0
  1.  
  2. /**
  3. * Create a battle program with several methods
  4. *
  5. * @neomattlac
  6. * @version 2, 11/18/2010
  7. */
  8. import java.util.*;
  9. public class TextBasedBattle2
  10. {
  11. public void menu(){
  12. System.out.println();
  13. System.out.println("*** Menu ***");
  14. System.out.println("1: Basic attack.");
  15. System.out.println("-Uses 1 stamina. Inflicts between 1 and 10 damage.");
  16. System.out.println("---");
  17. System.out.println("2: Strong attack.");
  18. System.out.println("-Uses 5 stamina. Inflicts between 25 and 35 damage.");
  19. System.out.println("---");
  20. System.out.println("3: Magic attack.");
  21. System.out.println("-Uses 10 mana. Inflicts between 10 and 35 damage. Has 50% of skipping the monster's turn.");
  22. System.out.println("---");
  23. System.out.println("4: Combination attack.");
  24. System.out.println("-Uses 5 mana and 5 stamina. Inflicts between 30 and 50 damage");
  25. System.out.println("---");
  26. System.out.println("5: Heal");
  27. System.out.println("-Uses 5 mana. Recovers 10-40 health points.");
  28. System.out.println("---");
  29. System.out.println("6: Flee");
  30. System.out.println("-Uses 20 mana and 20 stamina. 33% chance of fleeing");
  31. System.out.println("---");
  32. System.out.println("Any other choice results in a forfeited turn");
  33. System.out.println();
  34. }
  35. public void attackCompute(int attackChoice, int monsterHealth, int selfHealth, int selfAttack, int mana, int stamina, int fleeChance);
  36. Scanner input = new Scanner(System.in);
  37. Random rgen = new Random();
  38.  
  39. System.out.println("Choose your attack");
  40. System.out.println("--------------------");
  41. attackChoice=input.nextInt();
  42. //Take in the user's info and store it as attackChoice
  43. switch(attackChoice){
  44. case 1: stamina--;
  45. //Subtract 1 stamina
  46. selfAttack=rgen.nextInt(10)+1;
  47. //Generate a random number between 1 and 10 and store as selfAttack
  48. System.out.println("You attacked with a basic attack.");
  49. System.out.println("You dealt " + selfAttack + " damage");
  50. monsterHealth-=selfAttack;
  51. //Deal damage to monster
  52. System.out.println("The monster has " + monsterHealth + " health left.");
  53. break;
  54. case 2: stamina-=5;
  55. //Subtract one stamina
  56. selfAttack=rgen.nextInt(11)+25;
  57. //Generate a random number between 25 and 35 and store as selfAttack
  58. System.out.println("You attacked with a strong attack!");
  59. System.out.println("You dealt " + selfAttack + " damage");
  60. monsterHealth-=selfAttack;
  61. System.out.println("The monster has " + monsterHealth + " health left.");
  62. break;
  63. case 3: mana-=10;
  64. //Subtract 10 mana
  65. selfAttack=rgen.nextInt(26)+10;
  66. //Generate a random number between 10 and 35 and store as selfAttack
  67. System.out.println("You attacked with a magic attack!");
  68. System.out.println("You dealt " + selfAttack + " damage");
  69. monsterHealth-=selfAttack;
  70. System.out.println("The monster has " + monsterHealth + " health left.");
  71. skipChance=rgen.nextInt(2);
  72. break;
  73. case 4: mana-=5; stamina-=5;
  74. //Subtract 5 mana and 5 stamina
  75. selfAttack=rgen.nextInt(21)+31;
  76. //Generate a random number between 30 and 50 and store as selfAttack
  77. System.out.println("You attacked with a combination attack!");
  78. System.out.println("You dealt " + selfAttack + " damage");
  79. monsterHealth-=selfAttack;
  80. System.out.println("The monster has " + monsterHealth + " health left!");
  81. break;
  82. case 5: mana-=5;
  83. //Subtract 5 mana
  84. System.out.println("You chose to heal");
  85. selfHeal=rgen.nextInt(31)+11;
  86. //Generate a random number between 10 and 40 and store as selfHeal
  87. System.out.println("You recovered " + selfHeal + " health!");
  88. break;
  89. case 6:
  90. mana-=20; stamina-=20;
  91. //Subtract 20 mana and 20 stamina
  92. fleeChance=rgen.nextInt(3);
  93. //Generate a random number between 0 and 2 and store as fleeChance
  94. break;
  95. default: System.out.println("You forfeited your turn!"); break;
  96. }
  97. public void stats(int monsterHealth, int selfHealth, int mana, int stamina){
  98. Scanner input = new Scanner(System.in);
  99. Random rgen = new Random();
  100. while(monsterHealth>0||selfHealth>0){
  101. System.out.println("Stats: " + selfHealth + " health.");
  102. System.out.println(" " + stamina + "stamina.");
  103. System.out.println(" " + mana + "mana.");
  104. System.out.println("------------------");
  105. }
  106. }
  107. public static void main(String args[]){
  108. Scanner input = new Scanner(System.in);
  109. TextBasedBattle2 call = new TextBasedBattle2();
  110. int selfHealth=1000;
  111. int numBattle=0;
  112. string battleChoice;
  113. System.out.println("Would you like to battle");
  114. battleChoice=input.nextLine();
  115.  
  116. if(battleChoice=="yes"||battleChoice=="Yes"&&selfHealth>0){
  117. int fleeChance=0;
  118. int attackChoice=0;
  119. int mana=100;
  120. int stamina=200;
  121. int selfHeal=0;
  122. int selfAttack=0;
  123. int monsterHeal=0;
  124. int monsterAttack=0;
  125. System.out.println("The battle begins!");
  126. System.out.println("*******************");
  127. call.Menu();
  128. call.AttackCompute(attackChoice, monsterHealth, selfHealth, selfAttack, mana, stamina, fleeChance);
  129. while(fleeChance!=2){
  130. call.Stats(monsterHealth, selfHealth, mana, stamina);
  131. if(skipChance!=0){
  132. monsterAttack=rgen.nextInt(101);
  133. System.out.println("The monster attacked for " + monsterAttack + " damage!");
  134.  
  135. }
  136. }
  137. }
  138. }
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement