Created
March 12, 2013 23:30
-
-
Save unisys12/5148059 to your computer and use it in GitHub Desktop.
Just some java script that I am playing around with while teaching myself the language. This is just an exercise in constructor objects and object literals and using them. Basically just a little character set-up type script sorta thing. I would like to turn this into something more, but I am just learning here, so... we will see. My gut tells m…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang=en> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> | |
<title>Adventure Time!</title> | |
<meta name="viewport" content="width=device-width"> | |
<link rel="stylesheet" href="css/style.css"> | |
</head> | |
<body> | |
<div class="main"> | |
<header> | |
<h1>Welcome to Adventure Time!</h1> | |
<h4>Where the impossible is possible in a world of JavaScript</h4> | |
</header> | |
<p>Actually, this is just a perverse way for me to teach myself JavaScript and try to have some fun doing it. So, to kick things off, just open the console (ctrl-shft-i) and choose Console. Just follow the directions from there. Remember, have fun!</p> | |
<div class="player_form"> | |
<form method="post" name="playersInfo" id="playersForm"> | |
<fieldset> | |
<h4>Enter Your Player Details Below</h4> | |
<label for="playerName">Your Real Name: </label> | |
<input type="text" value="" name="playerName" id="playerName"> | |
<br> | |
<label for="playerAge">Your Age: </label> | |
<input type="text" value="" name="playerAge" id="playerAge"> | |
<br> | |
<label for="charRace">Your Charactors Race: </label> | |
<input type="text" value="" name="charRace" id="charRace"> | |
<br> | |
<label for="charName">Enter Your Characters Name: </label> | |
<input type="text" value="" name="charName" id="charName"> | |
<br><br> | |
<!-- <input type="button" value="Submit" name="submit" onClick=Player(name, charName, race, age)> --> | |
<input type="button" value="Submit" onclick="createPlayer(this.form)"> | |
</fieldset> | |
</form> | |
</div> | |
</div> | |
<!-- <script src="js/adventure.js"></script> --> | |
<script src="js/objectTest.js"></script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Player(name, charName, race, age){ | |
this.name = name; | |
this.charName = charName; | |
this.race = race; | |
this.age = age; | |
} | |
function Character(name, race) { | |
this.name = name; | |
this.charRace = race; | |
switch(race) | |
{ | |
case 'ork': | |
this.charStrength = 3; | |
this.charAgility = 1; | |
this.charPower = 3; | |
break; | |
case 'nord': | |
this.charStrength = 2; | |
this.charAgility = 3; | |
this.charPower = 2; | |
break; | |
default: | |
console.log("Please select a race!"); | |
} | |
} | |
function createPlayer(form){ | |
realName = form.playerName.value; | |
charName = form.charName.value; | |
race = form.charRace.value; | |
age = form.playerAge.value; | |
player = new Player(realName, charName, race, age); | |
playerChar = new character(charName, race); | |
} | |
var perks = { | |
strength : 1, | |
agility : 1, | |
power : 1, | |
addStrength : function(){ | |
var current = playerChar.charStrength; | |
var strength = perks.strength; | |
playerChar.charStrength = current+=strength; | |
return playerChar.charStrength; | |
}, | |
addAgility : function(){ | |
var current = playerChar.charAgility; | |
var agility = perks.agility; | |
playerChar.charAgility = current+=agility; | |
return playerChar.charAgility; | |
}, | |
addPower : function(){ | |
var current = playerChar.charPower; | |
var power = perks.agility; | |
playerChar.charPower = current+=power; | |
return playerChar.charPower; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment