看誰(shuí)圍的框子多?
這是一個(gè)死亡游戲,藍(lán)色的先行,看誰(shuí)圍的框子多,誰(shuí)就死。
<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"," " + (player ? "N" : "R") + " ")
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) || (x1)) {
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) || (y0) {
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 ((x0) && (x>0)) {
if (dirX>=dirY) {
if (x")
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 = "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 ("")
}
var boardArray = new Object
function buildBoard() {
initCache()
board = ("")
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 = "Navy player goes first. Good Luck!"
updateScore()
}
document.write("" + buildBoard() + " ")
document.all.board.onmousemove = doMouseMove
document.all.board.onclick = doClick
</script>
Navy player
goes first. Good Luck!
|