/* eslint-disable indent */
<template>
<div class="container"
class="item-rigts">
<div class="canvas-bg" id="bgcanvas">
<canvas id="canvas1" ref="myCanvas">不支持Canvascanvas>
div>
div>
template>
<script>
import {getWalkingEnrollItemBank, updateEnrollFractionById} from '../../api/index'
let canvas
let ctx
let subX
let subY
let descClick
export default {
name: 'gochess',
data () {
return {
totalSecond: 0,
countDownDay: 0,
countDownHour: 0,
countDownMinute: 0,
countDownSecond: 0,
name: '',
levelexam: '',
testId: '',
exchangCode: '',
gradId: '',
questionNum: 0,
enrollItemBanks: [],
Chess: [],
answerChess: [],
blackChess: [],
total: 0,
testIndex: 0,
clickNumber: 0,
canGoChess: true,
banMa: true,
banXiang: true,
existe: true,
faceState: false,
rX: 0,
rY: 0,
hX: 0,
hY: 0,
chessGoNumber: 0,
quesionNumber: 0,
eatChess: false,
isError: [],
redanswerlength: 0,
success: 0,
isTrue: true
}
},
created () {
this.name = this.$route.params.name
this.levelexam = this.$route.params.levelexam
this.testId = this.$route.params.id
this.exchangCode = this.$route.params.exchangCode
this.gradId = this.$route.params.testId
console.log(this.$route, this.name, this.levelexam, this.testId, this.exchangCode)
this.totalSecond = 1800
this.questionNum = 20
var interval = setInterval(function () {
var second = this.totalSecond
var day = Math.floor(second / 3600 / 24)
var dayStr = day.toString()
if (dayStr.length === 1) dayStr = '0' + dayStr
var hr = Math.floor((second - day * 3600 * 24) / 3600)
var hrStr = hr.toString()
if (hrStr.length === 1) hrStr = '0' + hrStr
var min = Math.floor((second - day * 3600 * 24 - hr * 3600) / 60)
var minStr = min.toString()
if (minStr.length === 1) minStr = '0' + minStr
var sec = second - day * 3600 * 24 - hr * 3600 - min * 60
var secStr = sec.toString()
if (secStr.length === 1) secStr = '0' + secStr
this.countDownDay = dayStr
this.countDownHour = hrStr
this.countDownMinute = minStr
this.countDownSecond = secStr
this.totalSecond--
console.log(this.totalSecond)
if (this.totalSecond === 300) {
this.$message('距离考试结束还剩5分钟')
}
if (this.totalSecond < 0) {
clearInterval(interval)
console.log('时间到', this.success)
this.updateEnrollFractionById(this.success)
}
}.bind(this), 1000)
},
mounted () {
history.pushState(null, null, document.URL)
window.addEventListener('popstate', function () {
history.pushState(null, null, document.URL)
})
window.addEventListener('beforeunload', this.unload)
this.getTest(this.testId, this.exchangCode)
this.initCanvas()
},
destroyed () {
window.removeEventListener('beforeunload', this.unload)
},
methods: {
unload (e) {
e = e || window.event
if (e) {
console.log(e)
e.returnValue = '重新加载将导致准考证号失效,是否重新加载'
}
return '重新加载将导致准考证号失效,是否重新加载'
},
getTest (id, exchangCode) {
getWalkingEnrollItemBank({
enrollGradeId: id,
exchangCode: exchangCode
}).then(res => {
console.log(res)
if (res.success) {
this.$message({
message: '已刷新,准考证号失效将退出本次考试',
center: true,
type: 'warning'
})
setTimeout(() => {
this.$router.push('/gradingTest')
}, 3000)
}
this.enrollItemBanks = res.walkingEnrollItemBanks
console.log(this.enrollItemBanks)
this.total = res.walkingEnrollItemBanks.length
this.drewChess(this.enrollItemBanks)
}).catch(() => {
})
},
updateEnrollFractionById (fraction) {
updateEnrollFractionById({
id: this.gradId,
fraction: fraction
}).then(res => {
console.log(res)
this.$router.push({
name: 'gradingResults',
query: {
id: this.gradId,
fractions: fraction,
levelexam: this.levelexam
}
})
}).catch((err) => {
console.log(err)
})
},
submit () {
this.$confirm('确认交卷', {
confirmButtonText: '确定',
cancelButtonText: '取消',
center: true
}).then(() => {
this.updateEnrollFractionById(this.success)
}).catch(() => {
})
},
initCanvas () {
let that = this
canvas = document.getElementById('canvas1')
ctx = canvas.getContext('2d')
canvas.width = 480
canvas.height = 530
ctx.lineWidth = 2
ctx.strokeStyle = '#000'
canvas.onclick = function (e) {
let sx = e.clientX - canvas.getBoundingClientRect().left
let sy = e.clientY - canvas.getBoundingClientRect().top
that.getChess(ctx, sx, sy)
}
that.initChess()
},
initChess () {
ctx.lineWidth = 2
ctx.strokeStyle = '#000'
let that = this
that.row()
that.cols()
that.center(90, 140)
that.center(390, 140)
that.center(40, 190)
that.center(140, 190)
that.center(240, 190)
that.center(340, 190)
that.center(440, 190)
that.center(40, 340)
that.center(140, 340)
that.center(240, 340)
that.center(340, 340)
that.center(440, 340)
that.center(90, 390)
that.center(390, 390)
},
LineDrawing (mx, my, lx, ly) {
ctx.beginPath()
ctx.moveTo(mx, my)
ctx.lineTo(lx, ly)
ctx.stroke()
},
row () {
for (var i = 40; i <= 490; i += 50) {
ctx.beginPath()
ctx.moveTo(40, i)
ctx.lineTo(440, i)
ctx.stroke()
}
},
cols () {
for (var i = 40; i <= 490; i += 50) {
ctx.beginPath()
ctx.moveTo(i, 40)
ctx.lineTo(i, 490)
ctx.stroke()
}
ctx.clearRect(41, 241, 398, 48)
ctx.font = '28px Georgia'
ctx.fillText('楚', 95, 275)
ctx.fillText('河', 145, 275)
ctx.fillText('汉', 315, 275)
ctx.fillText('界', 365, 275)
this.LineDrawing(190, 40, 290, 140)
this.LineDrawing(190, 390, 290, 490)
this.LineDrawing(290, 40, 190, 140)
this.LineDrawing(290, 390, 190, 490)
},
center (x, y) {
ctx.lineWidth = 3
if (x === 40 && y === 190) {
this.LineDrawing(x + 5, y - 15, x + 5, y - 5)
this.LineDrawing(x + 5, y - 5, x + 15, y - 5)
this.LineDrawing(x + 5, y + 15, x + 5, y + 5)
this.LineDrawing(x + 5, y + 5, x + 15, y + 5)
} else if (x === 440 && y === 190) {
this.LineDrawing(x - 5, y - 15, x - 5, y - 5)
this.LineDrawing(x - 5, y - 5, x - 15, y - 5)
this.LineDrawing(x - 5, y + 15, x - 5, y + 5)
this.LineDrawing(x - 5, y + 5, x - 15, y + 5)
} else if (x === 40 && y === 340) {
this.LineDrawing(x + 5, y - 15, x + 5, y - 5)
this.LineDrawing(x + 5, y - 5, x + 15, y - 5)
this.LineDrawing(x + 5, y + 15, x + 5, y + 5)
this.LineDrawing(x + 5, y + 5, x + 15, y + 5)
} else if (x === 440 && y === 340) {
this.LineDrawing(x - 5, y - 15, x - 5, y - 5)
this.LineDrawing(x - 5, y - 5, x - 15, y - 5)
this.LineDrawing(x - 5, y + 15, x - 5, y + 5)
this.LineDrawing(x - 5, y + 5, x - 15, y + 5)
} else {
this.LineDrawing(x - 5, y - 15, x - 5, y - 5)
this.LineDrawing(x - 5, y - 5, x - 15, y - 5)
this.LineDrawing(x + 5, y - 15, x + 5, y - 5)
this.LineDrawing(x + 5, y - 5, x + 15, y - 5)
this.LineDrawing(x - 5, y + 15, x - 5, y + 5)
this.LineDrawing(x - 5, y + 5, x - 15, y + 5)
this.LineDrawing(x + 5, y + 15, x + 5, y + 5)
this.LineDrawing(x + 5, y + 5, x + 15, y + 5)
}
},
draw_check (context, x, y) {
let screenx = x + 20
let screeny = y + 20
ctx.lineWidth = 3
ctx.strokeStyle = '#97092a'
context.beginPath()
context.moveTo(screenx - 23, screeny - 16)
context.lineTo(screenx - 23, screeny - 23)
context.lineTo(screenx - 16, screeny - 23)
context.moveTo(screenx + 16, screeny - 23)
context.lineTo(screenx + 23, screeny - 23)
context.lineTo(screenx + 23, screeny - 16)
context.moveTo(screenx - 23, screeny + 16)
context.lineTo(screenx - 23, screeny + 23)
context.lineTo(screenx - 16, screeny + 23)
context.moveTo(screenx + 23, screeny + 16)
context.lineTo(screenx + 23, screeny + 23)
context.lineTo(screenx + 16, screeny + 23)
context.stroke()
},
draw_blcheck (context, x, y) {
let screenx = x + 20
let screeny = y + 20
ctx.lineWidth = 3
ctx.strokeStyle = '#973c51'
context.beginPath()
context.moveTo(screenx - 23, screeny - 16)
context.lineTo(screenx - 23, screeny - 23)
context.lineTo(screenx - 16, screeny - 23)
context.moveTo(screenx + 16, screeny - 23)
context.lineTo(screenx + 23, screeny - 23)
context.lineTo(screenx + 23, screeny - 16)
context.moveTo(screenx - 23, screeny + 16)
context.lineTo(screenx - 23, screeny + 23)
context.lineTo(screenx - 16, screeny + 23)
context.moveTo(screenx + 23, screeny + 16)
context.lineTo(screenx + 23, screeny + 23)
context.lineTo(screenx + 16, screeny + 23)
context.stroke()
},
drewChess (enrollItemBanks) {
this.Chess = this.enrollItemBanks[this.testIndex].walkingEnrollItemBanks
this.answerChess = this.enrollItemBanks[this.testIndex].redAnswer
this.redanswerlength = this.enrollItemBanks[this.testIndex].redAnswer.length
this.blackChess = this.enrollItemBanks[this.testIndex].blackAnswer
console.log('棋子展示', this.Chess)
console.log('红棋答案展示', this.answerChess)
console.log('黑棋答案展示', this.blackChess)
for (let i in this.Chess) {
let img = new Image()
img.src = this.Chess[i].imageUrl
img.id = this.Chess[i].ids
let x = this.Chess[i].positionX
let y = this.Chess[i].positionY
img.onload = () => {
ctx.drawImage(img, x, y, 40, 40)
}
}
},
clearBox (context, descClick) {
let oldx = descClick[0]
let oldy = descClick[1]
let screenx = oldx + 20
let screeny = oldy + 20
ctx.lineWidth = 4
ctx.strokeStyle = '#f9c78b'
context.beginPath()
context.moveTo(screenx - 23, screeny - 16)
context.lineTo(screenx - 23, screeny - 23)
context.lineTo(screenx - 16, screeny - 23)
context.moveTo(screenx + 16, screeny - 23)
context.lineTo(screenx + 23, screeny - 23)
context.lineTo(screenx + 23, screeny - 16)
context.moveTo(screenx - 23, screeny + 16)
context.lineTo(screenx - 23, screeny + 23)
context.lineTo(screenx - 16, screeny + 23)
context.moveTo(screenx + 23, screeny + 16)
context.lineTo(screenx + 23, screeny + 23)
context.lineTo(screenx + 16, screeny + 23)
context.stroke()
},
clearChess (context, cx, cy) {
context.clearRect(cx, cy, 40, 400)
},
repaint (context) {
context.clearRect(0, 0, 480, 530)
this.initChess()
},
isChessAlive (x, y) {
this.existe = false
for (let i in this.Chess) {
if (this.Chess[i].positionX === x && this.Chess[i].positionY === y) {
this.existe = true
}
}
return this.existe
},
isFaceToFace () {
for (let i in this.Chess) {
if (this.Chess[i].piece === 5 && this.Chess[i].redBlack === 1) {
this.rX = this.Chess[i].positionX
this.rY = this.Chess[i].positionY
}
if (this.Chess[i].piece === 5 && this.Chess[i].redBlack === 0) {
this.hX = this.Chess[i].positionX
this.hY = this.Chess[i].positionY
}
if (this.rX === this.hX) {
for (let i in this.Chess) {
if (this.Chess[i].positionX === this.rX && this.Chess[i].positionY > this.rY && this.rX && this.Chess[i].positionY < this.hY) {
this.faceState = false
}
if (this.Chess[i].positionX === this.rX && this.Chess[i].positionY < this.rY && this.rX && this.Chess[i].positionY > this.hY) {
this.faceState = true
}
}
}
}
return this.faceState
},
successOrFail (context, subX, subY) {
let redanswerchess = this.answerChess[this.chessGoNumber]
let blackanswerchess = this.blackChess[this.chessGoNumber]
for (let i in this.Chess) {
if (this.Chess[i].positionX === subX && this.Chess[i].positionY === subY) {
this.Chess.splice(i, 1)
}
if (this.Chess[i].positionX === descClick[0] && this.Chess[i].positionY === descClick[1] && this.Chess[i].ids === descClick[5]) {
this.Chess[i].positionX = subX
this.Chess[i].positionY = subY
this.repaint(context)
this.drewChess(this.Chess)
for (let index = 0; index < redanswerchess.length; index++) {
console.log(redanswerchess[index].ids, descClick[5], redanswerchess[index].positionX, subX, redanswerchess[index].positionY, subY)
if (redanswerchess[index].ids === descClick[5] && redanswerchess[index].positionX === subX && redanswerchess[index].positionY === subY) {
console.log(this.chessGoNumber, 'this.chessGoNumber', this.redanswerlength, 'this.redanswerlength')
if (this.chessGoNumber === this.redanswerlength - 1) {
if (this.total - 1 === this.testIndex) {
this.success++
this.$message({
message: '已完成答题',
center: true,
type: 'success'
})
setTimeout(() => {
this.updateEnrollFractionById(this.success)
}, 2000)
} else {
this.$message({
message: '进入下一题',
center: true,
type: 'success'
})
setTimeout(() => {
this.chessGoNumber = 0
this.testIndex++
this.success++
this.isTrue = true
this.repaint(context)
this.drewChess(this.Chess)
descClick = []
}, 2000)
}
}
for (let i in this.Chess) {
for (let index in blackanswerchess) {
if (blackanswerchess[index].positionX === this.Chess[i].positionX && blackanswerchess[index].positionY === this.Chess[i].positionY) {
console.log('黑棋走子的地方有旗子')
this.Chess.splice(i, 1)
}
console.log(blackanswerchess[index].ids, this.Chess[i].ids)
if (blackanswerchess[index].ids === this.Chess[i].ids) {
console.log(this.Chess[i].ids)
let oldX = this.Chess[i].positionX
let oldY = this.Chess[i].positionY
let blackX = blackanswerchess[index].positionX
let blackY = blackanswerchess[index].positionY
console.log('走对了', blackX, blackY)
this.Chess[i].positionX = blackX
this.Chess[i].positionY = blackY
this.chessGoNumber = this.chessGoNumber + 1
setTimeout(() => {
this.repaint(context)
this.drewChess(this.Chess)
this.draw_check(context, blackX, blackY)
this.draw_blcheck(context, oldX, oldY)
}, 800)
}
break
}
}
break
} else {
console.log(index, redanswerchess.length - 1)
if (index === redanswerchess.length - 1) {
this.isTrue = false
console.log(this.isTrue)
}
}
console.log(this.isTrue)
if (!this.isTrue) {
if (this.total - 1 === this.testIndex) {
this.$message({
message: '已完成答题',
center: true,
type: 'success'
})
setTimeout(() => {
this.updateEnrollFractionById(this.success)
}, 2000)
} else {
this.$message({
message: '进入下一题',
center: true,
type: 'warning'
})
setTimeout(() => {
this.isTrue = true
this.chessGoNumber = 0
this.testIndex++
this.repaint(context)
this.drewChess(this.Chess)
descClick = []
}, 2000)
}
}
}
}
}
},
getChess (context, x, y) {
x = x - 20
y = y - 20
console.log('x', x, 'y', y)
if (x < 0 || y < 0 || x > 460 || y > 510) { return false }
console.log('x % 100 > 10 && x % 100 < 100', x % 100 > 10 && x % 100 < 100, x > 420 ? subX = 400 : subX = Math.abs((Math.floor(x / 50) * 50)))
console.log('y % 100 > 10 || y % 100 < 100', y % 100 > 10 || y % 100 < 100, y > 470 ? subY = 450 : subY = Math.abs(50 * Math.floor(y / 50)))
if (x % 100 > 10 || x % 100 < 100) { x > 420 ? subX = 400 : subX = Math.abs((Math.floor(x / 50) * 50)) }
if (y % 100 > 10 || y % 100 < 100) { y > 470 ? subY = 450 : subY = Math.abs(50 * Math.floor(y / 50)) }
subX = subX + 20
subY = subY + 20
console.log(' subX', subX, 'subY', subY)
if (subX >= 0 && subY >= 0) {
let chess = this.Chess
this.clickNumber = this.clickNumber + 1
console.log(descClick, 'descClick', this.clickNumber, 'clickNumber')
if (this.clickNumber === 1) {
for (let i in chess) {
if (chess[i].positionX === subX && chess[i].positionY === subY) {
if (chess[i].redBlack === 1) {
if (this.chessGoNumber > 0) {
this.repaint(context)
this.drewChess(this.Chess)
}
this.draw_check(context, subX, subY)
descClick = [subX, subY, i, chess[i].redBlack, chess[i].piece, chess[i].ids]
console.log(descClick, 'descClick')
break
} else {
this.$message({
message: '请点击红方',
center: true,
type: 'warning'
})
this.clickNumber = 0
}
}
}
}
if (this.clickNumber === 2) {
if (this.isChessAlive(subX, subY)) {
for (let i in this.Chess) {
if (chess[i].positionX === subX && chess[i].positionY === subY) {
if (chess[i].redBlack === 1) {
this.repaint(context)
this.drewChess(this.Chess)
descClick = [subX, subY, i, chess[i].redBlack, chess[i].piece, chess[i].ids]
this.draw_check(context, subX, subY)
console.log('第二次点击', descClick)
this.clickNumber = 1
break
} else {
if (this.canGo(subX, subY, descClick)) {
this.clearBox(context, descClick)
this.successOrFail(context, subX, subY)
this.clickNumber = 0
} else {
console.log('走子规则不对')
this.clickNumber = 1
this.canGoChess = true
}
}
break
}
}
} else {
console.log('棋子不存在可以走')
if (this.canGo(subX, subY, descClick)) {
this.clearBox(context, descClick)
this.successOrFail(context, subX, subY)
this.clickNumber = 0
} else {
console.log('走子规则不对')
this.banXiang = true
this.banMa = true
this.clickNumber = 1
}
}
}
}
},
canGo (x, y, descClick) {
this.canGoChess = true
let newX = x
let newY = y
let oldX = descClick[0]
let oldY = descClick[1]
let piece = descClick[4]
let minX = oldX > newX ? newX : oldX
let maxX = oldX > newX ? oldX : newX
let minY = oldY > newY ? newY : oldY
let maxY = oldY > newY ? oldY : newY
switch (piece) {
case 1:// che 不在一条直线上不能走不能吃
if (newX !== oldX && newY !== oldY) {
this.canGoChess = false
this.existe = false
break
}
for (let i in this.Chess) {
if (this.Chess[i].positionX === newX && this.Chess[i].positionY > minY && this.Chess[i].positionY < maxY) {
this.canGoChess = false
}
if (this.Chess[i].positionY === newY && this.Chess[i].positionX > minX && this.Chess[i].positionX < maxX) {
this.canGoChess = false
}
}
break
case 2:// ma
this.canGoChess = false
this.banMa = true
for (let i in this.Chess) {
let banX = this.Chess[i].positionX
let banY = this.Chess[i].positionY
console.log('进入规则马', 'banX', banX, 'banY', banY, 'newX', newX, 'newY', newY)
if (oldY === banY && oldX + 50 === banX && newY + 50 === banY && newX - 50 === banX) {
this.$message({
message: '绊马腿1',
center: true,
type: 'warning'
})
this.banMa = false
}
if (oldY === banY && oldX - 50 === banX && newY - 50 === banY && newX + 50 === banX) {
this.$message({
message: '绊马腿2',
center: true,
type: 'warning'
})
this.banMa = false
}
if (oldY === banY && oldX - 50 === banX && newY + 50 === banY && newX + 50 === banX) {
this.$message({
message: '绊马腿3',
center: true,
type: 'warning'
})
this.banMa = false
}
if (oldY === banY && oldX + 50 === banX && newY - 50 === banY && newX - 50 === banX) {
this.$message({
message: '绊马腿4',
center: true,
type: 'warning'
})
this.banMa = false
}
if (oldX === banX && oldY - 50 === banX && newY + 50 === banY && newX + 50 === banX) {
this.$message({
message: '绊马腿5',
center: true,
type: 'warning'
})
this.banMa = false
}
if (oldX === banX && oldY + 50 === banX && newY - 50 === banY && newX + 50 === banX) {
this.$message({
message: '绊马腿6',
center: true,
type: 'warning'
})
this.banMa = false
}
if (oldX === banX && oldY + 50 === banX && newY - 50 === banY && newX - 50 === banX) {
this.$message({
message: '绊马腿7',
center: true,
type: 'warning'
})
this.banMa = false
}
if (oldX === banX && oldY - 50 === banX && newY + 50 === banY && newX - 50 === banX) {
this.$message({
message: '绊马腿8',
center: true,
type: 'warning'
})
this.banMa = false
}
}
if (oldX + 50 === newX && oldY + 100 === newY && this.banMa) {
this.canGoChess = true
}
if (oldX + 100 === newX && oldY + 50 === newY && this.banMa) {
this.canGoChess = true
}
if (oldX - 100 === newX && oldY - 50 === newY && this.banMa) {
this.canGoChess = true
}
if (oldX + 100 === newX && oldY - 50 === newY && this.banMa) {
this.canGoChess = true
}
if (oldX - 100 === newX && oldY + 50 === newY && this.banMa) {
this.canGoChess = true
}
if (oldX - 50 === newX && oldY - 100 === newY && this.banMa) {
this.canGoChess = true
}
if (oldX - 50 === newX && oldY + 100 === newY && this.banMa) {
this.canGoChess = true
}
if (oldX + 50 === newX && oldY - 100 === newY && this.banMa) {
this.canGoChess = true
}
break
case 3:// xiang
this.canGoChess = false
this.banMa = true
for (let i in this.Chess) {
let banX = this.Chess[i].positionX
let banY = this.Chess[i].positionY
if (newY < 270) {
this.banXiang = false
}
if (newX + 50 === banX && newY + 50 === banY && oldX - 50 === banX && oldY - 50 === banY) {
this.$message({
message: '绊象腿1',
center: true,
type: 'warning'
})
this.banXiang = false
}
if (newX + 50 === banX && newY - 50 === banY && oldX - 50 === banX && oldY + 50 === banY) {
this.$message({
message: '绊象腿2',
center: true,
type: 'warning'
})
this.banXiang = false
}
if (newX - 50 === banX && newY + 50 === banY && oldX + 50 === banX && oldY - 50 === banY) {
this.$message({
message: '绊象腿3',
center: true,
type: 'warning'
})
this.banXiang = false
}
if (newX - 50 === banX && newY - 50 === banY && oldX + 50 === banX && oldY + 50 === banY) {
this.$message({
message: '绊象腿4',
center: true,
type: 'warning'
})
this.banXiang = false
}
}
if (oldX + 100 === newX && oldY + 100 === newY && this.banXiang) {
this.canGoChess = true
}
if (oldX + 100 === newX && oldY - 100 === newY && this.banXiang) {
this.canGoChess = true
}
if (oldX - 100 === newX && oldY + 100 === newY && this.banXiang) {
this.canGoChess = true
}
if (oldX - 100 === newX && oldY - 100 === newY && this.banXiang) {
this.canGoChess = true
}
break
case 4:// shi
this.canGoChess = false
if (newX < 170 || newX > 270) { break }
if (oldX + 50 === newX && oldY + 50 === newY) {
this.canGoChess = true
}
if (oldX - 50 === newX && oldY + 50 === newY) {
this.canGoChess = true
}
if (oldX - 50 === newX && oldY - 50 === newY) {
this.canGoChess = true
}
if (oldX + 50 === newX && oldY - 50 === newY) {
this.canGoChess = true
}
break
case 5:// shuai
this.canGoChess = false
if (newX < 170 || newX > 270) { break }
if (newY < 370 || newY > 470) { break }
if (oldX === newX && oldY - 50 === newY) {
this.canGoChess = true
}
if (oldX - 50 === newX && oldY === newY) {
this.canGoChess = true
}
if (oldX + 50 === newX && oldY === newY) {
this.canGoChess = true
}
if (oldX === newX && oldY + 50 === newY && oldY !== 470) {
this.canGoChess = true
}
break
case 6:
let num = 0
if (newX !== oldX && newY !== oldY) {
this.canGoChess = false
break
}
if (this.existe) {
if (newX === oldX || newY === oldY) {
for (let i in this.Chess) {
if (this.Chess[i].positionX === oldX && this.Chess[i].positionY > minY && this.Chess[i].positionY < maxY) {
num = num + 1
}
if (this.Chess[i].positionY === oldY && this.Chess[i].positionX > minX && this.Chess[i].positionX < maxX) {
num = num + 1
}
}
if (num !== 1) {
this.canGoChess = false
}
break
}
for (let i in this.Chess) {
if (this.Chess[i].positionX === oldX && this.Chess[i].positionY > minY && this.Chess[i].positionY < maxY) {
this.canGoChess = false
}
if (this.Chess[i].positionY === oldY && this.Chess[i].positionX > minX && this.Chess[i].positionX < maxX) {
this.canGoChess = false
}
}
}
if (!this.existe) {
console.log('点击的位置没有棋子')
if (newX === oldX || newY === oldY) {
console.log('x走')
for (let i in this.Chess) {
if (this.Chess[i].positionX === oldX && this.Chess[i].positionY > minY && this.Chess[i].positionY < maxY) {
num = num + 1
}
if (this.Chess[i].positionY === oldY && this.Chess[i].positionX > minX && this.Chess[i].positionX < maxX) {
num = num + 1
}
}
if (num !== 0) {
this.canGoChess = false
}
break
}
}
break
case 7:
this.canGoChess = false
if (oldX === newX && oldY - 50 === newY) {
this.canGoChess = true
}
if (newY <= 220) {
if (oldX === newX && oldY - 50 === newY) {
this.canGoChess = true
}
if (oldY === newY && oldX + 50 === newX) {
this.canGoChess = true
}
if (oldY === newY && oldX - 50 === newX) {
this.canGoChess = true
}
}
}
return this.canGoChess
}
}
}
script>
<style scoped lang="scss">
@import "../../assets/scss/base.scss";
@import "../../assets/scss/mixin.scss";
@import "../../assets/scss/config.scss";
.container{
box-sizing: border-box;
@media only screen and (min-width: 540px) and (max-width: 1180px){
width: 1180px;
}
.dotest{
box-sizing: border-box;
height: 40px;
width: 100%;
border-bottom: 1px solid #cecece;
@include flex();
margin-top: 30px;
.left{
font-size: 20px;
font-family: Microsoft YaHei;
font-weight: 400;
color: #EF0404;
}
.right{
font-size: 20px;
font-family: Microsoft YaHei;
font-weight: 400;
color: #000000;
.time{
font-size: 20px;
font-family: Microsoft YaHei;
font-weight: 400;
color: #EF0404;
}
}
}
.dotest_content{
box-sizing: border-box;
margin-top: 40px;
margin-bottom: 90px;
@include flexed();
.item_left{
width: 225px;
margin-right: 24px;
.info{
width: 225px;
border: 1px solid #cecece;
padding: 20px 30px;
box-sizing: border-box;
margin-bottom: 20px;
.item_title{
width: 100%;
text-align: center;
font-size: 18px;
font-family: Microsoft YaHei;
font-weight: 400;
color: #333333;
}
.item_info{
width: 100%;
text-align: left;
font-size: 16px;
font-family: Microsoft YaHei;
font-weight: 400;
color: #333333;
margin: 10px 0;
.question{
color: #000;
font-size: 30px;
}
.success{
color: #EF0404;
font-size: 30px;
}
}
}
.select {
width: 225px;
border: 1px solid #cecece;
padding: 10px 30px 20px;
box-sizing: border-box;
@include flexed();
.item_choose{
cursor: not-allowed;
width: 20px;
height: 20px;
border: 1px solid #cecece;
font-size: 14px;
font-family: Microsoft YaHei;
font-weight: 400;
color: #333333;
text-align: center;
line-height: 20px;
margin-top: 10px;
margin-right: 13px;
&:nth-child(5n){
margin-right: 0;
}
}
.item_chooses{
background-color: #008DE9;
border: 1px solid #008DE9;
color: #ffffff;
}
.agin_item_choose {
background-color: #999;
border: 1px solid #999;
color: #000;
}
}
.submit{
width: 100px;
height: 40px;
background-color: #008DE9;
color: #ffffff;
text-align: center;
line-height: 40px;
font-size: 20px;
margin: auto;
margin-top: 50px;
cursor: pointer;
}
}
.item-rigts{
width: 931px;
border: 1px solid #cecece;
padding-top: 20px;
padding-bottom: 20px;
// padding-left: 59px;
box-sizing: border-box;
margin: auto;
.canvas-bg{
width: 480px;
background-color: #f8be7c;
padding: 20px;
margin: auto;
}
}
}
}
style>