var game = { //merged variable resources: 0, incAmount: 1, upgradeCost: 1, robottotalavg: 0, robottotalrate: 0, t1robot: { amount: 0, rate: 1, cost: 100, upgrade: 1000, tickrate: 1000, tickratecost: 10000 }}; var robotTick = setInterval(runRobots, 1000); $(updateAmounts()); //Updates amounts on page load (just in case) // Will add commas at the thousands mark (American style) function commaSeparateNumber(val){ while (/(\d+)(\d{3})/.test(val.toString())){ val = val.toString().replace(/(\d+)(\d{3})/, '$1'+','+'$2'); } return val; } //Prevents buttons from being focused $(":button").focus(function() { this.blur(); }); //Activates the robots function runRobots() { game.resources = (game.resources + game.robottotalrate); game.resources = Math.ceil(game.resources); updateAmounts(); } // Declared function to update all the vars on the screen function updateAmounts(){ $("#current_clicks").text(commaSeparateNumber(game.resources)); $("#increment_amount").text(commaSeparateNumber(game.incAmount)); $("#upgrade_cost").text(commaSeparateNumber(game.upgradeCost)); $("#t1robot_amount").text(commaSeparateNumber(game.t1robot.amount)); $("#t1robot_rate").text(commaSeparateNumber(game.t1robot.rate)); $("#t1robot_cost").text(commaSeparateNumber(game.t1robot.cost)); $("#t1upgrade_cost").text(commaSeparateNumber(game.t1robot.upgrade)); $("#robot_totalavg").text(commaSeparateNumber(game.robottotalavg)); $("#tick_rate").text(commaSeparateNumber(game.t1robot.tickrate)); $("#tick_cost").text(commaSeparateNumber(game.t1robot.tickratecost)); $("#robot_pertickrate").text(commaSeparateNumber(game.robottotalrate)); } function resetGame() { game = { //merged variable resources: 0, incAmount: 1, upgradeCost: 1, robottotalavg: 0, robottotalrate: 0, t1robot: { amount: 0, rate: 1, cost: 100, upgrade: 1000, tickrate: 1000, tickratecost: 10000 }}; clearInterval(robotTick); robotTick = setInterval(runRobots, 1000); updateAmounts(); } $("#devcheat").click(function () { if (game.resources < 40000) { game.resources = (game.resources + 40000); } else { game.resources = (game.resources * 5); game.incAmount = (game.incAmount * 5); } updateAmounts(); }); $("#gather").click(function () { game.resources = (game.resources + game.incAmount); updateAmounts(); }); $('#upgrade').click(function () { if ((game.resources - game.upgradeCost) >= 0) { game.incAmount = Math.ceil(game.incAmount * 1.25); game.resources = (game.resources - game.upgradeCost); game.upgradeCost = (game.incAmount * (game.incAmount - 1)); updateAmounts(); } }); $("#t1buy").click(function () { if ((game.resources - game.t1robot.cost) >= 0) { game.resources = (game.resources - game.t1robot.cost); game.t1robot.amount = (game.t1robot.amount + 1); game.t1robot.cost = (game.t1robot.cost * 1.1); game.t1robot.cost = Math.ceil(game.t1robot.cost); game.robottotalrate = (game.t1robot.amount * game.t1robot.rate); } updateAmounts(); }); $("#t1upgrade").click(function () { if ((game.resources - game.t1robot.upgrade) >= 0) { game.resources = (game.resources - game.t1robot.upgrade); game.t1robot.rate = (game.t1robot.rate * 1.25); game.t1robot.upgrade = (game.t1robot.upgrade * 2); game.t1robot.rate = Math.ceil(game.t1robot.rate); game.robottotalrate = Math.ceil(game.t1robot.amount * game.t1robot.rate); updateAmounts(); } }); $("#tickupgrade").click(function () { if (game.resources - game.t1robot.tickratecost >= 0) { if (game.t1robot.tickrate > 50) { //Check if tick rate is lowest allowed game.resources = (game.resources - game.t1robot.tickratecost); game.t1robot.tickrate = Math.floor(game.t1robot.tickrate * 0.9); game.t1robot.tickratecost = Math.ceil(game.t1robot.tickratecost * 1.5); if (game.t1robot.tickrate < 50) { game.t1robot.tickrate = 50; game.t1robot.tickratecost = "Nope."; } clearInterval(robotTick); robotTick = setInterval(runRobots, game.t1robot.tickrate); updateAmounts(); } } }); $("#save").click(function () { localStorage.setItem("save",JSON.stringify(game)); $("#save_confirm").text("Save successful"); $("#save_confirm").fadeOut(5000, function() { $("#save_confirm").empty(); $("#save_confirm").fadeIn(1); }); }); $("#load").click(function () { $.extend(true,game,JSON.parse(localStorage.getItem("save"))); //Silent thanks to /u/LukeZaz clearInterval(robotTick); robotTick = setInterval(runRobots, game.t1robot.tickrate); updateAmounts(); $("#load_confirm").text("Load successful"); $("#load_confirm").fadeOut(5000, function() { $("#load_confirm").empty(); $("#load_confirm").fadeIn(1); }); }); $("#hardwipe").click(function () { var x; var r=confirm("This will wipe your save and reset the game!"); if (r == true) { localStorage.removeItem("save"); resetGame(); $("#wipe_confirm").text("Save cleared, Game Reset"); $("#wipe_confirm").fadeOut(5000, function() { $("#wipe_confirm").empty(); $("#wipe_confirm").fadeIn(1); }); } });
<!--Title & resource click/upgrade--> <div class="body"> <h1>NoName Incremental</h1> <div style="margin:0px auto; width:70%"> <div style="float:left; margin:0; width:50%;"> <button id="gather" type="button" class="btn btn-primary btn-lg">Gather Resources</button> </div> <div style="float:left; margin:0;width:50%;"> <button id="upgrade" type="button" class="btn btn-primary btn-lg">Increase resource per Click</button> <p style="padding:0.5em 0px 0px 2em">Upgrade Cost: <span id="upgrade_cost">1</span></p> </div> </div> <!--Resources & per click--> <br> <h2 style="clear:both">Resources: <span id="current_clicks">0</span></h2> <p>Current Resource Per Click: <span id="increment_amount">1</span></p> <p>Robots gather <span id="robot_pertickrate">0</span> resources per tick.</p> <hr style="width:50%"> <!--Robot box--> <div style="margin:0px auto; width:70%;text-align:center"> <div style="float:left; margin:0; width:50%;"> <h4 style="display:inline;padding:0em 1em 0em 0em"><span id="t1robot_amount">0</span> Robots</h4> <button id="t1buy" type="button" class="btn btn-primary">Buy a T1 Robot</button> <p style="padding:0.5em 0em 0em 6em">Robot Cost: <span id="t1robot_cost">100</span></p> </div> <div style="float:left; margin:0;width:50%;"> <button id="t1upgrade" type="button" class="btn btn-primary">Upgrade T1 Gather Amount</button> <h4 style="display:inline;padding:0em 0em 0em 1em"><span id="t1robot_rate">1</span> units</h4> <p style="padding:0.5em 3em 0em 0em">Upgrade Cost: <span id="t1upgrade_cost">1,000</span></p> </div> </div> </div> <div class="body"> <!--Float area--> <br><br><br><br><br><br> <p>Robots activate every: <span id="tick_rate"></span> milliseconds</p> <button id="tickupgrade" type="button" class="btn btn-primary">Increase robot speed</button> <p style="padding:0.5em 0em 0em 0em">Upgrade Cost: <span id="tick_cost">10,000</span></p> </div> <div style="text-align:right;display:none"> <button id="devcheat" type="button" class="btn btn-primary">Developer Cheat</button> </div> <hr style="width:50%"> <div class="body"> <h3>Save/Load Game</h3> <button id="save" type="button" class="btn btn-primary btn-md" style="width:10em">Save</button> <span id="save_confirm" style="display:block;padding:0.5em 0em 0em 0em"></span> <hr style="width:10%"> <span id="load_confirm" style="display:block;padding:0em 0em 0.5em 0em"></span> <button id="load" type="button" class="btn btn-primary btn-md" style="width:10em">Load</button> <hr style="width:10%"> <span id="wipe_confirm" style="display:block;padding:0em 0em 0.5em 0em"></span> <button id="hardwipe" type="button" class="btn btn-primary btn-md" style="width:10em">Hard Reset</button> <hr style="width:50%;padding:1em"> </div> <div class="body"> <h3 style="text-align:center">Changelog</h3> <h5 style="text-align:center">Current Version: V0.2</h5> <hr style="width:25%"> <dl style="text-align:center"> <dt>V0.2</dt> <dd>- Improved Layout to be more fluid <br>- Changed statistic placement and sizing <br>- Changed button sizes <br>- Added ability to increase robot speed <br>- Improved Save and Load <br>- Added hard reset (Wipes save and resets the whole game) <br> <br>- Thanks to <a href="http://www.reddit.com/user/TheWalrusEffect" target="_blank">/u/TheWalrusEffect</a> <br>- Added comma separators to large numbers <br>- Fixed button focus on click <br>- Improved code organization </dd> <hr style="width:25%"> <dt>V0.1</dt> <dd>- Basic game functionality (Click to gather resources) <br>- Added click upgrades (More resources per click) <br>- Added T1 Robots and ability to upgrade their resource rate <br>- Added some basic statistics <br>- Added Save & Load functionality using localstorage <br>- Added Changelog <br>- Added Buglist </dd> </dl> <hr style="width:50%"> <h3 style="text-align:center">Known Bugs/Issues from V0.2</h3> <h4 style="text-align:center">Key:</h4> <h6 style="text-align:center">Not yet fixed</h6> <h6 style="text-align:center"><del>Fix implemented</del></h6> <hr style="width:25%"> <h6 style="text-align:center">In small screen sizes or large text options, some areas are pushed to different positions (More likely to occur as numbers get higher)</h6> <hr> <p style="text-align:center">Game by MisterRusty - Last updated April 25th 2014</p> </div>