前言:很久之前闲着没事的时候写的,当时技术特菜,代码写的极其不规范,堪称shit山代码,请看到的大佬轻喷。
废话不多说代码如下:
这个vue3的围棋项目核心的代码就是在这个chessboard 的组件里面。
下面是组件中的代码:
<template>
<div class="chessBoardPage_main">
<!-- <div class="chessBoardPage_head">
<div class="chessBoardPage_head_title"></div>
</div> -->
<div class="chessBoardPage_container">
<div class="theSlot">
<slot name="select"></slot>
</div>
<div class="chessBoardPage_container_chessboard">
<div class="chessarea">
<span
v-for="item in numberarray"
:key="item.index"
:class="'A' + item.id"
@click="chessdown"
></span>
<span
v-for="item in numberarray"
:key="item.index"
:class="'B' + item.id"
@click="chessdown"
></span>
<span
v-for="item in numberarray"
:key="item.index"
:class="'C' + item.id"
@click="chessdown"
></span>
<span
v-for="item in numberarray"
:key="item.index"
:class="'D' + item.id"
@click="chessdown"
></span>
<span
v-for="item in numberarray"
:key="item.index"
:class="'E' + item.id"
@click="chessdown"
></span>
<span
v-for="item in numberarray"
:key="item.index"
:class="'F' + item.id"
@click="chessdown"
></span>
<span
v-for="item in numberarray"
:key="item.index"
:class="'G' + item.id"
@click="chessdown"
></span>
<span
v-for="item in numberarray"
:key="item.index"
:class="'H' + item.id"
@click="chessdown"
></span>
<span
v-for="item in numberarray"
:key="item.index"
:class="'I' + item.id"
@click="chessdown"
></span>
<span
v-for="item in numberarray"
:key="item.index"
:class="'J' + item.id"
@click="chessdown"
></span>
<span
v-for="item in numberarray"
:key="item.index"
:class="'K' + item.id"
@click="chessdown"
></span>
<span
v-for="item in numberarray"
:key="item.index"
:class="'L' + item.id"
@click="chessdown"
></span>
<span
v-for="item in numberarray"
:key="item.index"
:class="'M' + item.id"
@click="chessdown"
></span>
<span
v-for="item in numberarray"
:key="item.index"
:class="'N' + item.id"
@click="chessdown"
></span>
<span
v-for="item in numberarray"
:key="item.index"
:class="'O' + item.id"
@click="chessdown"
></span>
<span
v-for="item in numberarray"
:key="item.index"
:class="'P' + item.id"
@click="chessdown"
></span>
<span
v-for="item in numberarray"
:key="item.index"
:class="'Q' + item.id"
@click="chessdown"
></span>
<span
v-for="item in numberarray"
:key="item.index"
:class="'R' + item.id"
@click="chessdown"
></span>
<span
v-for="item in numberarray"
:key="item.index"
:class="'S' + item.id"
@click="chessdown"
></span>
</div>
<div class="chessBoard_control">
<div class="control_left">
<span class="iconfont icon-a-Chevron-Left2" @click="clearAllChess"></span>
<span class="iconfont icon-Chevron-Left"></span>
<span class="iconfont icon-caret-left" @click="clearlastChess"></span>
<span class="iconfont icon-caret-right"></span>
<span class="iconfont icon-Chevron-Right"></span>
<span class="iconfont icon-a-Chevron-Right2"></span>
<input type="text" />
<span class="go">go</span>
</div>
<div class="stepnumber" @click="openchessnumber">显示步数</div>
</div>
</div>
<div class="otherSlot">
<slot name="menu"></slot>
</div>
</div>
<!-- <div class="chessBoardPage_foot"></div> -->
<audio :src="sound" controls style="display: none"></audio>
</div>
</template>
<script>
import { onMounted, onUnmounted, onUpdated, reactive, ref, watch, watchEffect } from '@vue/runtime-core';
import {copyObj} from "../hooks/myconfig.js";
import "../hooks/myconfig.js";
import sound from "../assets/sound/落子.mp3";
import "../assets/font_HEMA-1/iconfont.css"
import "../assets/font3/iconfont.css"
import bus from "../hooks/Eventbus.js"
export default {
// props:['play'],
setup() {
// 数据
const numberarray = [
{ id: 1 },
{ id: 2 },
{ id: 3 },
{ id: 4 },
{ id: 5 },
{ id: 6 },
{ id: 7 },
{ id: 8 },
{ id: 9 },
{ id: 10 },
{ id: 11 },
{ id: 12 },
{ id: 13 },
{ id: 14 },
{ id: 15 },
{ id: 16 },
{ id: 17 },
{ id: 18 },
{ id: 19 },
];
let step = ref(0);
// chessSequence记录落子的情况
let chessSequence = [];
let allBlack = [];
let allWhite = [];
let theSelected2 = [];
let theSelected = [];
let openstep = 0;
let flag = false;
// 创建二维数组
let chesslist = new Array(19);
let b = new Array(19);
for (let i = 0; i < 19; i++) {
chesslist[i] = new Array(19);
b[i] = new Array(19);
for (let j = 0; j < 19; j++) {
chesslist[i][j] = {
// 颜色对应表: 0 => 未落子 | 1 => 黑子 | 2 => 白子 | 3 => 为棋盘边缘(无气)
color: 0,
topcolor: 0,
bottoncolor: 0,
leftcolor: 0,
rightcolor: 0,
};
}
}
// 生命周期钩子
// 当路由为 '/playchess' 时无需任何条件就可以下棋
if (window.location.pathname === '/playchess') {
flag = true
}
// 接受来自其他组件的传值,用来开启棋盘上落子的功能
bus.on('play',val =>{
console.log(val);
flag = val[0]
step.value = val[1]
})
// 方法
function chessdown(e) {
console.log(flag);
if (e.target.classList[1] === undefined && flag) {
// 落子声音播放
document.querySelector('audio').play()
document.querySelector('audio').volume = 0.2
// 棋子变色
step.value++;
if (step.value % 2 !== 0) {
e.target.classList.add("black_chessman");
} else {
e.target.classList.add("white_chessman");
}
// 将落子的位置与颜色push在chessSequence数组中
chessSequence.push({
position: e.target.classList[0],
chesscolor: e.target.classList[1].slice(0, 5),
chessnumber: step.value,
});
}
}
//#region
// 记录更新每处落子点的颜色
function updateChessColor() {
const allChess = document.querySelector(".chessarea").children;
for (let i = 0; i < allChess.length; i++) {
if (allChess[i].classList[1] === undefined) {
let x = parseInt(i / 19);
let y = i % 19;
// console.log(x,y);
chesslist[x][y].color = 0;
chesslist[x][y].index = i;
} else if (allChess[i].classList[1] === "black_chessman") {
let x = parseInt(i / 19);
let y = i % 19;
// console.warn(x,y);
chesslist[x][y].color = 1;
chesslist[x][y].index = i;
} else if (allChess[i].classList[1] === "white_chessman") {
let x = parseInt(i / 19);
let y = i % 19;
// console.error(x,y);
chesslist[x][y].color = 2;
chesslist[x][y].index = i;
}
}
}
//#endregion
//#region
// 记录更新每处落子点上下左右的颜色
function updateAroundColor() {
for (let i = 0; i < 19; i++) {
for (let j = 0; j < 19; j++) {
if (i > 0 && i < 18 && j > 0 && j < 18) {
chesslist[i][j].topcolor = chesslist[i-1][j].color
chesslist[i][j].bottoncolor = chesslist[i+1][j].color
chesslist[i][j].leftcolor = chesslist[i][j-1].color
chesslist[i][j].rightcolor = chesslist[i][j+1].color
}
else if(i === 0 && j === 0){
chesslist[i][j].topcolor = 3
chesslist[i][j].bottoncolor = chesslist[i+1][j].color
chesslist[i][j].leftcolor = 3
chesslist[i][j].rightcolor = chesslist[i][j+1].color
}
else if (i === 0 && j === 18) {
chesslist[i][j].topcolor = 3
chesslist[i][j].bottoncolor = chesslist[i+1][j].color
chesslist[i][j].leftcolor = chesslist[i][j-1].color
chesslist[i][j].rightcolor = 3
}
else if (i === 18 && j === 0) {
chesslist[i][j].topcolor = chesslist[i-1][j].color
chesslist[i][j].bottoncolor = 3
chesslist[i][j].leftcolor = 3
chesslist[i][j].rightcolor = chesslist[i][j+1].color
}
else if (i === 18 && j === 18) {
chesslist[i][j].topcolor = chesslist[i-1][j].color
chesslist[i][j].bottoncolor = 3
chesslist[i][j].leftcolor = chesslist[i][j-1].color
chesslist[i][j].rightcolor = 3
}
else if (i === 0 && j > 0 && j < 18) {
chesslist[i][j].topcolor = 3
chesslist[i][j].bottoncolor = chesslist[i+1][j].color
chesslist[i][j].leftcolor = chesslist[i][j-1].color
chesslist[i][j].rightcolor = chesslist[i][j+1].color
}
else if (i === 18 && j > 0 && j < 18) {
chesslist[i][j].topcolor = chesslist[i-1][j].color
chesslist[i][j].bottoncolor = 3
chesslist[i][j].leftcolor = chesslist[i][j-1].color
chesslist[i][j].rightcolor = chesslist[i][j+1].color
}
else if (j === 0 && i > 0 && i < 18) {
chesslist[i][j].topcolor = chesslist[i-1][j].color
chesslist[i][j].bottoncolor = chesslist[i+1][j].color
chesslist[i][j].leftcolor = 3
chesslist[i][j].rightcolor = chesslist[i][j+1].color
}
else if (j === 18 && i > 0 && i < 18) {
chesslist[i][j].topcolor = chesslist[i-1][j].color
chesslist[i][j].bottoncolor = chesslist[i+1][j].color
chesslist[i][j].leftcolor = chesslist[i][j-1].color
chesslist[i][j].rightcolor = 3
}
}
}
console.warn(chesslist);
console.log(chessSequence);
}
//#endregion
//#region
function isAliveBlack() {
let theQi = 0;
// allBlack 为从二维数组中提取出的一维数组,里面储存了棋盘上的所有黑子
allBlack = chesslist.twoDArrFilter((item)=>{
return item.color === 1
})
// theFirstBlack 中储存了 allBlack数组中的第一个棋子的数据,条件为:theSelected数组中不能有该子的记录
let theFirstBlack = allBlack.find((item1)=>{
if (theSelected.length !== 0 ) {
return theSelected.every((item2)=>{
return item1.index !== item2.index
})
}
else if (theSelected.length === 0) {
return true
}
})
// 当前遍历的棋子的数据(theFirstBlack),记录进 theSelected 数组
if (theFirstBlack !== undefined) {
theSelected.push(theFirstBlack);
}
// 判断当前遍历的子的气
if(theFirstBlack !== undefined)
{
if (theFirstBlack.topcolor === 0) {
theQi++
}
if (theFirstBlack.bottoncolor === 0) {
theQi++
}
if (theFirstBlack.leftcolor === 0) {
theQi++
}
if (theFirstBlack.rightcolor === 0) {
theQi++
}
for (let i = 0; i < allBlack.length; i++) {
if (allBlack[i].index === theFirstBlack.index) {
allBlack[i].Qi = theQi
}
}
theFirstBlack.Qi = theQi
theQi = 0
}
console.log('allBlack',allBlack);
console.log('theFirstBlack',theFirstBlack);
console.log('theSeleted',theSelected);
console.log(!allBlack.every((item1)=>{
return theSelected.some((item2)=>{
return item1.index === item2.index
})
}));
// 当 allBlack数组中所有子被遍历完后,停止递归
if
(
!(allBlack.every((item1)=>{
return theSelected.some((item2)=>{
return item1.index === item2.index
})
}))
)
{
isAliveBlack()
}
}
//#endregion
//#region
function isAliveWhite() {
let theQi = 0;
// allWhite 为从二维数组中提取出的一维数组,里面储存了棋盘上的所有黑子
allWhite = chesslist.twoDArrFilter((item)=>{
return item.color === 2
})
// theFirstWhite 中储存了 allBlack数组中的第一个棋子的数据,条件为:theSelected2数组中不能有该子的记录
let theFirstWhite = allWhite.find((item1)=>{
if (theSelected2.length !== 0 ) {
return theSelected2.every((item2)=>{
return item1.index !== item2.index
})
}
else if (theSelected2.length === 0) {
return true
}
})
// 当前遍历的棋子的数据(theFirstBlack),记录进 theSelected2 数组
if (theFirstWhite !== undefined) {
theSelected2.push(theFirstWhite);
}
// 判断当前遍历的子的气
if(theFirstWhite !== undefined)
{
if (theFirstWhite.topcolor === 0) {
theQi++
}
if (theFirstWhite.bottoncolor === 0) {
theQi++
}
if (theFirstWhite.leftcolor === 0) {
theQi++
}
if (theFirstWhite.rightcolor === 0) {
theQi++
}
for (let i = 0; i < allWhite.length; i++) {
if (allWhite[i].index === theFirstWhite.index) {
allWhite[i].Qi = theQi
}
}
theFirstWhite.Qi = theQi
theQi = 0
}
console.log('allWhite',allWhite);
console.log('theFirstWhite',theFirstWhite);
console.log('theSeleted',theSelected2);
console.log(!allWhite.every((item1)=>{
return theSelected2.some((item2)=>{
return item1.index === item2.index
})
}));
// 当 allBlack数组中所有子被遍历完后,停止递归
if
(
!(allWhite.every((item1)=>{
return theSelected2.some((item2)=>{
return item1.index === item2.index
})
}))
)
{
isAliveWhite()
}
}
//#endregion
//#region
// 清除黑棋无气的子
function clearDeadthBlack() {
const allChess = document.querySelector(".chessarea").children;
let allQi = 0;
let allDeath = [];
for (let i = 0; i < 5; i++) {
// 重复以下操作5次可彻底防止大龙中有未加入 allDeath 数组的棋子
for (let i = 0; i < allBlack.length; i++) {
// 清除无气孤子
if (allBlack[i].Qi === 0) {
if (allBlack[i].topcolor !== 1 && allBlack[i].bottoncolor !== 1 && allBlack[i].leftcolor !== 1 && allBlack[i].rightcolor !== 1) {
if (step.value % 2 === 0 && step.value !== 0)
{
let k = allBlack[i].index
allChess[k].classList.remove('black_chessman')
}
// 下面是落子不入气禁止行棋的逻辑
else if(step.value % 2 !== 0){
let k = allBlack[i].index
allChess[k].classList.remove('black_chessman')
chessSequence.pop()
step.value = step.value - 1
alert('此处不入气,禁止落子')
}
}
}
// 清除无气大龙
if (allBlack[i].topcolor === 1 || allBlack[i].bottoncolor === 1 || allBlack[i].leftcolor === 1 || allBlack[i].rightcolor === 1) {
if (allDeath.length === 0) {
allDeath.push(allBlack[i])
}
for (let j = 0; j < allDeath.length; j++) {
if (allDeath.every(item => item.index !== allBlack[i].index)){
if ((allBlack[i].index === allDeath[j].index - 19 || allBlack[i].index === allDeath[j].index + 19 || allBlack[i].index === allDeath[j].index - 1 || allBlack[i].index === allDeath[j].index + 1)) {
allDeath.push(allBlack[i])
}
}
}
console.warn('allDeath1',allDeath);
}
}
// 反向遍历筛选一次防止大龙中有未加入 allDeath 数组的棋子
for (let i = allBlack.length-1; i >= 0; i--) {
if (allBlack[i].topcolor === 1 || allBlack[i].bottoncolor === 1 || allBlack[i].leftcolor === 1 || allBlack[i].rightcolor === 1) {
for (let j = allDeath.length-1; j >= 0 ; j--) {
if (allDeath.every(item => item.index !== allBlack[i].index)){
if ((allBlack[i].index === allDeath[j].index - 19 || allBlack[i].index === allDeath[j].index + 19 || allBlack[i].index === allDeath[j].index - 1 || allBlack[i].index === allDeath[j].index + 1)) {
allDeath.push(allBlack[i])
}
}
}
}
}
}
// 统计黑棋大龙总共的气
for (let i = 0; i < allDeath.length; i++) {
allQi = allDeath[i].Qi + allQi
}
console.warn('allDeath2',allDeath);
console.warn('黑大龙的气2:',allQi);
if ( allQi === 0 ) {
// 下面是落子不入气禁止行棋的逻辑
if(step.value % 2 !== 0 && allDeath.length !== 0)
{
const p = chessSequence[chessSequence.length-1].position
for (let i = 0; i < allChess.length; i++) {
if (allChess[i].classList[0] === p) {
allChess[i].classList.remove('black_chessman')
step.value = step.value - 1
chessSequence.pop()
alert('此处不入气,禁止落子')
return // return 是为了跳出函数停止执行不然就会因为step被减1而执行下面的判断中的逻辑
}
}
}
if (step.value % 2 === 0 && step.value !== 0) {
for (let j = 0; j < allDeath.length; j++)
{
let k = allDeath[j].index
allChess[k].classList.remove('black_chessman')
}
}
}
else if(allQi !== 0){
let del = allBlack.filter(item1 => {
return allDeath.some(item2 => {
return item1.index === item2.index
})
})
for (let i = 0; i < allBlack.length; i++) {
for (let j = 0; j < del.length; j++) {
if (allBlack[i].index === del[j].index) {
allBlack.splice(i,1)
}
}
}
console.log(allBlack);
clearDeadthBlack()
}
}
//#endregion
//#region
// 清除白棋无气的子
function clearDeadthWhite() {
const allChess = document.querySelector(".chessarea").children;
let allQi = 0;
let allDeath = [];
for (let i = 0; i < 5; i++) {// 重复以下操作5次可彻底防止大龙中有未加入 allDeath 数组的棋子
for (let i = 0; i < allWhite.length; i++) {
// 清除无气孤子
if (allWhite[i].Qi === 0) {
if (allWhite[i].topcolor !== 2 && allWhite[i].bottoncolor !== 2 && allWhite[i].leftcolor !== 2 && allWhite[i].rightcolor !== 2) {
if(step.value % 2 !== 0)
{
let k = allWhite[i].index
allChess[k].classList.remove('white_chessman')
}
// 下面是落子不入气禁止行棋的逻辑
else if(step.value % 2 === 0 && step.value !== 0){
let k = allBlack[i].index
allChess[k].classList.remove('white_chessman')
chessSequence.pop()
step.value = step.value - 1
alert('此处不入气,禁止落子')
}
}
}
// 清除无气大龙
if (allWhite[i].topcolor === 2 || allWhite[i].bottoncolor === 2 || allWhite[i].leftcolor === 2 || allWhite[i].rightcolor === 2) {
if (allDeath.length === 0) {
allDeath.push(allWhite[i])
// allQi = allQi + allWhite[i].Qi
}
for (let j = 0; j < allDeath.length; j++) {
if (allDeath.every(item => item.index !== allWhite[i].index)){
if ((allWhite[i].index === allDeath[j].index - 19 || allWhite[i].index === allDeath[j].index + 19 || allWhite[i].index === allDeath[j].index - 1 || allWhite[i].index === allDeath[j].index + 1)) {
allDeath.push(allWhite[i])
// allQi = allQi + allWhite[i].Qi
}
}
}
console.warn('allDeath1',allDeath);
}
}
// 反向遍历筛选一次防止大龙中有未加入 allDeath 数组的棋子
for (let i = allWhite.length-1; i >= 0; i--) {
if (allWhite[i].topcolor === 2 || allWhite[i].bottoncolor === 2 || allWhite[i].leftcolor === 2 || allWhite[i].rightcolor === 2) {
for (let j = allDeath.length-1; j >= 0 ; j--) {
if (allDeath.every(item => item.index !== allWhite[i].index)){
if ((allWhite[i].index === allDeath[j].index - 19 || allWhite[i].index === allDeath[j].index + 19 || allWhite[i].index === allDeath[j].index - 1 || allWhite[i].index === allDeath[j].index + 1)) {
allDeath.push(allWhite[i])
}
}
}
}
}
}
// 统计白棋大龙总共的气
for (let i = 0; i < allDeath.length; i++) {
allQi = allDeath[i].Qi + allQi
}
console.warn('allDeath2',allDeath);
console.warn('白大龙的气2:',allQi);
if ( allQi === 0 ) {
// 下面是落子不入气禁止行棋的逻辑
if (step.value % 2 === 0 && step.value !== 0 && allDeath.length !== 0)
{
const p = chessSequence[chessSequence.length-1].position
for (let i = 0; i < allChess.length; i++) {
if (allChess[i].classList[0] === p) {
allChess[i].classList.remove('white_chessman')
step.value = step.value - 1
chessSequence.pop()
alert('此处不入气,禁止落子')
return // return 是为了跳出函数停止执行不然就会因为step被减1而执行下面的判断中的逻辑
}
}
}
if(step.value % 2 !== 0)
{
for (let j = 0; j < allDeath.length; j++)
{
let k = allDeath[j].index
allChess[k].classList.remove('white_chessman')
}
}
}
else if(allQi !== 0){
let del = allWhite.filter(item1 => {
return allDeath.some(item2 => {
return item1.index === item2.index
})
})
for (let i = 0; i < allWhite.length; i++) {
for (let j = 0; j < del.length; j++) {
if (allWhite[i].index === del[j].index) {
allWhite.splice(i,1)
}
}
}
console.log(allWhite);
clearDeadthWhite()
}
}
//#endregion
function openchessnumber(){
openstep ++
chessnumber()
console.log('openstep',openstep);
}
// 棋子显示步数的逻辑
function chessnumber() {
if(chessSequence.length > 0 && openstep !== 0){
switch (openstep % 3) {
case 0:
// 清除所有棋子上的步数标记
for (let i = 0; i < chessSequence.length; i++) {
const afterChess = chessSequence[i];
document.querySelector("." + afterChess.position).innerHTML =
"";
}
break;
case 1:
// 显示当前棋子步数的逻辑
const lastChess = chessSequence[chessSequence.length - 1];
document.querySelector("." + lastChess.position).innerHTML = lastChess.chessnumber;
if (step.value > 1) {
const deleteLastChess = chessSequence[chessSequence.length - 2];
document.querySelector("." + deleteLastChess.position).innerHTML = "";
}
break;
case 2:
// 显示所有棋子步数的逻辑
const allChess = document.querySelector(".chessarea").children;
for (let i = 0; i < chessSequence.length; i++) {
for (let j = 0; j < allChess.length; j++) {
if (chessSequence[i].position === allChess[j].classList[0]) {
let x = parseInt(j / 19);
let y = j % 19;
allChess[j].innerHTML = chessSequence[i].chessnumber
// 被提子时,清除被提棋子上的步数
updateChessColor()
if (chesslist[x][y].color === 0) {
allChess[j].innerHTML = ''
}
}
}
}
break;
}
}
}
// 回退到未落子的状态(清光chessSequence数组和chesslist数组的落子记录)
function clearAllChess() {
if (step.value > 0) {
const allChess = document.querySelector(".chessarea").children;
for (let i = 0; i < allChess.length; i++) {
allChess[i].classList.remove('white_chessman')
allChess[i].classList.remove('black_chessman')
}
// 清除所有棋子上的步数标记
for (let i = 0; i < chessSequence.length; i++) {
const afterChess = chessSequence[i];
document.querySelector("." + afterChess.position).innerHTML ="";
}
chessSequence = []
step.value = 0
}
}
// 回退到上一步落子的状态
function clearlastChess() {
if (step.value > 0) {
const lastChess = chessSequence[chessSequence.length - 1];
document.querySelector("." + lastChess.position).innerHTML = '';
document.querySelector("." + lastChess.position).classList.remove('white_chessman');
document.querySelector("." + lastChess.position).classList.remove('black_chessman');
chessSequence.pop()
step.value--
}
}
// 监视器
watch(step,()=>{
updateChessColor()
updateAroundColor()
if(step.value % 2 !== 0)
{
theSelected2 = []
isAliveWhite()
clearDeadthWhite()
updateChessColor()
updateAroundColor()
isAliveBlack()
isAliveWhite()
theSelected = []
isAliveBlack()
clearDeadthBlack()
}
else if(step.value % 2 === 0 && step.value !== 0){
theSelected = []
isAliveBlack()
clearDeadthBlack()
updateChessColor()
updateAroundColor()
isAliveBlack()
isAliveWhite()
theSelected2 = []
isAliveWhite()
clearDeadthWhite()
}
chessnumber()
})
// 返回对象
return {
numberarray,
chessdown,
step,
// chessSequence,
sound,
openchessnumber,
clearAllChess,
clearlastChess,
};
},
};
</script>
<style lang="less" scoped>
.chessBoardPage_main {
margin-top: 8px;
background-color: #3d3d3de5;
width: 90%;
box-sizing: border-box;
margin: auto;
// .chessBoardPage_head {
// width: 100%;
// height: 40px;
// background-color: #3d3d3d;
// }
.chessBoardPage_container {
width: 100%;
display: flex;
.theSlot {
width: 360px;
}
.otherSlot {
width: 410px;
}
.chessBoardPage_container_chessboard {
width: 933px;
height: 973px;
background-image: url(../assets/image/围棋棋盘.jpg);
background-repeat: no-repeat;
// margin: auto;
margin-top: 8px;
box-sizing: border-box;
overflow: hidden;
.chessBoard_control {
width: 800px;
height: 30px;
margin: auto;
margin-top: 10px;
display: flex;
.control_left {
width: 320px;
height: 30px;
border-radius: 15px;
background-color: #1b1b1b;
display: flex;
align-items: center;
span {
text-align: center;
line-height: 30px;
display: inline-block;
color: grey;
width: 34px;
height: 30px;
font-size: 22px;
}
.go {
font-size: 18px;
line-height: 27px;
margin-left: 10px;
cursor: pointer;
}
span:hover {
color: wheat;
}
input {
margin-left: 30px;
display: inline-block;
background-color: grey;
width: 20px;
height: 20px;
color: white;
cursor: pointer;
outline: none; /* 取消input表单的轮廓线 */
}
}
.stepnumber {
background-color: #1b1b1b;
border-radius: 15px;
text-align: center;
line-height: 30px;
display: inline-block;
color: grey;
width: 100px;
height: 30px;
font-size: 17px;
margin-left: 40px;
cursor: pointer;
}
.stepnumber:hover {
background-color: #1b1b1b9c;
}
}
.chessarea {
height: 933px;
width: 933px;
// background-color: rgba(255, 255, 255, 0.356);
margin: auto;
padding-left: 1px;
transform: translateY(1px);
overflow: hidden;
box-sizing: border-box;
display: flex;
align-content: flex-start;
// flex-wrap: wrap 之后元素上下间距过大怎么解决?
// 问题:flex-wrap: wrap 之后元素上下间距好大,实际上没有设置间距
// 原因:当元素设置了flex-wrap:wrap之后会有一个默认属性 align-content: stretch。元素被拉伸以适应容器。
// 解决方法:添加:align-content:flex-start; 使元素位于容器的开头。
flex-wrap: wrap;
.black_chessman {
background-image: url(../assets/image/blackchess.png);
color: white;
}
.white_chessman {
background-image: url(../assets/image/whitechess.png);
color: black;
}
span {
display: block;
width: 46px;
height: 46px;
border-radius: 23px;
// background-color: rgb(0, 0, 0);
cursor: pointer;
margin: 1.5px 1.5px;
text-align: center;
line-height: 46px;
overflow: hidden;
font-size: 18px;
font-weight: 700;
}
}
}
}
}
</style>
下面是功能演示:
csdn2
这个是函数封装文件myconfig.js
// for in 递归深拷贝
export function copyObj(obj) {
if (Array.isArray(obj)) {
var newObj = [];
}
else {
var newObj = {};
}
for (var key in obj) {
if (typeof obj[key] == 'object') {
newObj[key] = copyObj(obj[key]);
}
else {
newObj[key] = obj[key]
}
}
return newObj;
}
// 二维数组版 的 find方法
Array.prototype.twoDArrFind = function (fn) {
if (Object.prototype.toString.call(fn) !== '[object Function]') {
throw 'the arg should be a function'
}
let arr = this;
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr.length; j++) {
let res = fn(arr[i][j],i,j)
if (res) {
return arr[i][j]
}
return false
}
}
}
// 二维数组版 的 filter方法
Array.prototype.twoDArrFilter = function (fn) {
if (Object.prototype.toString.call(fn) !== '[object Function]') {
throw 'the arg should be a function'
}
let arr = this;
let arr1 = []
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr.length; j++) {
let res = fn(arr[i][j],i,j)
if (res) {
arr1.push(arr[i][j])
}
}
}
return arr1
}
由于写到一半突然就没兴趣不想写了,学C++去了,所以功能也只是初步写到了这儿,比如:
1、页面样式都没有写得很漂亮
2、打劫的逻辑还没写
3、循环劫(如三劫循环)、双头蛇两假烟活棋(盘龙眼)等特殊情况的处理逻辑没有实现
4、形式判断的功能没有实现