Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- alert("Welcome to Rock, Paper, Scissors, Lizard, Spock\n\t\t*Programmed by Schamanu*\n\t\t Refined By: Yehosua Selah");
- var userName = prompt("Please enter your name");
- userName = userName.charAt(0).toUpperCase() + userName.slice(1);
- alert("Nice Name.");
- alert(userName + ", " + "let's play Rock, Paper, Scissors, Lizard or Spock game!");
- alert("Are you ready" + " " + userName + "?");
- var newUserName = prompt("Please create your new username in the game!");
- newUserName = newUserName.charAt(0).toUpperCase() + newUserName.slice(1);
- userName = newUserName;
- alert("Cool Name!");
- alert("Let's get started!");
- var foeName = prompt("Create the name of your enemy!");
- foeName = foeName.charAt(0).toUpperCase() + foeName.slice(1);
- alert("The game starts with" + " " + newUserName + " vs. " + foeName);
- alert("Let the game begin!");
- /*Variables and game setup*/
- var played = 0;
- var score1 = 0;
- var score2 = 0;
- var times = Number(prompt("How many times do you want to play against" + " " + foeName + ", " + userName + "?"));
- if (isNaN(times)) {
- times = 1;
- alert("\nInvalid input!\nNumber of rounds set to 1!");
- }
- else
- {
- alert(userName + ", " + "you" + " " + "chose to play "+ times +" times against" + " " + foeName + "!");
- //FUNCTION COMPARING CHOICES
- var compare=function(choice1,choice2) {
- if (choice1===choice2) {
- alert("Its a tie. Choose again" + " " + userName + "!");
- }
- else if (choice1==="rock") {
- if (choice2==="scissors") {
- alert("Rock crushes scissors!");
- alert(userName + " " + "wins this round!");
- score1+=1;
- }
- else if (choice2==="paper") {
- alert("Paper covers rock!");
- alert(foeName + " " + "wins this round!");
- score2+=1;
- }
- else if (choice2==="spock") {
- alert("Spock vaporizes rock!");
- alert(foeName + " " + "wins this round.");
- score2+=1;
- }
- else { // choice2=lizard
- alert("Rock crushes lizard!");
- alert(userName + " " + "wins this round!");
- score1+=1;
- }
- }
- else if (choice1==="paper") {
- if (choice2==="rock") {
- alert("Paper covers rock.");
- alert(userName + " " + "wins this round!");
- score1+=1;
- }
- else if (choice2==="scissors") {
- alert("Scissors cut paper!");
- alert(foeName + " " + "wins this round.");
- score2+=1;
- }
- else if (choice2==="spock") {
- alert("Paper disproves Spock!");
- alert(userName + " " + "wins this round.");
- score1+=1;
- }
- else { // choice2=lizard
- alert("Lizard eats paper!");
- alert(foeName + " " + "wins this round!");
- score2+=1;
- }
- }
- else if (choice1==="scissors") {
- if (choice2==="rock") {
- alert("Rock crushes scissors!");
- alert(foeName + " " + "wins this round!");
- score2+=1;
- }
- else if (choice2==="paper") {
- alert("Scissors cut paper!");
- alert(userName + " " + "wins this round!");
- score1+=1;
- }
- else if (choice2==="spock") {
- alert("Spock smashes scissors!");
- alert(foeName + " " + "wins this round!");
- score2+=1;
- }
- else { // choice2=lizard
- alert("Scissors decapitate lizard!");
- alert(userName + " " + "wins this round!");
- score1+=1;
- }
- }
- else if (choice1==="spock") {
- if (choice2==="rock") {
- alert("Spock vaporizes rock!");
- alert(userName + " " + "wins this round!");
- score1+=1;
- }
- else if (choice2==="paper") {
- alert("Paper disproves Spock.");
- alert(foeName + " " + "wins this round!");
- score2+=1;
- }
- else if (choice2==="scissors") {
- alert("Spock smashes scissors!");
- alert(userName + " " + "wins this round!");
- score1+=1;
- }
- else { // choice2=lizard
- alert("Lizard poisons Spock.");
- alert(foeName + " " + "wins this round!");
- score2+=1;
- }
- }
- else if (choice1==="lizard") {
- if (choice2==="rock") {
- alert("Rock crushes lizard!");
- alert(foeName + " " + "wins this round!");
- score2+=1;
- }
- else if (choice2==="paper") {
- alert("Lizard eats paper!");
- alert(userName + " " + "wins this round!");
- score1+=1;
- }
- else if (choice2==="scissors") {
- alert("Scissors decapitate lizard!");
- alert(foeName + " " + "wins this round!");
- score2+=1;
- }
- else { // choice2=spock
- alert("Lizard poisons Spock!");
- alert(userName + " " + "wins this round!");
- score1+=1;
- }
- }
- };
- /*END OF FUNCTION*/
- do { // repeats game x times, as specified by player
- played += 1;
- do { // repeats code as long as game is tied
- do { // repeats code until player enters proper input
- if (userChoice==="rules") {
- alert("\nRules:\nScissors cuts paper. Paper covers rock.");
- alert("Rock crushes lizard. Lizard poisons Spock.\nSpock smashes scissors. Scissors decapitates lizard.");
- alert("Lizard eats paper. Paper disproves Spock.\nSpock vaporizes rock. Rock crushes scissors.");
- }
- var userChoice = prompt(newUserName + ", " + "do you choose rock, paper, scissors, lizard or spock?","Type <rules> to see the rules.").toLowerCase();
- } while (userChoice !="rock" && userChoice !="paper" && userChoice !="scissors" && userChoice !="spock" && userChoice !="lizard")
- var computerChoice = Math.random();
- if (computerChoice < 0.2) {
- computerChoice = "rock";
- } else if (computerChoice <= 0.4) {
- computerChoice = "paper";
- } else if (computerChoice <=0.6) {
- computerChoice = "scissors";
- } else if (computerChoice <=0.8) {
- computerChoice = "spock";
- }
- else {
- computerChoice = "lizard";
- }
- if (times >1) {
- alert("\nRound "+ played+"/"+times);
- }
- alert(" " + userName + " " + "\nChose: "+ userChoice);
- alert(" " + foeName + "\nChose: " + computerChoice);
- compare(userChoice,computerChoice);
- } while (userChoice === computerChoice);
- } while (played <= times-1); // times minus 1 because its a do-loop
- if (times >1) {
- alert("\nFinal Score: "+ userName + " gains a total score of " + score1 + " vs. " + foeName + " who gains a total score of " + score2);
- if (score1>score2) {
- alert(userName + " " + "is the overall winner!");
- alert("\t\tCongratulations" + " " + userName + "!" + "\nYou're the King of Rock, Paper, Scissors, Lizard and Spock!\n\t\tThanks for playing!!!");
- }
- else if (score2>score1) {
- alert(foeName + " " + "is the overall winner!");
- alert("Better luck next time" + " " + userName + "!" + "\n Thank you for playing!");
- }
- else {
- alert("Final game results:\n\tDraw!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment