Created
September 20, 2018 11:10
-
-
Save flxxyz/cd4fe2d53380598cbfc150d75f372426 to your computer and use it in GitHub Desktop.
五子棋基本模块
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var drawChessBoard = function(){ | |
for(var i = 0; i < 15; i++){ | |
context.moveTo(15 + i * 30 , 15); | |
context.lineTo(15 + i * 30 , 435); | |
context.stroke(); | |
context.moveTo(15 , 15 + i * 30); | |
context.lineTo(435 , 15 + i * 30); | |
context.stroke(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//绘制棋子 | |
var oneStep = function(i,j,me){ | |
// debugger; | |
context.beginPath(); | |
context.arc(15 + i * 30, 15 + j * 30, 13, 0, 2 * Math.PI);//画圆 | |
context.closePath(); | |
//渐变 | |
var gradient = context.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'); | |
} | |
context.fillStyle = gradient; | |
context.fill(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//赢法数组 | |
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++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment