Skip to content

Instantly share code, notes, and snippets.

@jpedrosa
Created June 16, 2015 21:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpedrosa/48e4fcdb4fdb66744a4f to your computer and use it in GitHub Desktop.
Save jpedrosa/48e4fcdb4fdb66744a4f to your computer and use it in GitHub Desktop.
Fun with game script. :-)
<!DOCTYPE html>
<!-- saved from url=(0037)http://zdmilot.com/gamegen/index.html -->
<html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
<title>GameGen</title>
<link rel="shortcut icon" href="http://zdmilot.com/gamegen/images/sixsided.ico" type="image/icon">
<script async="" src="./GameGen_files/analytics.js"></script><script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-64037687-1', 'auto');
ga('send', 'pageview');
</script>
<!-- CSS -->
<link href="./GameGen_files/materialize.css" type="text/css" rel="stylesheet" media="screen,projection">
<link href="./GameGen_files/style.css" type="text/css" rel="stylesheet" media="screen,projection">
<style type="text/css"></style>
</head>
<body>
<div id="navbar" class="navbar-fixed scrollspy">
<nav class="white">
<div class="nav-wrapper container">
<div class="container"> <a href="http://zdmilot.com/gamegen/index.html#navbar" class="brand-logo">GameGen</a></div>
<a href="http://zdmilot.com/gamegen/index.html#" data-activates="mobile-demo" class="button-collapse"><i class="mdi-navigation-menu"></i></a>
<ul class="right hide-on-med-and-down">
<li><a class="head-link" href="http://zdmilot.com/gamegen/index.html#projects">Rolling</a></li>
<li><a class="head-link" href="http://zdmilot.com/gamegen/index.html#aboutus">Chart</a></li>
</ul>
<ul class="right side-nav" id="mobile-demo">
<li><a class="head-link" href="http://zdmilot.com/gamegen/index.html#projects">Rolling</a></li>
<li><a class="head-link" href="http://zdmilot.com/gamegen/index.html#aboutus">Chart</a></li>
</ul>
</div>
</nav>
</div>
<div class="container">
<div class="section">
<!-- Icon Section -->
<div class="icon-block">
<h2 class="center" style="color:#333"><i class="mdi-av-new-releases"></i></h2>
<h5 class="center">Enter info here:</h5>
</div>
</div>
<p>Enter your Power Level:</p><br>
<input id="level" type="number">
<br>
<br>
<button id="enterButton">Enter</button>
<br><br>
Your result is:<p id="lvl"></p>
Your roll is:<p id="rndroll"></p>
<!-- Scripts-->
<script src="./GameGen_files/jquery-2.1.1.min.js"></script>
<script src="./GameGen_files/materialize.js"></script>
<script src="./GameGen_files/init.js"></script>
<script>
$(document).ready(function(){
$('.materialboxed').materialbox();
$('.button-collapse').sideNav();
});
</script>
<script>
$('.head-link').click(function(e) {
e.preventDefault();
var goto = $(this).attr('href');
$('html, body').animate({
scrollTop: $(goto).offset().top
}, 800);
});
</script>
<script>
function getEl(id) {
return document.getElementById(id);
}
function err(msg) {
if (msg === undefined) {
msg = "Exception";
}
throw new Error(msg);
}
function doCalculate() {
var x = Math.floor((Math.random() * 100)) + 1;
getEl("rndroll").innerHTML = "" + x;
var level;
var lvl = getEl("level").value;
console.log("lvl " + lvl);
if (x === 1) {
if (lvl >= 1 && lvl <= 10) {
level = "Major Fail";
} else {
err("The level value is out of range.");
}
}
else if (x >= 2 && x <= 7) {
if (lvl >= 1 && lvl <= 3) {
level = "Major Fail";
} else if (lvl >= 4 && lvl <= 10) {
level = "Fail";
} else {
err("The level value is out of range.");
}
}
else if (x >= 8 && x <= 15) {
if (lvl >= 1 && lvl <= 2) {
level = "Major Fail";
} else if (lvl >= 3 && lvl <= 10) {
level = "Fail";
} else {
err("The level value is out of range.");
}
}
else if (x >= 16 && x <= 24) {
if (lvl == 1) {
level = "Major Fail";
} else if (lvl >= 2 && lvl <= 8) {
level = "Fail";
} else if (lvl >= 9 && lvl <= 10) {
level = "Success";
} else {
err("The level value is out of range.");
}
}
else if (x >= 25 && x <= 31) {
if (lvl >= 1 && lvl <= 7) {
level = "Fail";
} else if (lvl >= 8 && lvl <= 10) {
level = "Success";
} else {
err("The level value is out of range.");
}
}
else if (x >= 32 && x <= 40) {
if (lvl >= 1 && lvl <= 5) {
level = "Fail";
} else if (lvl >= 6 && lvl <= 10) {
level = "Success";
} else {
err("The level value is out of range.");
}
}
else if (x >= 41 && x <= 49) {
if (lvl >= 1 && lvl <= 4) {
level = "Fail";
} else if (lvl >= 5 && lvl <= 10) {
level = "Success";
} else {
err("The level value is out of range.");
}
}
else if (x >= 50 && x <= 57) {
if (lvl >= 1 && lvl <= 2) {
level = "Fail";
} else if (lvl >= 3 && lvl <= 10) {
level = "Success";
} else {
err("The level value is out of range.");
}
}
else if (x >= 58 && x <= 65) {
if (lvl == 1) {
level = "Fail";
} else if (lvl >= 2 && lvl <= 10) {
level = "Success";
} else {
err("The level value is out of range.");
}
}
else if (x >= 66 && x <= 74) {
if (lvl >= 1 && lvl <= 9) {
level = "Success";
} else if (lvl == 10) {
level = "Major Success";
} else {
err("The level value is out of range.");
}
}
else if (x >= 75 && x <= 84) {
if (lvl >= 1 && lvl <= 6) {
level = "Success";
} else if (lvl >= 7 && lvl <= 10) {
level = "Major Success";
} else {
err("The level value is out of range.");
}
}
else if (x >= 85 && x <= 94) {
if (lvl >= 1 && lvl <= 3) {
level = "Success";
} else if (lvl >= 4 && lvl <= 10) {
level = "Major Success";
} else {
err("The level value is out of range.");
}
}
else if (x >= 95 && x <= 99) {
if (lvl == 1) {
level = "Success";
} else if (lvl >= 2 && lvl <= 9) {
level = "Major Success";
} else if (lvl == 10) {
level = "Legendary Success";
} else {
err("The level value is out of range.");
}
}
else if (x == 100) {
if (lvl >= 1 && lvl <= 7) {
level = "Major Success";
} else if (lvl >= 8 && lvl <= 10) {
level = "Legendary Success";
} else {
err("The level value is out of range.");
}
}
else {
err("The 'x' (" + x + ")value is out of range.");
}
getEl("lvl").innerHTML = level;
}
function calculate() {
try {
doCalculate();
} catch (e) {
getEl("lvl").innerHTML = "" + e + "<br />\n" +
"Level should stay between 1 and 10.";
getEl("rndroll").innerHTML = "";
throw e;
}
}
getEl("level").addEventListener("keypress", function(ev) {
if (ev.keyCode === 13) {
calculate();
}
});
getEl("enterButton").addEventListener("click", calculate);
</script>
</div><div class="hiddendiv common"></div><div class="drag-target" style="left: 0px; touch-action: pan-y; -webkit-user-drag: none; -webkit-tap-highlight-color: rgba(0, 0, 0, 0);"></div><div class="drag-target" style="left: 0px; touch-action: pan-y; -webkit-user-drag: none; -webkit-tap-highlight-color: rgba(0, 0, 0, 0);"></div></body></html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment