用QuickClick练习鼠标定位
添加时间: 2005-6-9 4:52:54 作者: 网络收集 阅读次数:85 来源: http://d9soft.com
<html>
<head>
<title>Quick_Click</title>
<SCRIPT Language="JavaScript">
/*
All Files are Designed & Writen by Windy_sk, you can use it freely but ...
YOU MUST KEEP THIS ITEM !
Email: d9soft@163.com
*/
function GetRandomNum(Min,Max){
var Range = Max - Min;
var Rand = Math.random();
return(Min + Math.round(Rand * Range));
}
function reportError(msg,url,line) {
var str = "You have found an error as below: \n\n";
str += "Err: " + msg + " on line: " + line;
alert(str);
return true;
}
window.onerror = reportError;
var info_bar = new Object();
var arc_obj = new Object();
var arc_lst = new Array();
var arc_timer = new Array();
var arc_time_unit = 200;
var level = 1;
var hp_max = 20;
var hp_cur = 20;
var lv_limit = 10;
var lv_cur = 1;
var lv_timer = null;
var lv_time_unit = 1000;
function arc_insert() {
var idx = arc_lst.length;
var cur_arc = arc_obj.cloneNode();
cur_arc.style.top = GetRandomNum(100, game_board.document.body.offsetHeight-100);
cur_arc.style.left = GetRandomNum(100, game_board.document.body.offsetWidth-100);
cur_arc.idx = idx;
if(GetRandomNum(1,10)>8) {
cur_arc.FillColor = "red";
cur_arc.StrokeColor = "red";
} else if(GetRandomNum(1,10)>9) {
cur_arc.FillColor = "blue";
cur_arc.StrokeColor = "blue";
}
cur_arc.onclick = arc_click;
game_board.document.body.insertBefore(cur_arc);
arc_lst[idx] = cur_arc;
arc_timer[idx] = setInterval("arc_show("+idx+")",arc_time_unit);
return;
}
function arc_show(idx) {
var cur_arc = arc_lst[idx];
if(typeof(cur_arc) != "object") return;
cur_arc.filters.alpha.opacity += 5;
cur_arc.style.width = parseInt(cur_arc.style.width) - 5;
cur_arc.style.height = parseInt(cur_arc.style.height) - 5;
if(cur_arc.filters.alpha.opacity >= 100){
cur_arc.removeNode();
arc_lst[idx] = null;
clearInterval(arc_timer[idx]);
arc_timer[idx] = null;
hp_cur--;
hp_show.innerText = hp_cur + "/" + hp_max;
modi_bar(hp_bar, hp_cur, hp_max);
if(hp_cur <= 0) {
for(var i=0; i<arc_lst.length; i++) {
if(arc_timer[i] != null)clearInterval(arc_timer[i]);
if(arc_lst[i] != null)arc_lst[i].removeNode();
}
start.disabled = false;
clearInterval(lv_timer);
show_info("Game Over !")
}
}
return;
}
function modi_bar(obj, cur, max) {
var rate = Math.ceil(cur * 100 / max);
if(isNaN(rate) rate < 0)rate = 0;
if(rate > 100) rate = 100;
obj.rows[0].cells[0].style.width = rate + "%";
obj.rows[0].cells[1].style.width = (100 - rate) + "%";
return;
}
function arc_click() {
var idx = game_board.event.srcElement.idx;
var cur_arc = arc_lst[idx];
clearInterval(arc_timer[idx]);
cur_arc.filters.alpha.opacity = 100;
cur_arc.onclick = null;
arc_timer[idx] = setInterval("arc_out("+idx+")", 10);
point.innerText = parseInt(point.innerText) + 1
if(cur_arc.FillColor == "red") {
hp_cur++;
if(hp_cur > hp_max) hp_cur = hp_max;
hp_show.innerText = hp_cur + "/" + hp_max;
modi_bar(hp_bar, hp_cur, hp_max);
} else if(cur_arc.FillColor == "blue") {
hp_max++;
hp_show.innerText = hp_cur + "/" + hp_max;
modi_bar(hp_bar, hp_cur, hp_max);
}
return;
}
function arc_out(idx) {
var cur_arc = arc_lst[idx];
cur_arc.style.left = parseInt(cur_arc.style.left) + 10;
if(cur_arc.offsetLeft > screen.width){
cur_arc.removeNode();
arc_lst[idx] = null;
clearInterval(arc_timer[idx]);
arc_timer[idx] = null;
}
}
function go_stage(lv) {
if(isNaN(lv) lv < 0) lv = 0;
if(lv > 9) lv = 9;
stg_lv.innerHTML = " " + (lv + 1) + " ";
lv_cur = 1;
lv_limit = 10 + lv * 10;
stg_info.innerText = "1/" + lv_limit;
modi_bar(stg_info_bar, lv_cur, lv_limit);
lv_time_unit = 1000 - lv * 100;
arc_lst = new Array();
arc_timer = new Array();
arc_insert();
lv_timer = setInterval("go_stage_step("+lv+")", lv_time_unit);
}
function go_stage_step(lv) {
if(++lv_cur>lv_limit){
clearInterval(lv_timer);
lv++;
setTimeout("show_info('Stage " + lv + " Clear !')", 2000)
setTimeout("go_stage("+lv+")", 5000);
}else{
stg_info.innerText = lv_cur + "/" + lv_limit;
modi_bar(stg_info_bar, lv_cur, lv_limit);
arc_insert();
}
}
function show_info(str){
info_bar.filters.revealTrans.transition=GetRandomNum(1,23);
info_bar.style.left=(game_board.document.body.offsetWidth-200)/2;
info_bar.style.top =(game_board.document.body.offsetHeight-40)/4;
info_bar.innerHTML="<table border=0 width=100% height=100%><tr><td align=center valign=middle style='font-size:16px; FONT-WEIGHT:bold;'>" + str + "</td></tr></table>";
info_bar.filters.revealTrans.apply();
info_bar.style.display = "";
info_bar.filters.revealTrans.play();
setTimeout("info_bar.style.display='none'",2000);
}
window.onload = function(){
game_board.document.open();
game_board.document.write("<html xmlns:v='urn:schemas-microsoft-com:vml'>\n<head>\n<title>Arc_Click</title>\n<STYLE>\n v\\:* { BEHAVIOR: url(#default#VML) }\n</STYLE>\n</head>\n<body scroll='no' onselectstart='return false' oncontextmenu='return false'></body>\n</html>");
game_board.document.close();
arc_obj = game_board.document.createElement("<v:arc style='position:absolute;width:100;height:100;filter:alpha(opacity=0);' StartAngle='0' EndAngle='360' Filled='true' FillColor='gray' StrokeColor='gray' StrokeWeight='1px' />");
info_bar = game_board.document.createElement("<div style='background-color: #eeeeee; width:200px; height:40px; FILTER: revealTrans(transition=23,duration=0.5) blendTrans(duration=0.5); position:absolute; text-align: center; border:0px solid black; display:none; zindex:999'></div>");
game_board.document.body.insertBefore(info_bar);
}
</SCRIPT>
</head>
<body scroll="no" onselectstart="return false">
<table style="border:0px;width:100%;height:100%">
<tr>
<td>
<iframe scrolling="no" id="game_board" src="about:blank" MARGINHEIGHT="0" MARGINWIDTH="0" style="width:100%; height:100%;"></iframe>
</td>
<td style="width:200px">
<table style="border:1px black solid;width:100%;height:100%">
<tr>
<td valign="top">
<span style="font-family: Arial, Helvetica; font-size: 18px">Stage <span id="stg_lv"> 1 </span></span><br />
<br />
<table style="border:0px;width:100%">
<tr>
<td width="60"><b>State :</b></td>
<td>
<table id="stg_info_bar" style="border:1px black solid;width:100px;height:100%">
<tr>
<td style="width:100%; background-color:skyblue; height:10px"></td>
<td style="width:0%"></td>
</tr>
</table>
</td>
<td width="20"><span id="stg_info">0/10</span></td>
</tr>
</table>
<br />
<table style="border:0px;width:100%">
<tr>
<td width="60"><b>Health:</b></td>
<td>
<table id="hp_bar" style="border:1px black solid;width:100px;height:100%">
<tr>
<td style="width:100%; background-color:skyblue; height:10px"></td>
<td style="width:0%"></td>
</tr>
</table>
</td>
<td width="20"><span id="hp_show">20/20</span></td>
</tr>
</table>
<br />
<table style="border:0px;width:100%">
<tr>
<td width="60"><b>Point :</b></td>
<td><span id="point">0</span></td>
</tr>
</table>
<br />
<center><input id="start" type="button" onclick="this.disabled=true;go_stage(0);hp_max=20" value="Start"></center>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
上一篇文章: CSS锦囊 下一篇文章: CSS轻松实现色块标题标识

