Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.92 KB | None | 0 0
  1. <!DOCTYPE>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8"></meta>
  5. <!--JQUERY files-->
  6. <script type="text/javascript" src="C:UsersRyanDocumentsWebjquery-1.11.1.min.js"></script>
  7. <!---Javascript--->
  8. <script type="text/javascript" src="C:UsersRyanDocumentsWeb_ProjectsTemplatetemp_1.js">
  9. </script>
  10. <!---CSS--->
  11. <link rel="stylesheet" type="text/css" href="C:UsersRyanDocumentsWeb_ProjectsTemplatetemp.css">
  12. </link>
  13. <!---WEB FONTS-->
  14. <link rel='stylesheet' type='text/css' href='http://fonts.googleapis.com/css? family=Roboto:400,900,100,100italic'>
  15. <title></title>
  16. </head>
  17. <body>
  18. <div id='container'>
  19. <div id='player'>
  20. <div id='pcont'>
  21. <label for="name">Name:</label>
  22. <p id='name'></p><br/>
  23. <label for="hp">Health:</label>
  24. <p id='hp'></p><br/>
  25. <label for="ep">Energy:</label>
  26. <p id='ep'></p><br/>
  27. <label for="lvl">Level:</label>
  28. p id='lvl'></p><br/><br/>
  29. <button id='explore'>Explore</button>
  30. <button id='rest'>Rest</button>
  31. <button id='run'>Run</button>
  32. <button id='attack'>Attack</button>
  33. <button id='quit'>Quit</button>
  34. </div>
  35. </div>
  36. <div id='enemy'>
  37. <div id="econt">
  38. <label for="ename">Name:</label>
  39. <p id='ename'></p><br/>
  40. <label for="ehp">Health:</label>
  41. <p id='ehp'></p><br/>
  42. </div>
  43. </div>
  44. </div>
  45. <h1 id='state'></h1>
  46. </body>
  47. </html>
  48.  
  49. $(document).ready(function () {
  50. var m = Math;
  51. //Character constructor where the player and enemies will receive their //attributes from.
  52. function Character() {
  53. this.name = "";
  54. this.health = 1;
  55. this.max_health = 10;
  56. this.do_dmg = do_dmg;
  57.  
  58. function do_dmg(enemy) {
  59. //calculates amount of damage done by by finding the lower number between a (rand int from 0 to personal health - a rand int from 0 to enemy health) and
  60. var dmg = m.min(m.max(
  61. m.round(m.random() * this.health) - m.round(m.random() * enemy.health), 0),
  62. enemy.health);
  63. $('#hp').text(this.health);
  64. $('#ehp').text(enemy.health -= dmg);
  65. if (dmg === 0) {
  66. console.log(this.name + " evades " + enemy.name + "'s attack!");
  67. } else {
  68. console.log(this.name + " hurts " + enemy.name + " for " + dmg);
  69. return enemy.health <= 0;
  70. }
  71. }
  72. }
  73. //Create Enemies HERE
  74. var Goblin = new Character();
  75. Goblin.name = "Goblin";
  76. Goblin.health = m.floor(m.round(m.random() * 10)) + 1;
  77. Goblin.XP = 25;
  78. var Demon = new Character();
  79. Demon.name = "Demon";
  80. Demon.health = m.floor(m.round(m.random() * 10 + m.random() * 1)) + 1;
  81. Demon.XP = 50;
  82. var Dragon = new Character();
  83. Dragon.name = "Dragon";
  84. Dragon.health = m.floor(m.round(m.random() * 10 + m.random() * 2)) + 1;
  85. Dragon.XP = 100;
  86. //Load created enemies into an Array
  87. var Enemies = [Goblin, Dragon, Demon];
  88.  
  89. //Create the Player.
  90. var Player = new Character();
  91. var p = Player;
  92. p.state = "normal";
  93. p.awoken = m.round(m.random());
  94. p.name = "Ryan";
  95. p.health = 10;
  96. p.max_health = 10;
  97. p.energy = 10;
  98. p.max_energy = 10;
  99. p.XP = 0;
  100. p.level = 1;
  101. p.nextLevel = p.level + 1;
  102. p.quit = function () {
  103. console.log(this.name + " has quit.");
  104. },
  105. p.tired = function () {
  106. this.energy -= 1;
  107. $('#ep').text(this.energy);
  108. if (this.energy == 5) {
  109. console.log(this.name + ' is getting tired.');
  110. } else if (this.energy == 2) {
  111. console.log(this.name + ' is exhausted.');
  112. } else if (this.energy <= 0) {
  113. this.energy = this.max_energy;
  114. $('#ep').text(this.energy);
  115. console.log(this.name + ' passed out from exhaustion. You woke up fully refreshed.');
  116.  
  117. } else {
  118. $('#ep').text(this.energy);
  119. }
  120. },
  121. p.rest = function () {
  122. console.log(this.awoken);
  123. if (this.awoken === 0) {
  124. window.enemy = Enemies[m.floor(m.random() * Enemies.length)];
  125. window.enemy = enemy;
  126. console.log(this.name + ' is awoken by a ' + enemy.name + '!');
  127. $('#ename').text(enemy.name);
  128. $('#ehp').text(enemy.health);
  129. this.state = 'fight';
  130. $('#state').text(this.state);
  131. this.enemy_atk();
  132.  
  133. } else if (this.awoken == 1) {
  134. console.log(this.name + ' rests.');
  135. if (this.health < this.max_health) {
  136. this.health += 1;
  137. $('#hp').text(p.health);
  138. } else if (this.energy < this.max_energy) {
  139. this.energy += 1;
  140. $('#ep').text(p.energy);
  141. } else {
  142. console.log(this.name + ' slept too long.');
  143. this.energy -= 1;
  144. $('#ep').text(p.energy);
  145. }
  146. } else {
  147. console.log(this.name + 'can't rest right now');
  148. }
  149.  
  150. },
  151. p.enemy_atk = function () {
  152. if (enemy.health >= 1) {
  153. if (enemy.do_dmg(this) >= this.health) {
  154. this.health = 0;
  155. console.log(this.name + ' was killed by the ' + enemy.name);
  156. } else {
  157. $('#ehp').text(enemy.health);
  158. $('#hp').text(this.health);
  159. }
  160. } else {
  161. $('#ename').text('');
  162. $('#ehp').text('');
  163. console.log(this.name + ' killed the ' + enemy.name);
  164. console.log(this.name + ' gained ' + enemy.XP / this.level + ' EXP!');
  165. this.state = 'normal';
  166. $('#state').text(this.state);
  167. }
  168.  
  169.  
  170. },
  171. p.atk = function () {
  172. if (this.state != 'fight') {
  173. console.log(this.name + ' swings at nothing and falls.');
  174. this.tired();
  175. } else {
  176. if (this.do_dmg(enemy) >= enemy.health) {
  177. enemy.health = 0;
  178. console.log(this.name + ' killed ' + enemy.name);
  179. console.log(this.name + ' gained ' + enemy.XP / this.level + ' EXP!');
  180. $('#ename').text('');
  181. $('#ehp').text('');
  182. this.state = 'normal';
  183. $('#state').text(this.state);
  184. } else {
  185. this.do_dmg(enemy);
  186. this.enemy_atk();
  187. }
  188. }
  189. },
  190. p.giveXP = function (amount) {
  191. var XPArray = popArray;
  192. this.XP += amount;
  193.  
  194. if (this.level == 60) {
  195.  
  196. } else {
  197. if (this.XP > XPforLevel(p.nextLevel)) {
  198. this.level++;
  199. console.log('Congratulations! ' + this.name + ' has leveled up!');
  200. }
  201. }
  202.  
  203. function popArray() {
  204. array = [60];
  205. array[0] = [0];
  206. for (i = 1; i < 60; i++) {
  207. array[i] = array[i - 1] + 100 * i;
  208. }
  209. return array;
  210. }
  211.  
  212. function XPforLevel(nextLevel) {
  213. return XPArray[p.nextLevel];
  214. }
  215. };
  216.  
  217. $('#quit').click(function () {
  218. p.quit();
  219. });
  220.  
  221. $('#rest').click(function () {
  222. p.awoken = m.round(m.random());
  223. p.rest();
  224. });
  225.  
  226. $('#attack').click(function () {
  227. p.atk();
  228. });
  229.  
  230. $('#name').text(p.name);
  231. $('#hp').text(p.health);
  232. $('#ep').text(p.energy);
  233. $('#lvl').text(p.level);
  234. $('#state').text(p.state);
  235. });
  236.  
  237. #html,body
  238. {
  239. margin:0%;
  240. padding:0%;
  241. width: 100%;
  242. height: Window.innerHeight;
  243. min-height:100%;
  244. min-width:600px;
  245. max-width:2000px;
  246. font-family: 'Roboto', sans-serif;
  247. }
  248. p
  249. {
  250. display: inline-block;
  251. }
  252. #player, #enemy
  253. {
  254. width: 49.5%;
  255. height: 50%;
  256. border: 1px solid black;
  257. position: relative;
  258. float:left;
  259. }
  260. #pcont, #econt
  261. {
  262. position: absolute;
  263. top: 0.5%;
  264. left: 0.5%;
  265. width: 100%;
  266. height: 100%;
  267. line-height: 0.5em;
  268. }
  269. #container
  270. {
  271. border: solid black;
  272. height: 50%;
  273. }
  274. #state
  275. {
  276. top: 1%;
  277. left: 1%;
  278. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement