【软件分享】貌似这两天围堵游戏挺受欢迎,升级为自定义关卡版本。
有谁设计的关卡不错来分享一下。
收集经典的关卡:http://www.renrousousuo.com/Rounded.aspx
自定义关卡:http://www.renrousousuo.com/Scripts/Rounded.html
/*--标题:围堵设计:王集鹄博客:http://blog.csdn.net/zswang日期:2009年12月5日--*///2009年12月6日 王集鹄 添加 地图参数、马和象的走法、操作次数、图像样式的兼容 function Box(options) { options = options || {}; var self = this; this.rowCount = options.rowCount || 15; // 行数 this.colCount = options.colCount || 15; // 列数 this.kickCount = options.kickCount || 1; // 玩家操作多少次一个周期 this.parent = options.parent || document.body; // 容器 this.caption = options.caption || "Replay"; // 标题 this.map = (options.map || "").replace(/\s+/g, ""); // 地图数据 this.button = document.createElement("input"); this.button.type = "button"; this.button.value = this.caption; this.button.onclick = function() { self.replay(); }; this.parent.appendChild(this.button); this.table_back = document.createElement("table"); this.table_back.className = "table_back"; this.table_back.cellPadding = "0px"; this.table_back.cellSpacing = "0px"; this.playing = false; // 是否在进行中 this.floors = {}; // 矩阵地板矩阵 [y,x] for (var i = 0; i < this.rowCount; i++) { var tr = this.table_back.insertRow(-1); for (var j = 0; j < this.colCount; j++) { var td = tr.insertCell(-1); this.floors[i + "," + j] = new Floor({ td: td , box: this , pos: { x: j, y: i } }); } } this.parent.appendChild(this.table_back); this.replay();}// 重新开始Box.prototype.replay = function() { this.playing = true; this.mickeys = []; this.step = 0; var k = 0; for (var i = 0; i < this.rowCount; i++) { for (var j = 0; j < this.colCount; j++) { var name = this.map.substr(k++, 1); switch(name) { case "1": case "x": case "w": case "c": this.floors[i + "," + j].setState("closed"); break; case "r": case "b": case "n": case "q": var mickey = new Mickey({name: name, box: this, pos: {x: j, y: i}}); this.mickeys.push(mickey); break; default: this.floors[i + "," + j].setState("blank"); break; } } }};// 下一个周期Box.prototype.kick = function() { if (!this.playing) return; this.step++; if (this.step % this.kickCount != 0) return; var count = 0; var freedom = false; for (var i = 0; i < this.mickeys.length; i++) { if (this.mickeys[i].run()) count++; if (this.mickeys[i].freedom) freedom = true; } if (freedom) // 有老鼠跑了 this.gameover(); else if (!count) this.win();};// 游戏结束Box.prototype.gameover = function() { if (!this.playing) return; this.playing = false; if (this.ongameover) this.ongameover(); else alert(this.caption + "跑掉了。o(╯□╰)o");};Box.prototype.win = function() { if (!this.playing) return; this.playing = false; if (this.onwin) this.onwin(); else alert(this.caption + "O(∩_∩)O成功!");};// 地板function Floor(options) { options = options || {}; var self = this; this.td = options.td || {}; this.td.innerHTML = " "; this.td.onclick = function() { if (!self.box.playing) return; // 游戏已经结束 if (self.state != "blank") return; self.setState("closed"); self.box.kick(); if (typeof playSound == "function") playSound("move"); // 播放声音 } this.box = options.box || {}; this.pos = options.pos || {}; this.state = "blank"; this.doChange();}// 状态变化Floor.prototype.doChange = function() { var className = "floor"; if (this.state == "blank" && (this.pos.x * this.pos.y == 0 || this.pos.x == this.box.colCount - 1 || this.pos.y == this.box.rowCount - 1)) // 边缘 className += " edge"; className += " " + this.state; if (typeof this.arrow != "undefined") className += " " + this.state + this.arrow; if (this.td.className != className) this.td.className = className;};Floor.prototype.setState = function(state, arrow) { if (this.state == state) return; this.state = state; this.arrow = arrow; this.doChange();};// 老鼠类function Mickey(options) { options = options || {}; this.box = options.box || {}; this.pos = options.pos || {}; // 所在位置 this.name = options.name || "rook"; if (this.name.length == 1) this.name = { "n": "knight", "q": "queen", "r": "rook", "b": "bishop" }[this.name]; this.route = []; // 逃跑路线 this.freedom = false; // 是否获得自由 this.move(this.pos); this.offsets = this.types[this.name].offsets;}Mickey.prototype.types = { "knight": { caption: "?" , offsets: [ { x: -2, y: -1 } , { x: -1, y: -2 } , { x: +2, y: -1 } , { x: +1, y: -2 } , { x: +2, y: +1 } , { x: +1, y: +2 } , { x: -2, y: +1 } , { x: -1, y: +2 } ] } , "queen": { caption: "?" , offsets: [ {x: 0, y: -1} , {x: +1, y: 0} , {x: 0, y: +1} , {x: -1, y: 0} , {x: -1, y: -1} , {x: +1, y: -1} , {x: +1, y: +1} , {x: -1, y: +1} ] } , "rook": { caption: "?" , offsets: [ {x: 0, y: -1} , {x: +1, y: 0} , {x: 0, y: +1} , {x: -1, y: 0} ] } , "bishop": { caption: "?" , offsets: [ {x: -1, y: -1} , {x: +1, y: -1} , {x: +1, y: +1} , {x: -1, y: +1} ] }};// 移动位置Mickey.prototype.move = function(pos) { pos = pos || {}; if (pos.x == this.x && pos.y == this.y) return; if (this.box.floors[this.pos.y + "," + this.pos.x]) this.box.floors[this.pos.y + "," + this.pos.x].setState("blank"); this.pos = pos; this.box.floors[this.pos.y + "," + this.pos.x].setState(this.name, this.arrow); this.freedom = this.pos.x == 0 || this.pos.y == 0 || this.pos.x == this.box.colCount - 1 || this.pos.y == this.box.rowCount - 1;};// 老鼠跑Mickey.prototype.run = function() { this.flags = {}; this.route = []; if (this.search(this.pos, this.route)) { var item = this.route.shift(); this.arrow = item.arrow; this.move(item.pos); return true; }};// 搜索逃跑路径Mickey.prototype.search = function(pos, route) { if (this.flags[pos.y + "," + pos.x]) return false; this.flags[pos.y + "," + pos.x] = true; // 标记已经扫描 // 搜索直观的路径 var directions = {}; // 每个方向的路径 var min = -1; // 最短的距离 for (var i = 0; i < this.offsets.length; i++) { directions[i
new Box({ caption: "第一关(堵車)" , rowCount: 7 , colCount: 7 , map: "\0000000\0000000\0000000\000r000\0000000\0000000\0000000\ "});