Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE>
- <html lang="en">
- <head>
- <meta charset="UTF-8"></meta>
- <!--JQUERY files-->
- <script type="text/javascript" src="C:UsersRyanDocumentsWebjquery-1.11.1.min.js"></script>
- <!---Javascript--->
- <script type="text/javascript" src="C:UsersRyanDocumentsWeb_ProjectsTemplatetemp_1.js">
- </script>
- <!---CSS--->
- <link rel="stylesheet" type="text/css" href="C:UsersRyanDocumentsWeb_ProjectsTemplatetemp.css">
- </link>
- <!---WEB FONTS-->
- <link rel='stylesheet' type='text/css' href='http://fonts.googleapis.com/css? family=Roboto:400,900,100,100italic'>
- <title></title>
- </head>
- <body>
- <div id='container'>
- <div id='player'>
- <div id='pcont'>
- <label for="name">Name:</label>
- <p id='name'></p><br/>
- <label for="hp">Health:</label>
- <p id='hp'></p><br/>
- <label for="ep">Energy:</label>
- <p id='ep'></p><br/>
- <label for="lvl">Level:</label>
- p id='lvl'></p><br/><br/>
- <button id='explore'>Explore</button>
- <button id='rest'>Rest</button>
- <button id='run'>Run</button>
- <button id='attack'>Attack</button>
- <button id='quit'>Quit</button>
- </div>
- </div>
- <div id='enemy'>
- <div id="econt">
- <label for="ename">Name:</label>
- <p id='ename'></p><br/>
- <label for="ehp">Health:</label>
- <p id='ehp'></p><br/>
- </div>
- </div>
- </div>
- <h1 id='state'></h1>
- </body>
- </html>
- $(document).ready(function () {
- var m = Math;
- //Character constructor where the player and enemies will receive their //attributes from.
- function Character() {
- this.name = "";
- this.health = 1;
- this.max_health = 10;
- this.do_dmg = do_dmg;
- function do_dmg(enemy) {
- //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
- var dmg = m.min(m.max(
- m.round(m.random() * this.health) - m.round(m.random() * enemy.health), 0),
- enemy.health);
- $('#hp').text(this.health);
- $('#ehp').text(enemy.health -= dmg);
- if (dmg === 0) {
- console.log(this.name + " evades " + enemy.name + "'s attack!");
- } else {
- console.log(this.name + " hurts " + enemy.name + " for " + dmg);
- return enemy.health <= 0;
- }
- }
- }
- //Create Enemies HERE
- var Goblin = new Character();
- Goblin.name = "Goblin";
- Goblin.health = m.floor(m.round(m.random() * 10)) + 1;
- Goblin.XP = 25;
- var Demon = new Character();
- Demon.name = "Demon";
- Demon.health = m.floor(m.round(m.random() * 10 + m.random() * 1)) + 1;
- Demon.XP = 50;
- var Dragon = new Character();
- Dragon.name = "Dragon";
- Dragon.health = m.floor(m.round(m.random() * 10 + m.random() * 2)) + 1;
- Dragon.XP = 100;
- //Load created enemies into an Array
- var Enemies = [Goblin, Dragon, Demon];
- //Create the Player.
- var Player = new Character();
- var p = Player;
- p.state = "normal";
- p.awoken = m.round(m.random());
- p.name = "Ryan";
- p.health = 10;
- p.max_health = 10;
- p.energy = 10;
- p.max_energy = 10;
- p.XP = 0;
- p.level = 1;
- p.nextLevel = p.level + 1;
- p.quit = function () {
- console.log(this.name + " has quit.");
- },
- p.tired = function () {
- this.energy -= 1;
- $('#ep').text(this.energy);
- if (this.energy == 5) {
- console.log(this.name + ' is getting tired.');
- } else if (this.energy == 2) {
- console.log(this.name + ' is exhausted.');
- } else if (this.energy <= 0) {
- this.energy = this.max_energy;
- $('#ep').text(this.energy);
- console.log(this.name + ' passed out from exhaustion. You woke up fully refreshed.');
- } else {
- $('#ep').text(this.energy);
- }
- },
- p.rest = function () {
- console.log(this.awoken);
- if (this.awoken === 0) {
- window.enemy = Enemies[m.floor(m.random() * Enemies.length)];
- window.enemy = enemy;
- console.log(this.name + ' is awoken by a ' + enemy.name + '!');
- $('#ename').text(enemy.name);
- $('#ehp').text(enemy.health);
- this.state = 'fight';
- $('#state').text(this.state);
- this.enemy_atk();
- } else if (this.awoken == 1) {
- console.log(this.name + ' rests.');
- if (this.health < this.max_health) {
- this.health += 1;
- $('#hp').text(p.health);
- } else if (this.energy < this.max_energy) {
- this.energy += 1;
- $('#ep').text(p.energy);
- } else {
- console.log(this.name + ' slept too long.');
- this.energy -= 1;
- $('#ep').text(p.energy);
- }
- } else {
- console.log(this.name + 'can't rest right now');
- }
- },
- p.enemy_atk = function () {
- if (enemy.health >= 1) {
- if (enemy.do_dmg(this) >= this.health) {
- this.health = 0;
- console.log(this.name + ' was killed by the ' + enemy.name);
- } else {
- $('#ehp').text(enemy.health);
- $('#hp').text(this.health);
- }
- } else {
- $('#ename').text('');
- $('#ehp').text('');
- console.log(this.name + ' killed the ' + enemy.name);
- console.log(this.name + ' gained ' + enemy.XP / this.level + ' EXP!');
- this.state = 'normal';
- $('#state').text(this.state);
- }
- },
- p.atk = function () {
- if (this.state != 'fight') {
- console.log(this.name + ' swings at nothing and falls.');
- this.tired();
- } else {
- if (this.do_dmg(enemy) >= enemy.health) {
- enemy.health = 0;
- console.log(this.name + ' killed ' + enemy.name);
- console.log(this.name + ' gained ' + enemy.XP / this.level + ' EXP!');
- $('#ename').text('');
- $('#ehp').text('');
- this.state = 'normal';
- $('#state').text(this.state);
- } else {
- this.do_dmg(enemy);
- this.enemy_atk();
- }
- }
- },
- p.giveXP = function (amount) {
- var XPArray = popArray;
- this.XP += amount;
- if (this.level == 60) {
- } else {
- if (this.XP > XPforLevel(p.nextLevel)) {
- this.level++;
- console.log('Congratulations! ' + this.name + ' has leveled up!');
- }
- }
- function popArray() {
- array = [60];
- array[0] = [0];
- for (i = 1; i < 60; i++) {
- array[i] = array[i - 1] + 100 * i;
- }
- return array;
- }
- function XPforLevel(nextLevel) {
- return XPArray[p.nextLevel];
- }
- };
- $('#quit').click(function () {
- p.quit();
- });
- $('#rest').click(function () {
- p.awoken = m.round(m.random());
- p.rest();
- });
- $('#attack').click(function () {
- p.atk();
- });
- $('#name').text(p.name);
- $('#hp').text(p.health);
- $('#ep').text(p.energy);
- $('#lvl').text(p.level);
- $('#state').text(p.state);
- });
- #html,body
- {
- margin:0%;
- padding:0%;
- width: 100%;
- height: Window.innerHeight;
- min-height:100%;
- min-width:600px;
- max-width:2000px;
- font-family: 'Roboto', sans-serif;
- }
- p
- {
- display: inline-block;
- }
- #player, #enemy
- {
- width: 49.5%;
- height: 50%;
- border: 1px solid black;
- position: relative;
- float:left;
- }
- #pcont, #econt
- {
- position: absolute;
- top: 0.5%;
- left: 0.5%;
- width: 100%;
- height: 100%;
- line-height: 0.5em;
- }
- #container
- {
- border: solid black;
- height: 50%;
- }
- #state
- {
- top: 1%;
- left: 1%;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement