五子棋html小游戏
代码语言:html
所属分类:游戏
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>人工智能五子棋</title> <meta name="viewport" content="device-width; initial-scale=1.0;" /> <style> #c1 { display: block; margin: 60px auto; box-shadow: 1px 1px 5px #000000; } </style> <script> window.onload = function() { var oC = document.getElementById('c1'); var oGc = oC.getContext('2d'); var over = false; oGc.strokeStyle = "#bfbfbf"; for (var i = 0; i < 15; i++) { oGc.moveTo(15+i*30, 15); oGc.lineTo(15+i*30, 435); oGc.stroke(); oGc.moveTo(15, 15+i*30); oGc.lineTo(435, 15+i*30); oGc.stroke(); } var wins = []; for (var i = 0; i < 15; i++) { wins[i] = []; for (var j = 0; j < 15; j++) { wins[i][j] = []; }} var count = 0; for (var i = 0; i < 15; i++) { for (var j = 0; j < 11; j++) { for (var k = 0; k < 5; k++) { wins[i][j+k][count] = true; } count++; }} for (var i = 0; i < 15; i++) { for (var j = 0; j < 11; j++) { for (var k = 0; k < 5; k++) { wins[j+k][i][count] = true; } count++; }} for (var i = 0; i < 11; i++) { for (var j = 0; j < 11; j++) { for (var k = 0; k < 5; k++) { wins[i+k][j+k][count] = true; } count++; }} for (var i = 0; i < 11; i++) { for (var j = 14; j > 3; j--) { for (var k = 0; k < 5; k++) { wins[i+k][j-k][count] = true; } count++; }} var myWin = []; var computerWin = []; for (var i = 0; i < count; i++) { myWin[i] = 0; computerWin[i] = 0; } function oneStep(i, j, me) { oGc.beginPath(); oGc.arc(15+i*30, 15+j*30, 13, 0, 2*Math.PI); oGc.closePath(); var gradient = oGc.createRadialGradient(15+i*30+2, 15+j*30+2, 13, 15+i*30+2, 15+j*30+2, 0); if (me) { gradient.addColorStop(0, "#0A0A0A"); gradient.addColorStop(1, "#636766"); } else { gradient.addColorStop(0, "#D1D1D1"); gradient.addColorStop(1, "#F9F9F9"); } oGc.fillStyle = gradient; oGc.fill(); }; var me = true; var chessBoard = []; for (var i = 0; i < 15; i++) { chessBoard[i] = []; for (var j = 0; j < 15; j++) { chessBoard[i][j] = 0; }}; oC.onclick = function(ev) { if (!me) { return; } if (over) { return; } var x = ev.offsetX; var y = ev.offsetY; var i = Math.floor(x/30); var j = Math.floor(y/30); if (chessBoard[i][j] == 0) { .........完整代码请登录后点击上方下载按钮下载查看
网友评论0