Cheer 发表于 2007-4-28 11:09:46

游戏类益智游戏 要求:把所有格子都填满黄色

把下列代码加到网页的<body></body>标签之间 从google下载我的照片管理软件
要完成此效果需要两个步骤

第一步:把如下代码加入到<head>区域中

<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>

<style>

<!--

a.con {text-decoration:none;font-weight:bolder}

#article {font: 12pt verdana, geneva, arial, sans-serif;background: white; color: black;

padding: 10pt 15pt 0 5pt}

#article p.start {text-indent: 0pt}

#article p {margin-top:0pt;font-size:10pt;text-indent:12pt}

#article #author {margin-bottom:5pt;text-indent:0pt;font-style: italic}

#pagelist p {padding-top:10pt}

#article h3 {font-weight:bold}

#article dl, ul, ol {font-size: 10pt}

-->

</style>

<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("your browser does not support the personal assistant.")

return false

}

// -->

</script>



<style>

#board {font-family: arial}

.dot {position: absolute; width: 5px; height: 5px; font-size: 0pt; background: black}

#line {position: absolute; font-size: 0pt; height: 5px}

.p1 {position: absolute; font-size: 0pt;background: navy}

.p2 {position: absolute; font-size: 0pt;background: red}

.p1b {position: absolute; font-size: 8pt; color: navy;text-align: center; font-weight: bold}

.p2b {position: absolute; font-size: 8pt; color: red; text-align: center; font-weight: bold}

</style>

<style type="text/css">

<!--

body {font-family: "宋体"; font-size: 9pt; margin-top: 0px; margin-left: 0px; margin-right:

0px}

a { color: black; font-size: 13px; font-weight: 400; text-decoration: none }

a:hover { color: red; font-size: 13px; font-weight: 400; text-decoration: underline }

a:active   { font: 9pt "宋体"; cursor: hand; color: #ff0033 }



-->

</style>

<meta http-equiv="content-type" content="text/html; charset=gb2312">

<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, date = 1, year++;

if (date == 32) date = 1, month++;

if ((date < 1) && (month == 1)) month= m, 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; 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>


第二步:把如下代码加入到<body>区域中

<table cellpadding="0" cellspacing="0" border="0" width="509">

<tr>

    <td width="10"></td>

    <td valign="top" width="499" id="article"><p class="start" style="text-align: left"><font

    size="+2" style="font-weight:bold;font-size: 14pt"><b>看谁围的框子多?</b></font></p>

    <p>这是一个双人游戏,蓝色的先行,看谁围的框子多,谁就赢。</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.navy = 0

    move=0,point=0   

}



function updatescore() {

    document.all.red.innertext = cache.red

    document.all.navy.innertext = cache.navy

    if ((cache.red+cache.navy)==((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

      var nextv = boardarray

      if ((bpos["vertical"]) && (bpos["horizontal"]) && (nextv["horizontal"])) {

          point++

          piece++

          fillpos(x-1,y)

      }

      }

      if ((x==1) || (x<size)) {

          var nextv = boardarray

          var nexth = boardarray

          if ((nextv["vertical"]) && (nexth["horizontal"]) && (boardarray["horizontal"])) {

            point++

            piece++

            fillpos(x,y)

          }

      }   

    }   

    else {

      if ((y==size) || (y>1)) {

      var nextv = boardarray

      var bpos = boardarray

      if ((bpos["vertical"]) && (bpos["horizontal"]) && (nextv["vertical"])) {

          point++

          piece++

          fillpos(x,y-1)

      }

      }

      if ((y==1) || (y<size)) {

      var nextv = boardarray

      var nexth = boardarray

      if ((nextv["vertical"]) && (nexth["horizontal"]) && (boardarray["vertical"])) {

          point++

          piece++

          fillpos(x,y)

      }

      }

    }

    if (piece>0) {

      if (player)

       cache.navy+=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)

      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=true

      var nextplayer = checkboard(cache.x,cache.y,cache.direction, player)

      if (nextplayer!=player) {

      player = nextplayer

      if (player) {

          document.all.message.innertext = "navy players turn"

          line.style.border = "1px navy 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 navy solid; width: 0; height: 0\"></div>")

    boardarray = new object()

    for (var x=1; x < size+1; x++) {

      boardarray = new object()

      for (var y=1; y < size+1; y++) {

      boardarray = new object

      boardarray["vertical"] = false

      boardarray["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 = "navy 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-left: 10pt; margin-top: 5pt"><p class="start" id="message">navy player

    goes first. good luck!</p>

    <dd><br>

      <table border="1" width="100">

      <tr>

          <td style="color: red"><b>red</b></td>

          <td id="red">0</td>

      </tr>

      <tr>

          <td style="color: navy"><b>navy</b></td>

          <td id="navy">0</td>

      </tr>

      </table>

      <p><br>

      </p>

      <table width="200">

      <tr>

          <td>游戏大小: </td>

          <td><input type="text" value="5" id="setsize" size="2"></td>

      </tr>

      <tr>

          <td colspan="2" align="center"><input type="button" onclick="creategame()"

          value="new game"></td>

      </tr>

      </table> <p class="copyright"> </p>

    </dd>

    </div></td>

</tr>

</table>
页: [1]
查看完整版本: 游戏类益智游戏 要求:把所有格子都填满黄色