JavaScript Written Game: Porter

zhaozj2021-02-16  44

dwin.net - Web Application - Sokoban </ Title> <body> Written by David Ng @ <a href="http://dwin.net"> http://dwin.net </A> <br > Copyright (c) 1998-2007 dwin.net all rights reserved <br> <style> .ground {}. Floor {}. Wall {Overflow: hidden; border: 2px outset # adff2f; Background-Color: # 888888; z -index: 0} .aim {overflow: hidden; background-color: # ff69b4; opacity: 0.4; -moz-opacity: 0.4; filter: alpha (Opacity = 100, finishopacity = 0, style = 3); z-index : 0} .box {overflow: hidden; background-color: # 87cefa; opacity: 0.5; -moz-opacity: 0.5; filter: alpha (Opacity = 0, finishopacity = 100, style = 3); z-index: 1 } .Man {overflow: hidden; z-index: 1;} </ stop> <br> Current map: <input id = "currentmap" size = 5> <br> <input type = button value = 'previous map' οnmοusedοwn = 'changeMap (-1)'> <input type = button value = 'Next Map' οnmοusedοwn = 'changeMap (1)'> <br> <br></p> <p><textarea id = "Solutioninfo" style = "word-wrap: break-all" Word-break: Break-all "WRAP =" Virtual "rows = 20> </ textarea> <br> <input type = button value = ' copy 'οnclick =' document.getElementById ( "SolutionInfo") select ();. document.execCommand ( "Copy") '> <input type = button value =' paste 'οnclick =' document.getElementById ( "SolutionInfo"). Focus (); if (! / [^ (l | r | u | d | l | r | u | d)] / g.exec (window.clipboardData.getdata ("text"))) Document.execCommand (" Paste ") '> <input type = button value =' Clear 'οnclick =' document.getElementById (" SolutionInfo "). value =" " '> <input type = button value =' Auto Run 'οnmοusedοwn =' AutoRun () '> <br> <br> Boxes has Moved <br> <input id = BoxMoveInfo readonly> Steps <br> Man has Moved <br> <input id = ManMoveInfo readonly> Steps</p> <p><Div id = Base style = 'position: absolute; overflow: hidden'> </ div> <script> // firefoxif {HTMLElement.prototype.insertAdjacentElement = (typeof HTMLElement = "undefined" && HTMLElement.prototype.insertAdjacentElement!!) function (where, parsedNode) {switch (where) {case 'beforeBegin': this.parentNode.insertBefore (parsedNode, this) break; case 'afterBegin': this.insertBefore (parsedNode, this.firstChild); break; case 'beforeEnd ': this.appendChild (parsedNode); break; case' afterEnd ': if (this.nextSibling) this.parentNode.insertBefore (parsedNode, this.nextSibling); else this.parentNode.appendChild (parsedNode); break;}} HTMLElement .prototype.insertAdjacentHTML = function (where, htmlStr) {var r = this.ownerDocument.createRange (); r.setStartBefore (this); var parsedHTML = r.createContextualFragment (htmlStr); this.insertAdjacentElement (where, parsedHTML)}</p> <p>Htmlelement.prototype.insertadjacenttext = function (where, txtstr) {var parsedtext = document.createtextNode (txtstr) this.insertadjacentelement (where, pasedtext)}}</p> <p>/ * Written by David Ng @ http: //dwin.netcopyright (c) 1998-2004 Dwin.Net All Rights Reserved</p> <p>Start: 2002-10-02 17: 50FINISH: 2002-10-15 22:41</p> <p>2003-06-11 18: 55bug fix</p> <p>2007-08-08 19: 44firefox support * / map = []; solution = []; formatary = []; currentmapptr = 0;</p> <p>Function init (mapptr) {mainmap = []; currentmapptr = mapptr; formatptr = 0; MaxWidth = 0;</p> <p>ReplayTime = 100 // Million Second Mapw = MapH = 30; PushScrollNo = 30; BoxCompletes = 0; TotalBox = 0;</p> <p>Timer = null; canMove = true BoxMoves = 0; Count = -1; BackRecord = []; document.getElementById ( 'BoxMoveInfo') value = 0;. Document.getElementById ( 'ManMoveInfo') value = 0;. Document.getElementById ( 'currentMap') value = CurrentMapPtr;.. document.getElementById ( 'SolutionInfo') value = Solution [CurrentMapPtr];} function ReadMap (MapPtr) {init (MapPtr); for (var y = 0; y <Map [MapPtr ] .length; y ) {ion (Map [mapptr] [y] .indexof ('$')! = -1) formatptr = 1; if (MaxWidth <map [mapptr] [y] .length) maxwidth = map [ Mapptr] [y] .length;} var h = map [mapptr] .length * mapw; var w = maxwidth * mapw; var baseobj = document.getlementByid ('base') baseobj.innerhtml = '; baseobj.style. Width = W; baseobj.style.height = h; baseobj.style.left = (wocument.body.clientwidth? 0: (document.body.offsetwidth-w) / 2; baseobj.Style.top = 10;</p> <p>For (var y = 0; y <map [mapptr] .length; y ) {mainmap [y] = new array (maxwidth) for (VAR x = 0; x <maxwidth; x ) {mainmap [y] [ X] = MAP [mapptr] [y] .Charat (x);} catch (e) {mainmap [y] [x] = formatary [formatptr] .floor;}</p> <p>IF (mainmap [y] == formatary [formatptr] .wall) html (x, y, 'wall'); else {html (x, y, 'ground'); switch (mainmap [y] [x ]) {CASE formatary [formatptr] .box: iBox (x, y, 0); Break; Case formatary [format] .aim: html (x, y, 'aim'); Break; Case Formatary [formatptr] .boxonaim : IHTML (X, Y, 'AIM'); IBOX (X, Y, 1); BoxCompletes ; Break; Case Formatary [formatptr] .player: iMan (x, y, 0); Break; Case Formatary [formatptr]. Playeronaim: IHTML (X, Y, 'AIM'); IMAN (X, Y, 1); Break;}}}}} Function IHTML (X, Y, K) {document.getElementByid ('base'). InsertJaceThtml "beforeend", "<span style;" x * mapw "; TOP:" y * maph "; width:" mapw "; Height:" MAPH "'Class ='" K "'x =" x "y =" y ">");</p> <p>Function IBOX (x, y, k) {var obj = document.createElement ("span"); obj.style.position = 'absolute'; obj.style.left = x * mapw; obj.Style.top = Y * Maph; Obj.style.Width = Mapw; Obj.Style.Height = maph; obj.classname = 'box'; Obj.SetaTRibute ('Class', 'Box'); Obj.SetaTRibute ('Complete', K);</p> <p>Document.GtelementByid ('base'). appendchild (obj); mainmap [y] = obj; TotalBox ;}</p> <p>Function iMan (x, y, k) {man = document.createElement ("img"); man.src = 'http://dwin.net/webapp/cow.gif'; man.style.position = 'ABSOLUTE' MAN.Style.Left = x * mapw; man.style.top = y * maph; man.style.width = mapw; man.style.Height = maph; man.classname = 'man'; man.setttribute (' Class ','man'); Man.SetaTribute ('x', x); man.setattribute ('y', y); document.getlementByid ('base'). appendchild (man); mainmap [y] [x ] = (k == 0)? formatary [formatptr] .flole: formatary [format] .aim;</p> <p>Function Dir (x, y, k) {if (! canmove || y (man.gettribute ('y') | 0) <0 || y (man.gettribute ('y') | 0)> = MAP [ CurrentMapptr] .length || x (man.getattribute ('x') | 0) <0 || x (man.gettribute ('x') | 0)> = maxwidth) Return</p> <p>Var manfront = mainmap [y ('y') | 0)] [x (man.getattribute ('x') | 0)]; if (manfront == formatary [formatptr] .floor || manfront = = Formatary [formatptr] .aim) {if (k! = Null) Move1 (x, y, k.tolowercase ()); else Move1 (x, y);} else {ix (typeof (manfront) == 'Object ') {Var manfrontfront = mainmap [2 * y (man.gettribute (' y ') | 0)] [2 * x (man.getattribute (' x ') | 0)];</p> <p>IF (manfrontfront == formatary [formatptr] .floor) {if (k! = null) Move1 (x, y, k.touppercase ()); Else Move1 (x, y); Move2 (Manfront, X, Y); } Else if (manfrontfront == formatary [formatptr] .aim) {if (k! = Null) Move1 (x, y, k.touppercase ()); else Move1 (x, y); move3 (Manfront, X, Y (} Boxmoves }}}</p> <p>Function Move1 (x, y, k) {IF (k! = null) {backrecord [ count] = k backrecord.length = count 1} man.setttribute ('x', x (man.getattribute ('x ') | 0)); Man.SetaTribute (' Y ​​', Y (man.gettribute (' y ') | 0)); man.style.left = (man.getattribute (' x ') | 0) * MAPW ;.Style.top = (man.gettribute ('y') | 0) * MapH;} Function Move2 (Obj, x, y) {Obj.Style.Left = (x (man.getattribute ('x') | 0) * MAPW; OBJ.Style.top = (Y (man.gettribute ('y') | 0)) * MapH; mainmap [y (man.getattribute ('y') | 0)] [x ( Man.getaTribute ('x') | 0)] = OBJ;</p> <p>IF (Obj.GetaTRibute ('complete') == 0) mainmap [man.getattribute ('y') | 0] [man.gettribute ('x') | 0] = formatary [formatptr] .floor; else {mainmap [Man.getattribute ('y') | 0] [man.getattribute ('x') | 0] = formatary [formatptr] .aim; boxcompletes -;} Obj.setttribute ('complete', 0);}</p> <p>Function Move3 (Obj, x, y) {Obj.style.Left = (x (man.getattribute ('x') | 0)) * MAPW; obj.style.top = (y (man.getattribute " ) | 0)) * MAPH; MAINMAP [Y (man.gettribute ('y') | 0)] [x (man.gettribute ('x') | 0)] = OBJ;</p> <p>IF (Obj.GetaTribute ('complete') == 1) mainmap [man.getattribute ('y') | 0] [man.gettribute ('x') | 0] = formatary [formatptr] .aim; else {mainmap [Man.getattribute ('y') | 0] [man.getattribute ('x') | 0] = formatary [formatptr] .floor; if ( boxcompletes == TotalBox) Owin ();} Obj.setttribute 'Complete', 1);</p> <p>Function undo () {if (count> = 0) {canmove = true switch (backrecord [count]) {// not object Case 'L': Move1 (1,0); Break; // Left -> Right Case ' U ': Move1 (0, 1); Break; // Up -> Down Case' R ': Move1 (-1, 0); Break; // Right -> Left Case' D ': Move1 (0, -1 Break; // down -> UP // Object Case 'L': UNGO (1,0); Break; // Left -> Right Case 'u': UNGO (0, 1); Break; // Up -> Down Case 'R': Ungo (-1, 0); Break; // Right -> Left Case 'D': Ungo (0, -1); Break; // Down -> Up} ISELECTS (- COUNT)}} Function Ungo (x, y) {Boxmoves ---; var obj = mainmap [-y (man.getattribute ('y') | 0)] [- x (man.getattribute ('x') | 0 )];</p> <p>IF (mainmap [man.getattribute ('y') | 0] [man.gettribute ('x') | 0] == formatary [formatptr] .floor) {if (Obj.getattribute ('complete') == 0 ) MainMap [-y ('y') | 0)] [- x (man.getattribute ('x') | 0)] = formatary [formatptr] .floor; else {mainmap [-y (man) .getattribute ('y') | 0)] [- x (man.getattribute ('x') | 0)] = formatary [formatptr] .aim; boxcompletes -;} Obj.settribute ('complete', 0) } Else {if (Obj.getaTribute ('complete') == 0) {mainmap [-y (man.gettribute ('y') | 0)] [- x (man.getattribute ('x') | 0 )] = Formatary [formatptr] .floor; if ( Boxcompletes == TotalBox) w ();} else mainmap [-y (man.gettribute ('y') | 0)] [- x (man.getattribute) 'x') | 0)] = formatary [formatptr] .aim; obj.setttribute ('completion', 1);} Obj.style.Left = (man.getattribute ('x') | 0) * MAPW; OBJ .Style.top = (man.getattribute ('y') | 0) * MapH; mainmap [man.getattribute ('y') | 0] [man.getattribute ('x') | 0] = Obj; Move1 x, y);} function redo () {if (count 1 <backrecord.length) {switch (backrecord [ count]) {c ASE 'L': Case 'L': DIR (-1, 0); Break; // Left Case 'U': Case 'u': DIR (0, -1); Break; // Up Case 'R' : Case 'R': DIR (1,0); Break; // Right Case 'D': Case 'D': DIR (0, 1); Break; // Down} Iselects (count)} else clearinterval (Timer }</p> <p>Function Owin () {canmove = false alert ('congratulation!')}</p> <p>Function autorun () {var temp = document.getlementByid ('solutioninfo'). Value; if (temp == ') return;</p> <p>Readmap (CurrentMapptr); Backrecord = Temp.split (""); Timer = setInterval (redo, replayTIME);}</p> <p>function iSelects (x) {var obj = document.getElementById ( 'SolutionInfo'); if (obj.createTextRange) {var iRange = obj.createTextRange () iRange.collapse (true) iRange.moveStart ( "character", x) iRange .Movend ("Character", 1) irange.select ()} else if (obj.setSelectionRange) {Obj.SelectionStart = x; obj.seeend = x 1;} Document.getlementByid ('BoxmoveInfo'). Value = Boxmoves ; Document.getlementByid ('manmoveinfo'). Value = x 1;}</p> <p>Function ChangeMap (PTR) {var gomap = (CurrentMapptr PTR)% map.length; gomap = gomap <0? map.length-1: gomap; readmap (gomap);}</p> <p>document.getElementById ( 'CurrentMap') onkeydown = ChangeMapHandler;. function ChangeMapHandler (evt) {if (typeof (evt) == 'undefined') evt = window.event || window.Event; var keyCode = 0; if (evt Keycode = Evt.Keycode; Else IF (TypeOf (Evt.Which)! = 'undefined') Keycode = evt.which;</p> <p>IF (Keycode == 13) ChangeMap (this.Value | 0);</p> <p>Evt.cancelbubble = true if (evt.preventdefault) evt.stoppropagation ();</p> <p>Document.onkeyDown = function (evt) {if (TypeOf (evt) == 'undefined') evt = window.event || WINDOW.EVENT; var keycode = 0; if (est.keycode) Keycode = evt.keycode; Else IF (TypeOf (Evt.Which)! = 'undefined') Keycode = evt.which;</p> <p>if (evt.ctrlKey) {switch (keyCode) {case 37: document.body.scrollLeft- = PushScrollNo; break; // left case 38: document.body.scrollTop- = PushScrollNo; break; // up case 39: document .BODY.ScrollLeft = pushscrollno; Break; // Right Case 40: Document.body.Scrolltop = PushScrollno; Break; // Down}} else {switch (keycode) {Case 37: DIR (-1, 0, 'l' Break; // Left case 38: DIR (0, -1, 'u'); Break; // Up Case 39: DIR (1, 0, 'R'); Break; // Right Case 40: Dir (0, 1, 'd'); Break; // down} if (evt.retavy "= false) evt.returnValue = false; if (espreventdefault) evt.preventdefault ();</p> <p>Document.getElementByid ('SolutionInfo'). Value = backrecord.join (") iSelects (count)}}</p> <p>Document.onmouseUp = function (evt) {if (TypeOf (evt) == 'undefined') evt = window.event || window.event;</p> <p>IF (Evt.Button == 1 || evt.button == 0) REDO ()}</p> <p>Document.onTextMenu = function (evt) {if (TypeOf (evt) == 'undefined') evt = window.event || window.event;</p> <p>IF (Evt.ReturnValue! = false) evt.returnValue = false; if (espreventdefault) evt.preventdefault ();</p> <p>Undo ();</p> <p>Window.onLoad = function () {readmap (currentmapptr% map.length); document.body.scroll = 'no' window.focus (); document.getlementByid ('base'). Focus ();</p> <p>/ * Xsb format: $ = box * = Box on aim @ = player = Player on aim # = Wall. = Aim = floor</p> <p>My Format: 0 = Box @ = Box ON AIM * = Player # = Player ON AIMW = Wall. = AIM = Floor * / Formatary [0] = {Box: "0", Boxonaim: "@", Player: "* ", Playeronaim:" # ", Wall:" W ", AIM:". ", Floor:"} formatary [1] = {Box: "$", Boxonaim: "*", Player: "@", Playeronaim : " ", Wall: "#", AIM: ".", Floor: "} map [map.length] = ['wwwwwwwwwww', 'w * w', 'w 00000 0 W', 'W W ',' WWWWW WWWWW ',' W .W ',' W .W ',' W ... W ',' W .W ',' WWWWW '] Solution [Solution.length] =' rddlllllluurDurrDLdRRRRuulDrdLuLDDDDuuulluullddRRRluurDrDDDrddLUluRuurruurrdLrdLLLulDDDDrddllURuuuuruurDrdLLulDDDDDldRuuuuuulldRurDDDlDRuuulluulDldRRRurDDDD ';</p> <p>Map [map.Length] = ['## ##', '## ##', '# * $ # $ * #', '# $ # #', '# # @. # #', '# $ # #', '# * $ # $ * #', '## ##', '## ###', '## ## '] Solution [Solution.Length] =' LuuluurdddrrurrdLLDDDDDLUUUULLLLURRRRRLUURUURRRRRDDDLDLLLLUDDLURRRRUURDLUUUUUUUUUUUURDLLLDLUUR ';</p> <p>Map [map.Length] = ['#####', '# #', '## $ ##', '### $. $ ###', '# $. *. $ #' , '## $. *. *. $ ##', '### $. *. $. *. $ ###', '# $ # *. $$ *. $ #', '# $ # ',' # $. *. $. *. $ # ',' ### $. *. $. *. $ ### ',' ## $ *. *. $ ## ',' ### $ #### ',' ##### ',' # @ # ',' ### ## '] Solution [Solution.length] =' ruUrUrruUrUrruulLuLuulLuLuulldDlDlldDlDllddrRdRddrRdRddrruururruulUlUdrdrrurruulluluulldLdLruruuluullddldllddrDrDululldllddrrdrddrruRuRlUddldlluululluurrurrdrdRdddlddrUdddrruuLrddlUlUlulluRdrdrdrrururruululLLrrrdrddlldldllulululululluurrRlllddrUluRRuruurDururuurrddrddldldLdDrrrrdrruLLdrddlUruurrruulDrdLLruululuulldldldlddrrRllluurDldRRuluuruUUdddlddrUUUruulDDurrrdLrdrdrddldlddlldldllulululululuururuurruruurrDDDuuulldRurDD '; Map [Map.length] = [' #### ',' # ## ',' ## $ #### ',' ### . #### #.. #### ',' ###### $ # ## ',' ###.. $. $. # #### ',' # $ # $ **. #. # ',' #. #. ** $ # $ # ',' #### $ # $. $.. ## # ',' ## # $ #### $ ## ',' ####.. # # ',' # $ #### ',' #. ### ',' #### $ ## ',' ## @ # ',' #### '] Solution [Solution.Length] =' ';</p> <p></ script></p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-25960.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="25960" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.045</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'Sr8DoFXjVNkVH6npxjpYUo9NVdJcJ1WpjJfvL9zxqNudLIx7nmPpJtl_2FKxZSetbqDDVPwyMHA0zVreRbYS84bQ_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>