javascript: function ccc() { if (!window.console) { window.console = { log: function() {} }; return; } var me = 19; var Star = function() { this.x = 0; this.speed = 1; this.y = 0; }; var score = 0; var strs = function() { var result = ''; for (var i = 0; i < 20; i++) { result += "\n"; for (var n = 0; n < 40; n++) { var now = '---'; if (i == 19 && n == me) { now = "码农"; } stars.forEach(function(star) { var x = Math.floor(star.x); var y = Math.floor(star.y); if (x == n && y == i) { if (Math.abs(star.y - 19) < 1 && (n == me)) { die(); } now = "BUG"; } }); result += now; } } result += " 得分:" + score; return result; }; window.onkeydown = function(e) { if (e.keyCode == 37) { me -= 1; if (me < 0) me = 0; } else if (e.keyCode == 39) { me += 1; if (me > 38) me = 38; } }; var count = 0; var die = function() { clearInterval(timer1); clearInterval(timer2); clearInterval(timer3); setTimeout(function() { console.log("游戏结束,您的得分:" + score); }, 100); }; var stars = []; var timer1, timer2, timer3; var begin = function() { timer1 = setInterval(function() { var createCount = Math.floor(Math.random() * 5 * appearP); for (var i = 0; i < createCount; i++) { var star = new Star(); star.x = Math.floor(Math.random() * 40); star.y = 0; star.speed = Math.random() * appearP; stars.push(star); } }, 1000); timer2 = setInterval(function() { stars.forEach(function(star, i) { star.y += star.speed; if (star.y >= 21) { stars.splice(i, 1); score++; } }); console.log(strs()); count++; if (count > 300) { console.clear(); count = 0; } }, 100); timer3 = setInterval(function() { appearP *= 1.1; }, 3000); }; console.log("输入 start(); 后即可开始《 码农躲bug》 游戏! "); window.start = function() { appearP = 1.1; starts = []; stars = []; score = 0; me = 19; count = 0; console.log("使用键盘左右键移动最下方的码农,躲开所有的bug,bug数量和速度会一直增加,看看谁坚持的最久吧!"); var countdown = 3; setTimeout(function() { if (countdown-- <= 1) { begin(); } else { console.log(countdown); setTimeout(arguments.callee, 1000); } }, 1000); return ("倒计时!"); }; start(); }; function insertafter(newElement, targetElement) { var parent = targetElement.parentNode; if (parent.lastChild == targetElement) { parent.appendChild(newElement); } else { parent.insertBefore(newElement, targetElement.nextSibling); } } function loading() { var btn = document.createElement("button"); btn.id = "btn"; btn.innerHTML = "码农躲bug"; btn.style.position = "fixed"; btn.style.top = "0px"; btn.style.left = "0px"; btn.style.width = "100px"; btn.style.height = "40px"; btn.style.backgroundColor = "#008CBA"; btn.style.zIndex = 10001; btn.style.fontSize = "12px"; if (document.getElementById("btn") == null) { document.body.appendChild(btn); } } loading(); document.getElementById("btn").addEventListener("click", ccc);
javascript: function ccc() { if (!window.console) { window.console = { log: function() {} }; return; } var me = 19; var Star = function() { this.x = 0; this.speed = 1; this.y = 0; }; var score = 0; var strs = function() { var result = ''; for (var i = 0; i < 20; i++) { result += "\n"; for (var n = 0; n < 40; n++) { var now = '□□□'; if (i == 19 && n == me) { now = "■■■"; } stars.forEach(function(star) { var x = Math.floor(star.x); var y = Math.floor(star.y); if (x == n && y == i) { if (Math.abs(star.y - 19) < 1 && (n == me)) { die(); } now = "■■■"; } }); result += now; } } result += "\n得分:" + score; return result; }; window.onkeydown = function(e) { if (e.keyCode == 37) { me -= 1; if (me < 0) me = 0; } else if (e.keyCode == 39) { me += 1; if (me > 38) me = 38; } }; var count = 0; var die = function() { clearInterval(timer1); clearInterval(timer2); clearInterval(timer3); setTimeout(function() { var aaa = "游戏结束,您的得分:" + score; mask_msg.innerText = aaa; }, 100); }; var stars = []; var timer1, timer2, timer3; var begin = function() { timer1 = setInterval(function() { var createCount = Math.floor(Math.random() * 5 * appearP); for (var i = 0; i < createCount; i++) { var star = new Star(); star.x = Math.floor(Math.random() * 40); star.y = 0; star.speed = Math.random() * appearP; stars.push(star); } }, 1000); timer2 = setInterval(function() { stars.forEach(function(star, i) { star.y += star.speed; if (star.y >= 21) { stars.splice(i, 1); score++; } }); mask_msg.innerText = strs(); count++; if (count > 300) { console.clear(); count = 0; } }, 100); timer3 = setInterval(function() { appearP *= 1.1; }, 3000); }; window.start = function() { appearP = 1.1; starts = []; stars = []; score = 0; me = 19; count = 0; var mask_msg = document.getElementById("maskmsg"); var countdown = 3; setTimeout(function() { if (countdown-- <= 1) { begin(); } else { mask_msg.innerText = countdown; setTimeout(arguments.callee, 1000); } }, 1000); mask_msg.innerText = "倒计时!"; }; start(); }; var mask_bg = document.createElement("div"); mask_bg.id = "mask_bg"; mask_bg.style.position = "fixed"; mask_bg.style.top = "0px"; mask_bg.style.left = "0px"; mask_bg.style.width = "100%"; mask_bg.style.height = "100%"; mask_bg.style.backgroundColor = "#777"; mask_bg.style.zIndex = 10001; if (document.getElementById("mask_bg") == null) { document.body.appendChild(mask_bg); } var mask_msg = document.createElement("div"); mask_msg.id = "maskmsg"; mask_msg.style.position = "absolute"; mask_msg.style.top = "30%"; mask_msg.style.left = "50%"; mask_msg.style.background = 'white'; mask_msg.style.width = "1000px"; mask_msg.style.height = "600px"; mask_msg.style.marginLeft = "-500px"; mask_msg.style.border = "#336699 1px solid"; mask_msg.style.textAlign = "left"; mask_msg.style.fontSize = "12px"; mask_msg.style.padding = "0.5em 3em 0.5em 3em"; mask_msg.style.zIndex = 10002; mask_msg.innerText = "点击按钮开始"; if (document.getElementById("maskmsg") == null) { mask_bg.appendChild(mask_msg); } var btn = document.createElement("button"); btn.id = "btn"; btn.innerHTML = "开始"; btn.style.position = "fixed"; btn.style.top = "0px"; btn.style.left = "0px"; btn.style.width = "100px"; btn.style.height = "40px"; btn.style.backgroundColor = "#008CBA"; btn.style.zIndex = 10003; btn.style.fontSize = "12px"; if (document.getElementById("btn") == null) { document.body.appendChild(btn); } document.getElementById("btn").addEventListener("click", ccc);
浙公网安备 33010602011771号