Skip to content

Instantly share code, notes, and snippets.

@bootcoder
Last active August 29, 2015 13:57
Show Gist options
  • Save bootcoder/9729321 to your computer and use it in GitHub Desktop.
Save bootcoder/9729321 to your computer and use it in GitHub Desktop.
code combat dressed up
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">
var player = {
name: "Eddie Murphy",
};
var ogre = {
name: "Donkey!",
};
var positionArray = [];
function startGame(){
// love how you did the random generation here
var x = Math.floor((Math.random()*10));
var y = Math.floor((Math.random()*10));
// not sure why this line is here
// unless you replace the position text on ln22 with orge.position
ogre.position = x + "," + y;
var playerPos = prompt("The Ogre, " + ogre.name + " is at " + x + "," + y + ". Where would you like to move " + player.name + "? Type in 'x-value,y-value'. We recommend next to the ogre, if you are not scared...");
// can you explain to me how the x2 y2 variables are returned from the prompt, I think I get it but want to make sure. prompt returns an array x is @ 0 the comma is @ 1 and y is @ 2
var y2 = playerPos[2];
var x2 = playerPos[0];
var attackYesNo = confirm("You are positioned at " + x2 +"," + y2 + ". Would you like to attack the dreaded ogre?");
if (((x2-x===1) && (y2-y===0)) || ((x2-x===0) && (y2-y===1)) || ((x-x2===1) && (y-y2===0)) || ((x-x2===0) && (y-y2===1))) {
alert("You have won!");
} else {
alert("Wow, you really need to learn to position yourself better! Go learn how to do that and come back to try again.");
};
};
</script>
</head>
<body>
<button onclick="startGame()">Start</button>
<style type="text/css">
button {
width: 100px;
height: 100px;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
background-color: red;
border-radius: 100%;
border: 1px solid black;
padding: 15px;
font-size: 1.5em;
}
</style>
<div class="main">
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment