html5 - How to make a button pattern? -
i'm trying make little puzzle game in html5 , i'm having trouble figuring out how make puzzle. in puzzle have click squares in order beat it. don't know how make have click buttons in order , if don't you'll lose.
<!doctype html> <html> <head> <title>room two</title> <link rel="stylesheet" type="text/css" href="youtubegame.css"> <link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=tangerine|inconsolata|droid+sans|oxygen|ubuntu|coming+soon"> </head> <body> <div id="content"> <h1 id="roomnum">room 2</h1> <p id="roominfo">once again door seems magically close behind you.<br /> unlike stone floor previous room, 1 divided wooden slabs.<br /> press foot onto slab. slides down, , arrrow shoots roof.<br /> barely out of way somehow dodge it. tell watch step...</p> <p id="step"></p> <p id="step2"></p> <div class="menu-container" id="puzzle"> <div class="button-container"> <a href="#" class="button" onclick="wrongstep()">1</a> <a href="#" class="button" onclick="correctstep6()">2</a> <a href="#" class="button" onclick="correctstep7()">3</a> <a href="#" class="button" onclick="wrongstep()">4</a> <a href="#" class="button" onclick="correctstep5()">5</a> <a href="#" class="button" onclick="correctstep4()">6</a> <a href="#" class="button" onclick="correctstep1()">7</a> <a href="#" class="button" onclick="correctstep2()">8</a> <a href="#" class="button" onclick="correctstep3()">9</a> </div> </div> </div> <br><br> <div id="death"> <a href="youtubegame.html">try again?</a> </div> <a href="roomthree.html" id="nextroom">next room</a> <script type="text/javascript"> document.getelementbyid("death").style.display = "none"; document.getelementbyid("nextroom").style.display = "none"; function correctstep1() { return true; } function correctstep2() { return true; } function correctstep3() { return true; } function correctstep4() { return true; } function correctstep5() { return true; } function correctstep6() { return true; } function correctstep7() { return true; } function wrongstep() { document.getelementbyid("content").style.display = "none;" document.getelementbyid("puzzle").style.display = "none"; document.getelementbyid("death").style.display = "block"; document.getelementbyid("roomnum").innerhtml = "you have died"; document.getelementbyid("roominfo").style.display = "none"; } </script> </body> </html>
please me fix this
a simple way save correct order in array , if user clicks, increment clickcounter , check if clicked button @ position in array:
var state = { clickedbuttons:[] }; var correctclicksettings = { order:[7,8,9,6,5,2,3], reseton:7 // order has 7 elements, user have click 7 buttons, after checked , clicked buttons resolved or rejected }; // called every button can clicked solve game function onclick(evt) { evt = evt || window.event; var sourcebuttontext = this.innertext; state.clickedbuttons.push(sourcebuttontext); if(state.clickedbuttons.length >= correctclicksettings.reseton) { var distancebetweenarrays = state.clickedbuttons.reduce((cur,val,idx)=>cur+math.abs(val-correctclicksettings.order[idx]),0); if(distancebetweenarrays > 0) { wrongstep(); state.clickedbuttons = []; } else { alert('this right!'); } } }
this solution has 1 problem: little bit of understanding javascript can open webpage , read out solution. if want little better (not easaly cheatable) have use solution:
you can use hash instead of array of button clicks correct order:
function simplehash(currenthash, idx, sourcebuttontext) { currenthash = currenthash*137+parseint(sourcebuttontext,10); }
now calculate correct solution value: 46672273550408 (in case)
now every button click calculate next hash , compare after 7 steps solution.
Comments
Post a Comment