Spicyninja09

Untitled

Apr 14th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.05 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class WWTBAM {
  4. public static void main (String[]args) {
  5. Scanner sc= new Scanner (System.in);
  6. int lifeline1=1;//to check if the user has used the lifeline
  7. int lifeline2;// to determine which answer is chosen by the computer
  8. int fiftyfifty=1;//to check if fifty fifty has been used
  9. int ff1,ff2;// to determine whichanswer will appear before another
  10. int audience=1;//to check if ask the audience has been used
  11. int wage=0;//to calculate the ending wage
  12. int streak=1;//this will be turned to 0 and the game will be over if the useer enters the wrong answer
  13. int rand=1;//to randomize questions
  14. int audRand=0;
  15. int count=0;
  16. String input,quest,ans,name,input2;
  17. int [] aud=new int[4];
  18. int [] quests=new int[16];//for each question
  19. int [] rands=new int [16];//for the program to not repeat questions
  20. int [] wages=new int [14];
  21. String [] words=new String[4];//for each inidividual answer
  22.  
  23. /*
  24. * Variable Initialization
  25. */
  26. for (int i =0; i<quests.length;i+=1){
  27. quests[i] =1;
  28. }
  29. for (int i =0; i<rands.length;i+=1){
  30. rands[i] =0;
  31. }
  32. ans="";
  33. quest="";
  34. ff1=-1;
  35. ff2=-1;
  36. wages[0]=0;
  37. wages[1]=100;
  38. wages[2]=200;
  39. wages[3]=500;
  40. wages[4]=1000;
  41. wages[5]=2000;
  42. wages[6]=5000;
  43. wages[7]=10000;
  44. wages[8]=20000;
  45. wages[9]=50000;
  46. wages[10]=100000;
  47. wages[11]=200000;
  48. wages[12]=500000;
  49. wages[13]=1000000;
  50. /*
  51. * End of initialization
  52. */
  53. System.out.println ("Welcome to Who wants to be a Millionaire!");
  54. System.out.println ("The objective of the game is to answer trivia questions to earn up to $1000000");
  55. System.out.println("If you get the question wrong, you will lose and your wage will be your last check point if you earned any");
  56. System.out.println ("Today's subject will be Lord of the Rings");
  57. System.out.println ("Please enter your name");
  58. name=sc.nextLine();//Name for the final wage at the end
  59. while (wage<13) {
  60. if (wage<5) {
  61. rand = (int)(Math.random() * 6) +1;//Easy difficulty questions
  62. } else if (wage>=5 && wage <9){
  63. rand = (int)(Math.random() * 6) +7;//Medium difficulty questions
  64. }else if (wage>=9 &&wage <12){
  65. rand = (int)(Math.random() *4) +12;//Hard difficulty questions
  66. }else if (wage==12){
  67. rand=16;//Final question
  68. }
  69. /*
  70. * For each question I initialized the same 6 variables over and over
  71. */
  72. if (rand==1){
  73. ans= "A";
  74. quest= "What is the name of the wizard accompanying the Fellowship of the Ring?";
  75. words[0]="A. Gandalf";//The array is to help
  76. words[1]="B. Dumbledore";
  77. words[2]="C. Harry Potter";
  78. words[3]="D. Aragorn";
  79. }else if(rand==2){
  80. ans= "B";
  81. quest= "What is the name of the main villain in the main trilogy?";
  82. words[0]="A. Zeus";
  83. words[1]="B. Sauron";
  84. words[2]="C. Palpatine";
  85. words[3]="D. Cthulhu";
  86. }else if (rand==3){
  87. ans= "A";
  88. quest= "What is the name of Frodo’s village in the Fellowship of the Ring?";
  89. words[0]="A. The Shire";
  90. words[1]="B. The Village";
  91. words[2]="C. Mordor";
  92. words[3]="D. Rivendell";
  93. }else if (rand ==4){
  94. ans= "C";
  95. quest= "What are the names of the nine commanders that Sauron leads?";
  96. words[0]="A. Ghosts";
  97. words[1]="B. Death Eaters";
  98. words[2]="C. Nazgul";
  99. words[3]="D. Fellbeasts";
  100. }else if (rand==5){
  101. ans= "B";
  102. quest= "What is the name of the kingdom that Denethor rules during the Return of the King?";
  103. words[0]="A. Minas Tirith";
  104. words[1]="B. Gondor";
  105. words[2]="C. Boromir";
  106. words[3]="D. Faramir";
  107. }else if (rand==6){
  108. ans= "D";
  109. quest= "Who was the wizard that served under Sauron during the War of the Ring?";
  110. words[0]="A. Gandalf";
  111. words[1]="B. Frodo";
  112. words[2]="C. Elrond";
  113. words[3]="D. Saruman";
  114. }else if (rand==7){
  115. ans= "C";
  116. quest= "What is the name of Gandalf's sword?";
  117. words[0]="A. Sting";
  118. words[1]="B. Gurthang";
  119. words[2]="C. Glamdring";
  120. words[3]="D. Anglachel";
  121. }else if (rand==8){
  122. ans= "D";
  123. quest= "Finish the quote: 'One Ring to rule them all, One Ring to find them, One Ring to bring them all and";
  124. words[0]="A. Mordor shall blind them";
  125. words[1]="B. No man shall grind them";
  126. words[2]="C. Sauron shall bind them";
  127. words[3]="D. In the darkness bind them";
  128. }else if (rand==9){
  129. ans= "A";
  130. quest= "Who directed the Lord of the Rings Trilogy?";
  131. words[0]="A. Peter Jackson";
  132. words[1]="B. Steven Spielberg";
  133. words[2]="C. James Gunn";
  134. words[3]="D. Viggo Mortensen";
  135. }else if (rand==10){
  136. ans= "C";
  137. quest= "What was Gollum's original name before being corrupted by the power of the ring?";
  138. words[0]="A. Deagol";
  139. words[1]="B. Meriadoc";
  140. words[2]="C. Smeagol";
  141. words[3]="D. Beren";
  142. }else if (rand==11){
  143. ans= "B";
  144. quest= "What is the name of the book about the Lord of the Rings Franchise that was published after J.R.R. Tolkien(the author) died?";
  145. words[0]="A. The Hobbit";
  146. words[1]="B. Silmarilion";
  147. words[2]="C. Beren and Luthien";
  148. words[3]="D. The Adventures of Tom Bombadil";
  149. }else if (rand==12){
  150. ans= "B";
  151. quest= "What is the name of the immortal wizards that include Gandalf and Saruman?";
  152. words[0]="A. Valar";
  153. words[1]="B. Istar";
  154. words[2]="C. Ainur";
  155. words[3]="D. Maiar";
  156. }else if (rand==13){
  157. ans= "C";
  158. quest= "Who is the creator and god of Middle-Earth??";
  159. words[0]="A. Melkor";
  160. words[1]="B. Varda";
  161. words[2]="C. Eru Illuvitar";
  162. words[3]="D. Gandalf";
  163. }else if (rand==14){
  164. ans= "B";
  165. quest= "What is the name of Beren's Lover who sacrifices herself to be with him?";
  166. words[0]="A. Lorien";
  167. words[1]="B. Luthien";
  168. words[2]="C. Galadriel";
  169. words[3]="D. Feanor";
  170. }else if (rand==15){
  171. ans= "A";
  172. quest= "What three swords were found in the Troll's cave in 'The Hobbit'?";
  173. words[0]="A. Orcist,Sting, and Glamdring";
  174. words[1]="B. Narsil,Glamdring, and Hadhafang";
  175. words[2]="C. Sting,Anduil, and the White Knife of Legolas";
  176. words[3]="D. Aeglos,Orcrist, and Sting";
  177. }else if (rand==16){
  178. ans= "D";
  179. quest= "In the prophesized final battle (Dagor Dagorath), who is the man who will finally finish off Morgoth forever?";
  180. words[0]="A. Tulkas";
  181. words[1]="B. Earendil";
  182. words[2]="C. Eonwe";
  183. words[3]="D. Turin Turambar";
  184. }
  185. rands[rand-1]+=1;//if the question has been asked once,it will not be asked again
  186. if (rands[rand-1]==1) {//if the question has not been asked
  187. count+=1;
  188. System.out.print(count +". ");
  189. System.out.println (quest);//outputting the question and answers
  190. System.out.println (words[0]);
  191. System.out.println (words[1]);
  192. System.out.println (words[2]);
  193. System.out.println (words[3]);
  194. if (lifeline1==1) {
  195. System.out.println ("1. Lifeline ");
  196. } if(fiftyfifty==1) {
  197. System.out.println ("2. Fifty Fifty ");
  198. } if(audience==1) {
  199. System.out.println ("3. Ask the audience ");
  200. }
  201. while (true){
  202. input=sc.nextLine();
  203. if (input.equalsIgnoreCase("a")||input.equalsIgnoreCase("b")||input.equalsIgnoreCase("c")||input.equalsIgnoreCase("d")) {//if user inputs a,b,c, or d
  204. if (input.equalsIgnoreCase(ans)){//if the answer is correct
  205. wage +=1;
  206. System.out.println ("Correct!");
  207. }else {//the 3 wrong options
  208. streak =0;
  209. System.out.println ("Incorrect");
  210. }
  211. break;//the user validation will end
  212. } else if (input.equals("1")) {//this lifeline has an 80% chance of being correct, and chooses a random wrong answer if is not correct
  213. if (lifeline1==1){//
  214. lifeline2 = (int)(Math.random() * 5) +1;
  215. System.out.println ("Guest:");
  216. if (lifeline2 >=2) {
  217. System.out.println ("I think the answer is "+ans);
  218. }else {
  219. if (ans.equals("A")){
  220. lifeline2 = (int)(Math.random() * 3) +1;
  221. if (lifeline2==1){
  222. System.out.println ("I think the answer is B");
  223. }else if (lifeline2==2){
  224. System.out.println ("I think the answer is C");
  225. }else if (lifeline2==3){
  226. System.out.println ("I think the answer is D");
  227. }
  228. } else if (ans.equals("B")){
  229. lifeline2 = (int)(Math.random() * 3) +1;
  230. if (lifeline2==1){
  231. System.out.println ("I think the answer is A");
  232. }else if (lifeline2==2){
  233. System.out.println ("I think the answer is C");
  234. }else if (lifeline2==3){
  235. System.out.println ("I think the answer is D");
  236. }
  237. } else if (ans.equals("C")){
  238. lifeline2 = (int)(Math.random() * 3) +1;
  239. if (lifeline2==1){
  240. System.out.println ("I think the answer is A");
  241. }else if (lifeline2==2){
  242. System.out.println ("I think the answer is B");
  243. }else if (lifeline2==3){
  244. System.out.println ("I think the answer is D");
  245. }
  246. } else if (ans.equals("D")){
  247. lifeline2 = (int)(Math.random() * 3) +1;
  248. if (lifeline2==1){
  249. System.out.println ("I think the answer is A");
  250. }else if (lifeline2==2){
  251. System.out.println ("I think the answer is B");
  252. }else if (lifeline2==3){
  253. System.out.println ("I think the answer is C");
  254. }
  255. }
  256. }
  257. lifeline1=0;
  258. }else{
  259. System.out.println ("You have already used this lifeline");
  260. }
  261. }else if (input.equals("2")) {//This lifeline outputs 2 final options, the correct one and one incorrect answer
  262. if (fiftyfifty==1) {
  263. if (ans.equalsIgnoreCase("A")){
  264. ff2=0;
  265. ff1 = (int)(Math.random() * 3) +1;
  266. } else if (ans.equalsIgnoreCase("B")){
  267. ff2=1;
  268. ff1 = (int)(Math.random() * 4);
  269. if (ff1==ff2){
  270. while (ff1==ff2){
  271. ff1 = (int)(Math.random() * 4);
  272. }
  273. }
  274. } else if (ans.equalsIgnoreCase("C")){
  275. ff2=2;
  276. ff1 = (int)(Math.random() * 4);
  277. if (ff1==ff2){
  278. while (ff1==ff2){
  279. ff1 = (int)(Math.random() * 4);
  280. }
  281. }
  282. } else if (ans.equalsIgnoreCase("D")){
  283. ff2=3;
  284. ff1 = (int)(Math.random() * 3);
  285. }
  286. if (ff2>ff1){
  287. System.out.println(quest);
  288. System.out.println(words[ff1]);
  289. System.out.println(words[ff2]);
  290. } else if (ff1>ff2){
  291. System.out.println(quest);
  292. System.out.println(words[ff2]);
  293. System.out.println(words[ff1]);
  294. }
  295. fiftyfifty=0;
  296. }else {
  297. System.out.println("You have already used this lifeline");
  298. }
  299. }else if (input.equals("3")){//this lifeline is completely random and has no positive effect on the user's choices
  300. if (audience==1){
  301. while (aud[0]+aud[1]+aud[2]+aud[3]<100){
  302. audRand = (int)(Math.random() * 4);
  303. aud[audRand]+=1;
  304. }
  305. for (int i=0;i<=3;i+=1){
  306. System.out.print(aud[i] +"% of the audience voted for ");
  307. if (i==0){
  308. System.out.println ("A");
  309. }else if (i==1){
  310. System.out.println ("B");
  311. }else if (i==2){
  312. System.out.println ("C");
  313. }else if (i==3){
  314. System.out.println ("D");
  315. }
  316. audience=0;
  317. }
  318. } else {
  319. System.out.println("You have already used this lifeline");
  320. }
  321. }else{ //if the user inputs anything other than a,b,c,d,1,2,or 3
  322. System.out.println ("Invalid");
  323. }
  324. }
  325. if (streak==0){//is the user gets the wrong answer
  326. break;
  327. }
  328. }
  329. if (wage==5||wage==9){
  330. System.out.println("Congratulations, you reached a checkpoint!");
  331. }
  332. System.out.println("Your current wage is $" +wages[wage]);
  333. if (wage<13){
  334. System.out.println("Would you like to walk away?(yes or no)");
  335. while (true) {
  336. input2=sc.nextLine();
  337. if (input2.equalsIgnoreCase("yes")){
  338. break;
  339. }else if (input2.equalsIgnoreCase("no")){
  340. break;
  341. }else{
  342. System.out.println("Invalid");
  343. }
  344. }
  345. if (input2.equals("yes")){
  346. break;
  347. }
  348. }
  349. }
  350. if (streak==0){
  351. if (wage<5){
  352. wage=0;
  353. }else if (wage>=5&&wage<9){
  354. wage=5;
  355. }else if (wage>=9){
  356. wage=9;
  357. }
  358. }
  359. System.out.println ("Congratulations, " + name + ", you earned $" +wages[wage]);
  360. }
Advertisement
Add Comment
Please, Sign In to add comment