⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 超新星制作javascript游戏围框子.htm

📁 检测session或cookies
💻 HTM
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0045)http://df163.com/life/shishang/weikuangzi.htm -->
<HTML><HEAD><TITLE>超新星*制作*JavaScript游戏*围框子</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content="MSHTML 6.00.2800.1106" name=GENERATOR>
<META content=FrontPage.Editor.Document name=ProgId>
<SCRIPT>
function ShowMenu(bMenu) {
document.all.idFinder.style.display = (bMenu) ? "none" : "block" 
document.all.idMenu.style.display = (bMenu) ? "block" : "none"
idML.className = (bMenu) ? "cOn" : "cOff"
idRL.className = (bMenu) ? "cOff" : "cOn"
return false
}
</SCRIPT>

<SCRIPT>
<!--
function addList(url,desc) {
if ((navigator.appName=="Netscape") || (parseInt(navigator.appVersion)>=4)) {
var w=window.open("","_IDHTML_LIST_","top=0,left=0,width=475,height=150,history=no,menubar=no,status=no,resizable=no")
var d=w.document
if (!w._init) {
d.open()
d.write("<TITLE>Loading...</TITLE><EM>Loading...</EM>")
d.close()
d.location.replace("/assist/listing.asp?url="+escape(url)+"&desc="+escape(desc))  
w.opener=self    
window.status="Personal Assistant (Adding): " + desc
} else {
window.status=w.addOption(url,desc)    
w.focus()
}
}
else
alert("你用的浏览器不支持这个程序!")
return false
}
// -->
</SCRIPT>

<STYLE>#board {
	FONT-FAMILY: arial
}
.dot {
	FONT-SIZE: 0pt; BACKGROUND: black; WIDTH: 5px; POSITION: absolute; HEIGHT: 5px
}
#line {
	FONT-SIZE: 0pt; POSITION: absolute; HEIGHT: 5px
}
.p1 {
	FONT-SIZE: 0pt; BACKGROUND: blue; POSITION: absolute
}
.p2 {
	FONT-SIZE: 0pt; BACKGROUND: red; POSITION: absolute
}
.p1B {
	FONT-WEIGHT: bold; FONT-SIZE: 8pt; COLOR: blue; POSITION: absolute; TEXT-ALIGN: center
}
.p2B {
	FONT-WEIGHT: bold; FONT-SIZE: 8pt; COLOR: red; POSITION: absolute; TEXT-ALIGN: center
}
</STYLE>

<STYLE type=text/css>BODY {
	MARGIN-TOP: 0px; FONT-SIZE: 9pt; MARGIN-LEFT: 0px; MARGIN-RIGHT: 0px; FONT-FAMILY: "宋体"
}
A {
	FONT-WEIGHT: 400; FONT-SIZE: 13px; COLOR: black; TEXT-DECORATION: none
}
A:hover {
	FONT-WEIGHT: 400; FONT-SIZE: 13px; COLOR: red; TEXT-DECORATION: underline
}
A:active {
	FONT: 9pt "宋体"; CURSOR: hand; COLOR: #ff0033
}
</STYLE>

<SCRIPT language=JavaScript>
<!-- Begin
var timerRunning = false;
var timezone = "Greenwich Mean Time";
var adjust = 0;

function timeCheck(tzone, diff) {
if (timerRunning) {
clearTimeout(updatetime);
timerRunning = false; }
gmtOffset=eval(diff+adjust);
timezone = tzone;
checkDateTime();
}

