Advertisement
HerobrineGamesYT

code

Apr 21st, 2019
389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.51 KB | None | 0 0
  1. package net.tanner.starwarsbattles;
  2.  
  3. import java.util.Random;
  4. import java.util.Scanner;
  5.  
  6. public class Main {
  7.  
  8. public static void main(String[] args) {
  9. // This is going to be a game.
  10. // You can choose an imperial fleet, dark fleet, or
  11. // rebel fleet.
  12. // The army will attack the death star, but there will be
  13. // different outcomes and options depending on what fleet
  14. // you choose and how many troops you go with.
  15. // Each army will have different abilities, and a different
  16. // number of troops.
  17. // The user can select different options by typing
  18. // different choices into the console, options being
  19. // displayed
  20. // and processed as integers/strings.
  21. Scanner optionReader = new Scanner(System.in);
  22. System.out.println("Welcome to Star Wars Battles!");
  23. System.out.println("In this game, you can choose your fleet, and battle the death star!");
  24. System.out.println("Each fleet has different abilities.");
  25. System.out.println("Let's select your fleet!");
  26. System.out.println("Pick the number of the fleet that you would like to use.");
  27.  
  28. System.out.println("1: Imperial Fleet");
  29. System.out.println("2: Dark Fleet");
  30. System.out.println("3: Rebel Fleet");
  31. System.out.println("4: Tell me about each fleet!");
  32. int fleetChoice = optionReader.nextInt();
  33. if (fleetChoice == 1) {
  34. System.out.println("You chose to use the Imperial Fleet.");
  35. } else if (fleetChoice == 2) {
  36. System.out.println("You chose to use the Dark Fleet.");
  37. } else if (fleetChoice == 3) {
  38. System.out.println("You chose to use the Rebel Fleet.");
  39. } else if (fleetChoice == 4) {
  40. System.out.println("Each fleet has different abilities and specifications.");
  41. System.out.println("The imperial fleet has only 5 troops, but they are very powerful and tanky.");
  42. System.out.println(
  43. "The ability of the imperial fleet is a high-powered laser beam, which you can fire every 180 seconds.");
  44. System.out.println("The dark fleet has 100 troops, but they are not as powerful as the other troops.");
  45. System.out.println(
  46. "The ability of the dark fleet is the ability to call on their master-- Darth Vader. Darth Vader is about 5 times more powerful than the entire imperial fleet.");
  47. System.out.println("You can call on Darth Vader once every 200 seconds.");
  48. System.out.println("The rebel fleet has 50 troops, each of an average strength.");
  49. System.out.println(
  50. "However, there is one special troop in the fleet-- Luke Skywalker! Every 100 seconds, he can activate a super secret ability that will make him as powerful as an imperial fleet soldier for 10 seconds.");
  51. System.out.println("Do you understand? 1. Yes 2. No");
  52.  
  53. Scanner anotherOptionReader = new Scanner(System.in);
  54. int doYouUnderstand = anotherOptionReader.nextInt();
  55. if (doYouUnderstand == 1) {
  56. System.out.print("\033[H\033[2J");
  57. System.out.flush();
  58. System.out.println("Great! Now choose your fleet:");
  59. System.out.println("1: Imperial Fleet");
  60. System.out.println("2: Dark Fleet");
  61. System.out.println("3: Rebel Fleet");
  62. int secondFleetChoice = anotherOptionReader.nextInt();
  63. if (secondFleetChoice == 1) {
  64. System.out.println("You have chosen the Imperial Fleet.");
  65. System.out.println("Would you like to attack the Death star?");
  66. System.out.println("1: Yes");
  67. System.out.println("2: No");
  68. Scanner initiateAttackChoice = new Scanner(System.in);
  69. int initiateAttackDecision = initiateAttackChoice.nextInt();
  70. if (initiateAttackDecision == 1) {
  71. System.out.print("\033[H\033[2J");
  72. System.out.flush();
  73. System.out.println("How to attack:");
  74. System.out.println("First, you must initiate an attack on the ship.");
  75. System.out.println("To do this, press 1.");
  76. Scanner attackChoice = new Scanner(System.in);
  77. int attackDecision = attackChoice.nextInt();
  78. if (attackDecision == 1) {
  79. System.out.println("Inflicted 50 damage on the death star! It has 950 health left.");
  80. System.out.println("Great job, but now it's the death star's turn!");
  81. System.out.println("I think you got this on your own now, good luck!");
  82. System.out.println("Press 6 to continue.");
  83. Scanner continueBattle = new Scanner(System.in);
  84. int continueInput = continueBattle.nextInt();
  85. if (continueInput == 6) {
  86. int deathStarHealth = 950;
  87. int imperialFleetHealth = 1500;
  88. while (deathStarHealth > 0 || imperialFleetHealth > 0) {
  89. if (deathStarHealth <= 0) {
  90. System.out.flush();
  91. System.out.println("Congratulations! You have defeated the death star!");
  92. break;
  93. } else if (imperialFleetHealth <= 0) {
  94. System.out.flush();
  95. System.out.println("Game over! You have been defeated by the death star!");
  96. break;
  97.  
  98. }
  99. Random rand = new Random();
  100.  
  101. int attackID = 1 + rand.nextInt((10 - 1) + 1);
  102. if (attackID == 1) {
  103. System.out.println(
  104. "The death star has fired a powerful laser beam! 100 fleet damage was inficted.");
  105. imperialFleetHealth = imperialFleetHealth - 100;
  106. System.out.println("The fleet has " + imperialFleetHealth + " health left.");
  107. } else if (attackID == 2) {
  108. System.out.println(
  109. "The death star has fired an explosive heat-seeking missle! 500 fleet damage was inflicted.");
  110. imperialFleetHealth = imperialFleetHealth - 500;
  111. System.out.println("The fleet has " + imperialFleetHealth + " health left.");
  112. }
  113.  
  114. else if (attackID == 3) {
  115. System.out.println(
  116. "A soldier aboard the death star taken some shots at your fleet. 200 fleet damage was inflected.");
  117. imperialFleetHealth = imperialFleetHealth - 200;
  118. System.out.println("The fleet has " + imperialFleetHealth + " health left.");
  119. }
  120.  
  121. else if (attackID == 4) {
  122. System.out.println(
  123. "A group of 100 storm troopers unleashed their lightsabers and attacked your fleet. 300 fleet damage was inflicted.");
  124. imperialFleetHealth = imperialFleetHealth - 300;
  125. System.out.println("The fleet has " + imperialFleetHealth + " health left.");
  126. }
  127.  
  128. else if (attackID == 5) {
  129. System.out.println(
  130. "Darth Vader has appeared! He attacks! 500 fleet damage has been inflicted.");
  131. imperialFleetHealth = imperialFleetHealth - 500;
  132. System.out.println("The fleet has " + imperialFleetHealth + " health left.");
  133. } else if (attackID == 6) {
  134. System.out.println(
  135. "Uh oh! A metorite came in and struck your fleet AND the death star. 200 fleet damage was inflicted, and 100 damage was done to the death star.");
  136. imperialFleetHealth = imperialFleetHealth - 200;
  137. deathStarHealth = deathStarHealth - 100;
  138. System.out.println("Your fleet has " + imperialFleetHealth + " health left.");
  139. System.out.println("The death star has " + deathStarHealth + " health left.");
  140. } else if (attackID == 7) {
  141. System.out.println("");
  142. }
  143.  
  144. else if (attackID == 8) {
  145.  
  146. } else if (attackID == 9) {
  147.  
  148. }
  149.  
  150. else if (attackID == 10) {
  151.  
  152. } else {
  153. System.out.println("Fatal error, shutting down!");
  154. return;
  155. }
  156.  
  157. System.out.println("What will you choose to do next?");
  158. System.out.println("1: Attack");
  159. System.out.println("2: Use Ability");
  160. System.out.println("3: Surrender");
  161. System.out.println("4: Check the status of your fleet and the ships.");
  162. Scanner anotherAttackChoice = new Scanner(System.in);
  163. int anotherAttackDecision = anotherAttackChoice.nextInt();
  164. if (anotherAttackDecision == 1) {
  165. Random attackDMGGen = new Random();
  166. int attackDMG = 50 + attackDMGGen.nextInt((200 - 50) + 1);
  167. System.out.println("The attack was successful! " + attackDMG
  168. + " damage was dealt to the death star.");
  169. deathStarHealth = deathStarHealth - attackDMG;
  170. System.out.println("The death star has " + deathStarHealth + " health left.");
  171. } else if (anotherAttackDecision == 2) {
  172.  
  173. } else if (anotherAttackDecision == 3) {
  174.  
  175. Scanner areYouSure = new Scanner(System.in);
  176. System.out.println("Are you sure you want to surrender? Y/N");
  177. if (areYouSure.nextLine().equalsIgnoreCase("Y")) {
  178. System.out.println("Activated the getaway ship!");
  179. break;
  180. } else if (areYouSure.nextLine().equalsIgnoreCase("N")) {
  181. System.out.println("Cancelled the getway.");
  182. }
  183. } else if (anotherAttackDecision == 4) {
  184. System.out.println("Your fleet has " + imperialFleetHealth + " health left.");
  185. System.out.println("The death star has " + deathStarHealth + " health left.");
  186. }
  187. }
  188.  
  189. }
  190.  
  191. }
  192.  
  193. else if (initiateAttackDecision == 2) {
  194. System.out.println("Attack canceled.");
  195. }
  196.  
  197. else {
  198. System.out.println("Invalid decision.");
  199. }
  200.  
  201. } else if (secondFleetChoice == 2) {
  202. System.out.println("You have chosen the Dark Fleet.");
  203. }
  204.  
  205. else if (secondFleetChoice == 3) {
  206.  
  207. System.out.println("You have chosen the Rebel Fleet.");
  208. } else {
  209. System.out.println("Invalid fleet number.");
  210. }
  211. }
  212.  
  213. } else {
  214. System.out.println("Invalid fleet number.");
  215. }
  216. }
  217.  
  218. }
  219. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement