这篇文章主要为大家详细介绍了基于JavaScript实现五子棋游戏,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了js实现五子棋的具体代码,供大家参考,具体内容如下
思路:
1、先用canvas画五子棋的棋盘
2、获取鼠标点击的位置
3、根据鼠标点击的位置判断,并画棋子
4、根据下的棋子判断是否赢了
代码:
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <style> * { padding: 0; margin: 0; } canvas { margin: 10px; border: 2px solid #000; } #box { display: inline-block; position: absolute; margin-top: 200px; margin-left: 100px; } span { font: 24px "微软雅黑"; display: inline-block; height: 50px; } input { margin-top: 30px; display: block; width: 100px; height: 50px; font: 16px "微软雅黑"; color: #fff; background-color: #0099cc; } </style> </head> <body> <canvas width="640" hei