From 84f83fb02efb544e6a17665532cb3ad1eb59eee4 Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Sun, 18 Feb 2018 20:42:59 -0500 Subject: [PATCH] Added support for metric and customary units --- game.js | 18 +++++++++++++--- stroll.html | 2 ++ units.js | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 units.js diff --git a/game.js b/game.js index 995fc9e..eccff85 100644 --- a/game.js +++ b/game.js @@ -7,6 +7,8 @@ var strolling = false; var maxStomachDigest = 10; var maxBowelsDigest = 10; +var metric = true; + victims = {}; function toggle_auto() @@ -18,6 +20,16 @@ function toggle_auto() else update(["You stop walking."]); } + +function toggle_units() +{ + metric = !metric; + + document.getElementById("button-units").innerHTML = metric ? "Metric" : "Customary"; + + update(); +} + function initVictims() { return { @@ -167,8 +179,8 @@ function update(lines = []) var height = baseHeight * scale; var mass = baseMass * Math.pow(scale, 3); - document.getElementById("height").innerHTML = "Height: " + Math.round(height * 3) + " feet"; - document.getElementById("mass").innerHTML = "Mass: " + Math.round(mass * 2.2) + " pounds"; + document.getElementById("height").innerHTML = "Height: " + (metric ? metricLength(height) : customaryLength(height)); + document.getElementById("mass").innerHTML = "Mass: " + (metric ? metricMass(mass) : customaryMass(mass)); for (var type in victims) { if (victims.hasOwnProperty(type)) { @@ -270,7 +282,7 @@ window.addEventListener('load', function(event) { document.getElementById("button-stomp").addEventListener("click",stomp); document.getElementById("button-anal_vore").addEventListener("click",anal_vore); document.getElementById("button-stroll").addEventListener("click",toggle_auto); - + document.getElementById("button-units").addEventListener("click",toggle_units); setTimeout(pick_move, 2000); update(); diff --git a/stroll.html b/stroll.html index a767a71..56f6b6b 100644 --- a/stroll.html +++ b/stroll.html @@ -4,6 +4,7 @@ Stroll + @@ -26,6 +27,7 @@
Standing
+

Stomped

diff --git a/units.js b/units.js new file mode 100644 index 0000000..d9ea0bd --- /dev/null +++ b/units.js @@ -0,0 +1,60 @@ +function round(number,precision=3) { + return Math.round(number*Math.pow(10,precision)) / Math.pow(10,precision); +} + +function metricMass(kg) { + if (kg < 1) { + var mass = round(kg * 1000); + return mass + (mass == 1 ? " gram" : " grams"); + } else if (kg < 5000) { + var mass = round(kg); + return mass + (mass == 1 ? " kilogram" : " kilograms"); + } else { + var mass = round(kg / 1000); + return mass + (mass == 1 ? " metric ton" : " metric tons"); + } +} + +function customaryMass(kg) { + var lbs = kg * 2.2; + + if (lbs < 1) { + var mass = round(lbs * 16); + return mass + (mass == 1 ? " ounce" : " ounces"); + } else if (lbs < 2000) { + var mass = round(lbs); + return mass + (mass == 1 ? " pound" : " pounds"); + } else { + var mass = round(lbs / 2000); + return mass + (mass == 1 ? "ton" : " tons"); + } +} + +function metricLength(m) { + if (m < 1) { + var length = round(m * 100); + return length + (length == 1 ? " centimeter" : " centimeters"); + } else if (m < 500) { + var length = round(m); + return length + (length == 1 ? " meter" : " meters"); + } else { + var length = round(m / 1000); + return length + (length == 1 ? " kilometer" : " kilometers"); + } +} + +function customaryLength(m) { + var ft = m * 3.28084; + + if (ft < 1) { + var length = round(ft * 12,0); + return length + (length == 1 ? " inch" : " inches"); + } else if (ft < 5280) { + var end = customaryLength((ft - Math.floor(ft))/3.28084); + var length = Math.floor(ft); + return length + (length == 1 ? " foot" : " feet") + " " + end; + } else { + var length = round(ft/5280); + return length + (length == 1 ? " mile" : " miles"); + } +}