function checkDateTime () {
var today = new Date();
var year = today.getYear() + 1900;
var month = today.getMonth()+1;
var date = today.getDate();
var day = today.getDay();
var hour = today.getHours();
var minute = today.getMinutes();
var second = today.getSeconds();

var lastSat = date - (day+1);
while (lastSat < 32) lastSat+=7;
if (lastSat > 31) lastSat+=-7;
var firstSat = date - (day+1);
while (firstSat > 0) firstSat+=-7;
if (firstSat < 1) firstSat+=7;
if ((((month == 4) && (date >= firstSat)) || month > 4) && 
(month < 11 || ((month == 10) && day <= lastSat))) adjust += 60;
yourOffset = (new Date()).getTimezoneOffset();
yourOffset = yourOffset + adjust;

var xx = navigator.appName
var xy = navigator.appVersion;
xy = xy.substring(0,1);
if ((xy == 4) && (xx == "Netscape")) yourOffset = yourOffset+adjust;
if ((((month == 4) && (date > 20)) || month > 4) && (month < 11 || ((month == 10) &&
day < 30))) adjust -= 60;

ourDifference = eval(gmtOffset - yourOffset);
var half = eval(ourDifference % 60);
ourDifference = Math.round(ourDifference / 60);
hour = eval(hour - ourDifference);
var m = new Array("",
"Jan","Feb","Mar",
"Apr","May","Jun",
"Jul","Aug","Sept",
"Oct","Nov","Dec");
var leap = eval(year % 4);

if ((half == -30) || (half == 30)) minute += 30;
if (minute > 59) minute -= 60, hour++;
if (minute < 0) minute += 60, hour--;
if (hour > 23) hour -= 24, date += 1;
if (((month == 4) || (month == 6) || 
(month == 9) || (month == 11)) && (date==31)) date = 1, month ++;
if (((month == 2) && (date > 28)) && (leap != 0)) date = 1, month ++;
if ((month == 2) && (date > 29)) date = 1, month++;
if (hour < 0) hour += 24, date --;
if ((date == 32) && (month == 12)) month = m[1], date = 1, year++;
if (date == 32) date = 1, month++;
if ((date < 1) && (month == 1)) month= m[12], date = 31, year--;
if (date < 1) date = 31, month --;
if (((month == 4) || (month == 6) || 
(month== 9) || (month == 11)) && (date == 31)) date = 30;
if ((month == 2) && (date > 28)) date = 29;
if (((month == 2) && (date > 28)) && (leap != 0)) date=28;
for (i=1; i<13; i++) {
if (month == i) {
month = m[i]; break;
   }
}

var dateTime = hour;
dateTime = ((dateTime < 10) ? "0":"") + dateTime;
dateTime = "   " + dateTime;
dateTime += ((minute < 10) ? ":0" : ":") + minute;
dateTime += ((second < 10) ? ":0" : ":") + second;
dateTime += (hour >= 12) ? " PM, " : " AM, ";
dateTime += month + " " + date + ", " + year;

document.clock.zonetime.value = dateTime;
document.clock.zonename.value = timezone;
updatetime=setTimeout("checkDateTime()", 900);
timerRunning = true;
}
// End -->
</SCRIPT>
</HEAD>
<BODY bgColor=#90c080>
<TABLE cellSpacing=0 cellPadding=0 width=509 border=0>
  <TBODY>
  <TR>
    <TD id=article vAlign=top width=499>
      <P class=start align=center><BIG><BIG><B><U><FONT 
      color=#ffff00>超新星*制作*JavaScript游戏*围框子</FONT></U></B></BIG></BIG></P>
      <P align=center>这是一个双人游戏,蓝色的先行,看谁围的框子多,谁就赢。</P>
      <P style="MARGIN-TOP: 5pt">
      <SCRIPT>
  /* DHTML Dots is copyright 1998 insideDHTML.com, LLC. All rights reserved.
     DHTML Dots cannot be reproduced in any manner without prior consent from insideDHTML.com */

  var scale= 25
  var size = 5

  var totalSize = ((size+1)*scale) + 6
  var cache = new Object()
  var move=0,point=0
  var player = true

  function initCache() {
    cache.x = 0
    cache.y = 0
    cache.red = 0
    cache.blue = 0
    move=0,point=0    
  }

  function updateScore() {
    document.all.red.innerText = cache.red
    document.all.blue.innerText = cache.blue
    if ((cache.red+cache.blue)==((size-1)*(size-1))) {
      board.onclick = null
      document.all.message.innerText = "Game Over!"
    }
     
  }

  function fillPos(x,y) {
    document.all.board.insertAdjacentHTML("beforeEnd","<DIV class=" + (player ? "p1B" : "p2B") + " ID=\"point"+point+"\">" + (player ? "N" : "R") + "</DIV>")
    var el = document.all["point"+point].style
    el.pixelTop = (y*scale)+5
    el.pixelLeft = (x*scale)+5
    el.pixelWidth = scale - 5
    el.pixelHeight = scale - 5

  }

  function checkBoard(x,y,dir, player) {
    var piece=0
    if ("vertical"==dir) {
      if ((x==size) || (x>1)) {
        var bPos = boardArray[x-1][y]
        var nextV = boardArray[x-1][y+1]
        if ((bPos["vertical"]) && (bPos["horizontal"]) && (nextV["horizontal"])) {
          point++
          piece++
          fillPos(x-1,y)
        }
      } 
      if ((x==1) || (x<size)) {
          var nextV = boardArray[x+1][y]
          var nextH = boardArray[x][y+1]
          if ((nextV["vertical"]) && (nextH["horizontal"]) && (boardArray[x][y]["horizontal"])) {
            point++
            piece++
            fillPos(x,y)
          }
      }   
    }    
    else {
      if ((y==size) || (y>1)) {
        var nextV = boardArray[x+1][y-1]
        var bPos = boardArray[x][y-1]
        if ((bPos["vertical"]) && (bPos["horizontal"]) && (nextV["vertical"])) {
          point++
          piece++
          fillPos(x,y-1)
        } 
      }
      if ((y==1) || (y<size)) {
        var nextV = boardArray[x+1][y]
        var nextH = boardArray[x][y+1]
        if ((nextV["vertical"]) && (nextH["horizontal"]) && (boardArray[x][y]["vertical"])) {
          point++
          piece++
          fillPos(x,y)
        }
      }
    } 
    if (piece>0) {
      if (player)
       cache.blue+=piece
      else
       cache.red+=piece
      document.all.message.innerText = "Score! Go Again."
      updateScore()
      return player
    }
    else
      return !player
        
  }

  function doMouseMove() {
    if (event.srcElement.className!="dot") {
      var x = Math.floor(event.offsetX / scale) 
      var y = Math.floor(event.offsetY / scale) 
      var dirX = (event.offsetX % scale)
      var dirY = (event.offsetY % scale)
      if ((x<size+1) && (y<size+1) && (y>0) && (x>0)) {
        if (dirX>=dirY) {
          if (x<size) {
            line.style.pixelHeight = 5 
            line.style.pixelWidth = scale  - 5
            line.style.pixelTop = (y * scale) 
            line.style.pixelLeft = (x * scale) + 5
            cache.direction = "horizontal"
          }
        } else
        {
          if (y<size) { 
            line.style.pixelWidth = 5 
            line.style.pixelHeight = scale - 5
            line.style.pixelTop = (y * scale) + 5
            line.style.pixelLeft = x * scale
            cache.direction = "vertical"
          }
        }
        cache.x = x
        cache.y = y
      }
    }
    
  }

  function doClick() {

    if (cache.x==0) return
    if (boardArray[cache.x][cache.y][cache.direction])
      document.all.message.innerText="That spot is taken! Choose again"
    else {
      document.all.board.insertAdjacentHTML("beforeEnd","<DIV class=" + (player ? "p1" : "p2") + " ID=move"+move+"></DIV>")
      var el = document.all["move"+move]
      el.style.top = line.style.top 
      el.style.left = line.style.left 
      el.style.width = line.style.width
      el.style.height = line.style.height
      boardArray[cache.x][cache.y][cache.direction]=true
      var nextPlayer = checkBoard(cache.x,cache.y,cache.direction, player)
      if (nextPlayer!=player) {
        player = nextPlayer
        if (player) {
          document.all.message.innerText = "blue players turn"
          line.style.border = "1px blue solid"
        }
        else {
          document.all.message.innerText = "Red players turn"
          line.style.border = "1px red solid"
        }
      }
    }

 
    move++
  }

  function buildDiv(x,y, scale) {
    return ("<DIV CLASS=dot STYLE=\"top:" +  (x*scale) + "; left: " + (y*scale) + "\"></DIV>")
  }   

  var boardArray = new Object


  function buildBoard() {
    initCache()
    board = ("<DIV ID=line STYLE=\"border: 1px blue solid; width: 0; height: 0\"></DIV>")
    boardArray = new Object()
    for (var x=1; x < size+1; x++) {
      boardArray[x] = new Object()
      for (var y=1; y < size+1; y++) {
        boardArray[x][y] = new Object
        boardArray[x][y]["vertical"] = false
        boardArray[x][y]["horizontal"] = false
        board+=(buildDiv(x,y, scale))
      }
    }

    return board
  }

  function createGame() {
    size=parseInt(document.all.setSize.value)
    if (size>12)
      size=12
    if (size<3)
      size=3
    document.all.setSize.value = size
    document.all.board.innerHTML = buildBoard()
    document.all.board.onclick = doClick
    totalSize = ((size+1)*scale) + 6
    document.all.board.style.pixelWidth = totalSize
    document.all.board.style.pixelHeight = totalSize
    document.all.message.innerText = "blue player goes first. Good Luck!"
    updateScore()    
  }
  document.write("<DIV ID=board STYLE=\"position: relative; height: "+ totalSize + "; width:" + totalSize + "; border: 1px black solid\">" + buildBoard() + "</DIV>")
  document.all.board.onmousemove = doMouseMove
  document.all.board.onclick = doClick

</SCRIPT>
      </P>
      <DIV style="MARGIN-TOP: 5pt; MARGIN-LEFT: 10pt">
      <P class=start id=message>蓝方先行,祝你好运。</P>
      <DD><BR>
      <TABLE width=100 border=1>
        <TBODY>
        <TR>
          <TD style="COLOR: red"><B>红方</B></TD>
          <TD id=red>0</TD></TR>
        <TR>
          <TD style="COLOR: blue"><B>蓝方</B></TD>
          <TD id=blue>0</TD></TR></TBODY></TABLE>
      <P><BR></P>
      <TABLE width=200>
        <TBODY>
        <TR>
          <TD>游戏大小: </TD>
          <TD><INPUT id=setSize size=2 value=5></TD></TR>
        <TR>
          <TD align=middle colSpan=2><INPUT onclick=createGame() type=button value=开始新游戏></TD></TR></TBODY></TABLE>
      <P class=copyright></P></DD></DIV></TD></TR></TBODY></TABLE></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -