Yehosua_Selah

Rock, Paper, Scissors REvolution! by Schamanu..Refined by me

Aug 6th, 2015
394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.87 KB | None | 0 0
  1. alert("Welcome to Rock, Paper, Scissors, Lizard, Spock\n\t\t*Programmed by Schamanu*\n\t\t Refined By: Yehosua Selah");
  2. var userName = prompt("Please enter your name");
  3. userName = userName.charAt(0).toUpperCase() + userName.slice(1);
  4. alert("Nice Name.");
  5.  
  6.  
  7. alert(userName + ", " + "let's play Rock, Paper, Scissors, Lizard or Spock game!");
  8. alert("Are you ready" + " " + userName + "?");
  9.  
  10. var newUserName = prompt("Please create your new username in the game!");
  11. newUserName = newUserName.charAt(0).toUpperCase() + newUserName.slice(1);
  12. userName = newUserName;
  13.  
  14. alert("Cool Name!");
  15. alert("Let's get started!");
  16.  
  17.  
  18. var foeName = prompt("Create the name of your enemy!");
  19. foeName = foeName.charAt(0).toUpperCase() + foeName.slice(1);
  20.  
  21. alert("The game starts with" + " " + newUserName + " vs. " + foeName);
  22. alert("Let the game begin!");
  23. /*Variables and game setup*/
  24. var played = 0;
  25. var score1 = 0;
  26. var score2 = 0;
  27. var times = Number(prompt("How many times do you want to play against" + " " + foeName + ", " + userName + "?"));
  28. if (isNaN(times)) {
  29. times = 1;
  30. alert("\nInvalid input!\nNumber of rounds set to 1!");
  31. }
  32. else
  33. {
  34. alert(userName + ", " + "you" + " " + "chose to play "+ times +" times against" + " " + foeName + "!");
  35.  
  36. //FUNCTION COMPARING CHOICES
  37. var compare=function(choice1,choice2) {
  38. if (choice1===choice2) {
  39. alert("Its a tie. Choose again" + " " + userName + "!");
  40. }
  41. else if (choice1==="rock") {
  42. if (choice2==="scissors") {
  43. alert("Rock crushes scissors!");
  44. alert(userName + " " + "wins this round!");
  45. score1+=1;
  46. }
  47. else if (choice2==="paper") {
  48. alert("Paper covers rock!");
  49. alert(foeName + " " + "wins this round!");
  50. score2+=1;
  51. }
  52. else if (choice2==="spock") {
  53. alert("Spock vaporizes rock!");
  54. alert(foeName + " " + "wins this round.");
  55. score2+=1;
  56. }
  57. else { // choice2=lizard
  58. alert("Rock crushes lizard!");
  59. alert(userName + " " + "wins this round!");
  60. score1+=1;
  61. }
  62. }
  63. else if (choice1==="paper") {
  64. if (choice2==="rock") {
  65. alert("Paper covers rock.");
  66. alert(userName + " " + "wins this round!");
  67. score1+=1;
  68. }
  69. else if (choice2==="scissors") {
  70. alert("Scissors cut paper!");
  71. alert(foeName + " " + "wins this round.");
  72. score2+=1;
  73. }
  74. else if (choice2==="spock") {
  75. alert("Paper disproves Spock!");
  76. alert(userName + " " + "wins this round.");
  77. score1+=1;
  78. }
  79. else { // choice2=lizard
  80. alert("Lizard eats paper!");
  81. alert(foeName + " " + "wins this round!");
  82. score2+=1;
  83. }
  84. }
  85. else if (choice1==="scissors") {
  86. if (choice2==="rock") {
  87. alert("Rock crushes scissors!");
  88. alert(foeName + " " + "wins this round!");
  89. score2+=1;
  90. }
  91. else if (choice2==="paper") {
  92. alert("Scissors cut paper!");
  93. alert(userName + " " + "wins this round!");
  94. score1+=1;
  95. }
  96. else if (choice2==="spock") {
  97. alert("Spock smashes scissors!");
  98. alert(foeName + " " + "wins this round!");
  99. score2+=1;
  100. }
  101. else { // choice2=lizard
  102. alert("Scissors decapitate lizard!");
  103. alert(userName + " " + "wins this round!");
  104. score1+=1;
  105. }
  106. }
  107. else if (choice1==="spock") {
  108. if (choice2==="rock") {
  109. alert("Spock vaporizes rock!");
  110. alert(userName + " " + "wins this round!");
  111. score1+=1;
  112. }
  113. else if (choice2==="paper") {
  114. alert("Paper disproves Spock.");
  115. alert(foeName + " " + "wins this round!");
  116. score2+=1;
  117. }
  118. else if (choice2==="scissors") {
  119. alert("Spock smashes scissors!");
  120. alert(userName + " " + "wins this round!");
  121. score1+=1;
  122. }
  123. else { // choice2=lizard
  124. alert("Lizard poisons Spock.");
  125. alert(foeName + " " + "wins this round!");
  126. score2+=1;
  127. }
  128. }
  129. else if (choice1==="lizard") {
  130. if (choice2==="rock") {
  131. alert("Rock crushes lizard!");
  132. alert(foeName + " " + "wins this round!");
  133. score2+=1;
  134. }
  135. else if (choice2==="paper") {
  136. alert("Lizard eats paper!");
  137. alert(userName + " " + "wins this round!");
  138. score1+=1;
  139. }
  140. else if (choice2==="scissors") {
  141. alert("Scissors decapitate lizard!");
  142. alert(foeName + " " + "wins this round!");
  143. score2+=1;
  144. }
  145. else { // choice2=spock
  146. alert("Lizard poisons Spock!");
  147. alert(userName + " " + "wins this round!");
  148. score1+=1;
  149. }
  150. }
  151. };
  152. /*END OF FUNCTION*/
  153.  
  154. do { // repeats game x times, as specified by player
  155. played += 1;
  156. do { // repeats code as long as game is tied
  157. do { // repeats code until player enters proper input
  158. if (userChoice==="rules") {
  159. alert("\nRules:\nScissors cuts paper. Paper covers rock.");
  160. alert("Rock crushes lizard. Lizard poisons Spock.\nSpock smashes scissors. Scissors decapitates lizard.");
  161. alert("Lizard eats paper. Paper disproves Spock.\nSpock vaporizes rock. Rock crushes scissors.");
  162. }
  163. var userChoice = prompt(newUserName + ", " + "do you choose rock, paper, scissors, lizard or spock?","Type <rules> to see the rules.").toLowerCase();
  164. } while (userChoice !="rock" && userChoice !="paper" && userChoice !="scissors" && userChoice !="spock" && userChoice !="lizard")
  165.  
  166.  
  167.  
  168. var computerChoice = Math.random();
  169. if (computerChoice < 0.2) {
  170. computerChoice = "rock";
  171. } else if (computerChoice <= 0.4) {
  172. computerChoice = "paper";
  173. } else if (computerChoice <=0.6) {
  174. computerChoice = "scissors";
  175. } else if (computerChoice <=0.8) {
  176. computerChoice = "spock";
  177. }
  178. else {
  179. computerChoice = "lizard";
  180. }
  181.  
  182. if (times >1) {
  183. alert("\nRound "+ played+"/"+times);
  184. }
  185. alert(" " + userName + " " + "\nChose: "+ userChoice);
  186. alert(" " + foeName + "\nChose: " + computerChoice);
  187.  
  188. compare(userChoice,computerChoice);
  189. } while (userChoice === computerChoice);
  190. } while (played <= times-1); // times minus 1 because its a do-loop
  191.  
  192. if (times >1) {
  193. alert("\nFinal Score: "+ userName + " gains a total score of " + score1 + " vs. " + foeName + " who gains a total score of " + score2);
  194. if (score1>score2) {
  195. alert(userName + " " + "is the overall winner!");
  196. alert("\t\tCongratulations" + " " + userName + "!" + "\nYou're the King of Rock, Paper, Scissors, Lizard and Spock!\n\t\tThanks for playing!!!");
  197. }
  198. else if (score2>score1) {
  199. alert(foeName + " " + "is the overall winner!");
  200. alert("Better luck next time" + " " + userName + "!" + "\n Thank you for playing!");
  201. }
  202. else {
  203. alert("Final game results:\n\tDraw!");
  204. }
  205. }
  206. }
Advertisement
Add Comment
Please, Sign In to add comment