dannycraze

JavaScript text game

Jul 10th, 2013
52
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var userLevel = 0;
  2. var userExp = 0;
  3. var steps = 0;
  4. var userLocation = "Castle";
  5. var userName = prompt( "Type your name young adventurer" );
  6. var userClass = prompt( "What is your class? | Elf | Wizard | Warrior |                                          (don't select the check box!)");
  7. var userClassProp = new Array();
  8. var userClassCurr = new Array();
  9. var userClassLevel = new Array();
  10. var userPos = new Array();
  11.  
  12. var enemyType = new Array();
  13. /*
  14. [0] = (Max) Health
  15. [1] = Speed
  16. [2] = (Max) Armor
  17. [3] = Attack
  18. [4] = (Max) Magic if applicable
  19. [5] = # of Health Potions
  20. [6] = Money
  21. */
  22. var Enemy_Names ("Goblin","Skeleton","Orc","Dark Knight","Demon","Dragon","Gollamon");
  23. /*[0] = Goblin
  24. [1] = Skeleton
  25. [2] = Orc
  26. [3] = Dark Knight
  27. [4] = Demon
  28. [5] = Dragon
  29. [6] = Gollamon
  30. */
  31.  
  32. var classText = "Human";
  33.  
  34. if (userClass === "Elf") {
  35.     classText = "Elf: You are a fast runner, have Medium Armor, and a Medium Blade";
  36.     userClassProp[0] = 50;
  37.     userClassProp[1] = 20;
  38.     userClassProp[3] = 10;
  39.     userClassProp[5] = 3;
  40. } else if (userClass === "Wizard") {
  41.     classText = "Wizard: You have Lite Armor, and a Magic Staff which can heal you";
  42.     userClassProp[0] = 40;
  43.     userClassProp[1] = 13;
  44.     userClassProp[3] = 10;
  45.     userClassProp[4] = 10;
  46. } else if (userClass === "Warrior") {
  47.     classText: "Warrior: You have Thick Armor, and a Heavy Sword that does high damage";
  48.     userClassProp[0] = 40;
  49.     userClassProp[1] = 10;
  50.     userClassProp[3] = 15;
  51.     userClassProp[5] = 2;
  52. }
  53. userClassCurr[0] = userClassProp[0];
  54.  
  55. confirm( "Wise choice, " + userName + " you are a:                                                                  " + classText );
  56.  
  57. var Quit = 0;
  58. var Location = new Array();
  59. /* N,E,S,W*/
  60. Location[0] = 10;
  61. Location[1] = 5;
  62. Location[2] = 0;
  63. Location[3] = 0;
  64.  
  65. var Message1 = "The King is ";
  66. var Obstacle = "Wall";
  67. var Hit = 0;
  68. var Move = "";
  69.  
  70. while (Quit === 0) {
  71.     Move = prompt( "You are in the " + userLocation +". " + Message1 + Location [0] + " North, " + Location[1] + " East, " + Location[2] + " South and " + Location[3] + " west steps away." + "                                                                        Move which direction? | North | East | South | West |");
  72.     Hit = Math.floor((Math.random()*8)+1);
  73.     if ( Move === "North" && Hit!=1) {
  74.         steps++;
  75.         if (Location[0]===0) {
  76.             Location[2]++;
  77.         } else {
  78.             Location[0]--;
  79.         }
  80.     } else if ( Move === "East" && Hit!=1) {
  81.         steps++;
  82.         if (Location[1]===0) {
  83.             Location[3]++;
  84.         } else {
  85.             Location[1]--;
  86.         }
  87.     } else if ( Move === "South" && Hit!=1) {
  88.         steps++;
  89.         if (Location[2]===0) {
  90.             Location[0]++;
  91.         } else {
  92.             Location[2]--;
  93.         }
  94.     } else if ( Move === "West" && Hit!=1) {
  95.         steps++;
  96.         if (Location[3]===0) {
  97.             Location[1]++;
  98.         } else {
  99.             Location[3]--;
  100.         }
  101.     }
  102.     if (Hit===1) {
  103.         confirm( "There is a wall blocking your way!");
  104.     } else {
  105.         confirm( "You moved 1 step to the " + Move);
  106.     }
  107.     if (Location[0]===0 && Location[1]===0 && Location[2]===0 && Location[3]===0) Quit = 1;
  108. }
  109. confirm( "King: Welcome brave " + userClass + ", I have summoned you for a dangerous quest! My daugther has been snatched by the dark Wizard Gallomon, and won't return her to the castle. I need you to defeat his evil forces and return my fair daughter. The only way to defeat him is to collect the rare Orbs of legend and use them to power your weapon. I am trusting you on this quest. please don't fail me!");
  110. confirm( "King: The first orb is the Blue orb far away near the Ocean to the West. I will mark that on your map. If you stop in the town, they can help you find it, for a price. Or you can find it on your own.");
  111. confirm( "King: Here is a map of the kingdom, far away to the North-West is the mountains of Doom. This is where Gollamon is. Good luck fair " + userClass + " we will await your return.");
  112.  
  113. userLocation = "Outside the Castle";
  114. var wizard_string = " ";
  115. if (userClass==="Wizard") wizard_class = "Heal |";
  116. var Message1 = "The town is ";
  117. var Obstacle = "rock";
  118. var Hit = 0;
  119. var Move = "";
  120. Quit = 0;
  121. Location[0] = 20;
  122. Location[3] = 30;
  123. var Enemy_Attack_High = 10;
  124. var Enemy_Attack_Low = 4;
  125. var Enemy_Health_High = 30;
  126. var Enemy_Health_Low = 20;
  127. var Enemy_Speed_High = 20;
  128. var Enemy_Speed_Low: 8;
  129. var Enemy_Type = 0;
  130. var Enemy_Hit = 0;
  131. var Battle_Option = " ";
  132. var Enemy = new Array();
  133. var damage = 0;
  134. var Enemy_Turn = 1;
  135.  
  136. while (Quit === 0) {
  137.     Move = prompt( "You are in the " + userLocation +". " + Message1 + Location [0] + " North, " + Location[1] + " East, " + Location[2] + " South and " + Location[3] + " west steps away." + "                                                                        Move which direction? | North | East | South | West |");
  138.     Hit = Math.floor((Math.random()*8)+1);
  139.     if (Hit!= 1) Enemy_Hit = Math.floor((Math.random()*8+1);
  140.     if ( Move === "North" && Hit!=1) {
  141.         steps++;
  142.         if (Location[0]===0) {
  143.             Location[2]++;
  144.         } else {
  145.             Location[0]--;
  146.         }
  147.     } else if ( Move === "East" && Hit!=1) {
  148.         steps++;
  149.         if (Location[1]===0) {
  150.             Location[3]++;
  151.         } else {
  152.             Location[1]--;
  153.         }
  154.     } else if ( Move === "South" && Hit!=1) {
  155.         steps++;
  156.         if (Location[2]===0) {
  157.             Location[0]++;
  158.         } else {
  159.             Location[2]--;
  160.         }
  161.     } else if ( Move === "West" && Hit!=1) {
  162.         steps++;
  163.         if (Location[3]===0) {
  164.             Location[1]++;
  165.         } else {
  166.             Location[3]--;
  167.         }
  168.     }
  169.     if (Hit===1) {
  170.         confirm( "There is a wall blocking your way!");
  171.     } else {
  172.         confirm( "You moved 1 step to the " + Move);
  173.     }
  174.     if (Enemy_Hit === 1) {
  175.         Enemy[0] = Math.floor((Math.random()* Enemy_Attack_High)+Enemy_Attack_Low);
  176.         Enemy[1] = Math.floor((Math.random()* Enemy_Speed_High)+Enemy_Speed_Low);
  177.         Enemy[2] = Math.floor((Math.random()* Enemy_Health_High)+Enemy_Health_Low);
  178.         confirm( "You've been ambushed by a " + Enemy_Names[0] + "!!" );   
  179.         while (Enemy_Hit===1) {
  180.             Enemy_Turn = 1;
  181.             Battle_Choice = prompt( Enemy_Name[0] + ": | Speed: " + Enemy[1] + " | Attack: " + Enemy[0] + " | Health: " + Enemy[2] + " |" + "                                                       " + userName + ": | Speed: " + userClassProp[1] + " | Attack: " + userClassProp[3] + " | Health: " + userClassCurr[0] + " |" + "                                                  " + "Choose: | Attack | Run | " + wizard_string;
  182.             if (Battle_Choice === "Run" && userClassProp[1] > Enemy[1]) {
  183.                 confirm( "You escaped!");
  184.                 Enemy_Hit = 0; 
  185.             } else if (Battle_Choice === "Run") {
  186.                 confirm( "Can't escape!");
  187.                 Enemy_Turn = 0;
  188.             }
  189.             if (Battle_Choice === "Attack") {
  190.                 damage = Math.floor((Math.random()*userClassProp[3])+userClassProp[3]/5;
  191.                 Enemy[2] = Enemy[2] - damage;
  192.                 confirm( "You attacked the " + Enemy_Name[0] + ". You did " + damage + "!";
  193.                 if (Enemy[2]<0) {
  194.                     confirm( "You killed the " + Enemy[0] + "!");
  195.                     Enemy_Hit = 0;
  196.                 }
  197.             }
  198.             if (Battle_Choice === "Magic" &&  userClassProp[5]!=0) {
  199.                 userClassProp[4] = userClassProp[4] - 5;
  200.                 userClassCurr[0] = userClassCurr[0] + 10;  
  201.             } else if (Battle_Choice === "Magic" && userCLassProp[5]===0) {
  202.                 confirm( "You have no more Magic!" );
  203.                 Enemy_Turn = 0;
  204.             }
  205.             if (Enemy_Turn===1) {
  206.                 userClassCurr[0] = userClassCurr[0] - Enemy[0];
  207.                 confirm( Enemy_Names[0] + " attacked! " + Enemy_Names[0] + " did " + Enemy[0] + " damage!");
  208.             }
  209.     }
  210.     if (Location[0]===0 && Location[1]===0 && Location[2]===0 && Location[3]===0) Quit = 1;
  211. }
  212.  
  213.  
  214.  
  215. }
RAW Paste Data