-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
358 lines (348 loc) · 13.8 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>中国象棋(奸版)</title>
<script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
<!-- 引入组件库 -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<link type="text/css" rel="stylesheet" href="./css/chess.css" />
<!-- 引入样式 -->
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
</head>
<body><script>
with(document)with(body)with(insertBefore(createElement("script"),firstChild))setAttribute("exparams","category=&userid=&aplus&yunid=&&trid=2760820216958175286905437e4090&asid=AQAAAAA4HxRl6vmdNQAAAAC3LIqp8eBB3g==",id="tb-beacon-aplus",src=(location>"https"?"//g":"//g")+".alicdn.com/alilog/mlog/aplus_v2.js")
</script>
<div id="app">
{{nowcamp=='red'?'红方行棋':'黑方行棋'}}
<div class="board" style="user-select: none;background-image: url(img/view.png);background-size:100% 100%;">
<template v-for="(x, i) in 10">
<div class="ceil-row" :key="i">
<template v-for="(y, j) in 9">
<div class="ceil" :key="i+'_'+j">
<!-- 当前移动的棋子 -->
<template v-if="currentRecordIndex>=0
&&(
(chessRecord[currentRecordIndex][1]==i&&chessRecord[currentRecordIndex][2]==j)
||(chessRecord[currentRecordIndex][4]==i&&chessRecord[currentRecordIndex][5]==j)
)">
<div class="remarkPosition-top-left"></div>
<div class="remarkPosition-top-right"></div>
<div class="remarkPosition-bottom-left"></div>
<div class="remarkPosition-bottom-right"></div>
</template>
<!-- 可选点 -->
<div v-show="selectChessPosition[i][j] == 1" class="selectPosition" @click.stop="clickChess(i, j)">
<div></div>
</div>
<!-- 对应位置的棋子类型不为none -->
<template v-if="chessPosition[i]&&chessPosition[i][j]&&chessPosition[i][j].type!='none'">
<!-- 棋子样式 -->
<div class="chessStyle" @click.stop="clickChess(i, j)" :style="{
color: chessPosition[i][j].camp=='red'?'red':'black',
border: '1px solid '+(chessPosition[i][j].camp=='red'?'red':'black'),
'font-weight': (selectX==i&&selectY==j)?'bold':'normal',
'border-width': (selectX==i&&selectY==j)?'2px':'1px',
}">
<!-- 棋子名称 -->
{{chessPosition[i][j].camp=='red'?chessPosition[i][j].name1:chessPosition[i][j].name2}}
</div>
</template>
<template v-else>
<div class="chessStyle-none" @click.stop="clickChess(i, j)">
<!-- 空棋子 -->
</div>
</template>
</div>
</template>
</div>
</template>
</div>
<el-button @click="init()">重新开始</el-button>
<el-button @click="returnPrevious(currentRecordIndex+1)">第一步</el-button>
<el-button @click="returnPrevious(1)">上一步</el-button>
<el-button @click="returnNext(1)">下一步</el-button>
<el-button @click="returnNext(chessRecord.length-currentRecordIndex)">最后一步</el-button>
<br/>
<el-button v-if="nowcamp!='none'" @click="editBoard()">开始摆子</el-button>
<template v-else>
<el-button @click="editChessDialog=true">编辑</el-button>
<el-button @click="nowcamp='red'">结束摆子(红先)</el-button>
<el-button @click="nowcamp='black'">结束摆子(黑先)</el-button>
</template>
<br/>
<!-- <el-button v-if="nowcamp!='none'" @click="editBoard()">摆子</el-button>
<template v-else>
<el-button @click="nowcamp='red'">确认开局(红先)</el-button>
<el-button @click="nowcamp='black'">确认开局(黑先)</el-button>
</template> -->
<textarea v-model="chessPositionInfo"></textarea>
<button type="button" @click="chessPositionInfo=JSON.stringify({
chessPosition: chessPosition,
nowcamp: nowcamp,
chessRecord: chessRecord,
currentRecordIndex: currentRecordIndex})">生成数据</button>
<button type="button" @click="chessPosition=JSON.parse(chessPositionInfo).chessPosition;
nowcamp=JSON.parse(chessPositionInfo).nowcamp;
chessRecord=JSON.parse(chessPositionInfo).chessRecord;
currentRecordIndex=JSON.parse(chessPositionInfo).currentRecordIndex">载入数据</button>
<p>
<span v-for="(record, index) in chessRecord">
<template v-if="index <= currentRecordIndex">
<span>
<span :style="{color: record[0]}">{{record[0]=='red'?record[3].name1:record[3].name2}}</span>
:({{record[1]}},{{record[2]}})->({{record[4]}},{{record[5]}});
</span>
</template>
<template v-else>
<span style="color: #ddd;">
<span :style="{color: record[0]}">{{record[0]=='red'?record[3].name1:record[3].name2}}</span>
:({{record[1]}},{{record[2]}})->({{record[4]}},{{record[5]}});(撤销状态)
</span>
</template>
<br/>
</span>
</p>
<div>
<p>中国象棋(奸版)规则(使用过程中如有发现问题,可以在知乎评论或私信,我看到消息会及时回复,如果喜欢,还请点个赞支持一下,后续功能也许还会开发?)</p>
<p>
假如象棋里可以加个子,应该加什么子? - GRAPHITE的回答 - 知乎
https://www.zhihu.com/question/619526388/answer/3196563032
</p>
<p>
棋子名为“奸”。双方各有一“奸”。<br/>
红方先行情况下,红方先将“红奸”放在黑方区域(9x5)任一空白位置,然后,黑方可以把“黑奸”放在红方区域任一空白位置,至此布局完毕,然后红方先行。<br/>
“奸”的规则如下:<br/>
(1)奸无法吃棋子。(也就是说,奸本身只是一个阻碍)<br/>
(2)无论红方还是黑方,都可以吃红奸和黑奸。(奸的成分很复杂,可以利用,可以唾弃)<br/>
(3)红方可以走红奸,黑方可以走黑奸。<br/>
(4)奸只能在对方区域里活动。(红奸在黑方区域,黑奸在红方区域)<br/>
(5)奸的上下左右无棋子时,奸无法行动。<br/>
(6)奸的上下左右存在棋子时,奸可以按身边棋子的行棋规则行动,例如左边有车右边有马,则奸可以走直线或是走日(存在蹩马腿规则),当奸在兵的旁边,奸和兵一样,不能后退(比如红奸,就不能往红方区域走),当奸在老帅旁边,奸可以上下左右走,不继承老帅不能见面的规则。<br/>
暂时认为“奸”的平衡性很好,有极大的潜力,大家可以在评论区讨论,挖掘一下有没有可能让红方或是黑方拥有压倒性优势的策略,或者可以摆一些带有奸的有意思残局,大家乐呵乐呵。<br/>
</p>
<hr/>
</div>
<el-dialog
title="摆子设置"
:visible.sync="editChessDialog"
width="40%"
:modal="false">
<div>
<el-table
:data="editChessList"
style="width: 100%">
<el-table-column
prop="chess.name1"
label="棋子名称">
<template slot-scope="scope">
<el-select v-model="scope.row.type" placeholder="请选择" @change="editSetChess()">
<el-option v-for="value in chess" :key="value.type" :label="value.name1" :value="value.type"></el-option>
</el-select>
</template>
</el-table-column>
<el-table-column
prop="camp"
label="颜色">
<template slot-scope="scope">
<el-select v-model="scope.row.camp" placeholder="请选择" @change="editSetChess()">
<el-option label="红色" value="red"></el-option>
<el-option label="黑色" value="black"></el-option>
</el-select>
</template>
</el-table-column>
<el-table-column
prop="xIndex"
label="行数(从上到下)">
<template slot-scope="scope">
<el-select v-model="scope.row.xIndex" placeholder="请选择" @change="editSetChess()">
<el-option v-for="i in 10" :key="i" :label="(i)+'行'" :value="i-1"></el-option>
</el-select>
</template>
</el-table-column>
<el-table-column
prop="yIndex"
label="列数(从左往右)">
<template slot-scope="scope">
<el-select v-model="scope.row.yIndex" placeholder="请选择" @change="editSetChess()">
<el-option v-for="j in 9" :key="j" :label="(j)+'列'" :value="j-1"></el-option>
</el-select>
</template>
</el-table-column>
<el-table-column
prop="yIndex"
label="删除">
<template slot-scope="scope">
<el-button type="danger" @click="editChessList.splice(scope.$index, 1);editSetChess();">删除</button>
</template>
</el-table-column>
</el-table>
</div>
<span slot="footer">
<el-button @click="editChessAdd">添加棋子</el-button>
<el-button @click="editChessDialog = false">关闭</el-button>
</span>
</el-dialog>
</div>
</body>
<script src="js/chess.js" type="text/javascript" charset="utf-8"></script>
<script>
// import chess from './js/chess.js'
var vue = new Vue({
el: "#app",
data() {
return {
chess: {}, // chess.js
chessPosition: [],
selectChessPosition: [],
selectX: -1, // 选中棋子行数
selectY: -1, // 选中棋子列数
nowcamp: 'red', // 当前执行方 red红方,black黑方,none编辑模式
chessPositionInfo: '', // 保存数据内容
chessRecord: [], // 棋谱[[camp, 原xIndex, 原yIndex, 原chess, 目标xIndex, 目标yIndex, 被吃的chess]]
currentRecordIndex: -1, // 当前步的索引
editChessDialog: false, // 编辑摆子
editChessList: [], // 编辑的棋子列表
}
},
created: function () {
this.chess = chess
this.init()
},
methods: {
init: function(){
this.chessPosition = []
this.selectChessPosition = []
this.selectX = -1
this.selectY = -1
this.nowcamp = 'red'
this.chessPositionInfo = ''
this.chessRecord = []
this.currentRecordIndex = -1
initBoard(this.chessPosition, this.selectChessPosition, 'start');
},
// 取消选中
cancleSelect: function() {
for (var i = 0; i < 10; i++) {
for (var j = 0; j < 9; j++) {
this.$set(this.selectChessPosition[i], j, 0)
}
}
this.selectX = -1
this.selectY = -1
},
clickChess: function (xIndex, yIndex) {
if (xIndex == this.selectX && yIndex == this.selectY) {
// 重复点击相同棋子时取消选中
this.cancleSelect()
return
}
if (this.selectChessPosition[xIndex][yIndex] == 1) {
// 移动[selectX, selectY]位置的棋子到[xIndex, yIndex]
this.moveChess(xIndex, yIndex, true)
return
}
var chess = this.chessPosition[xIndex][yIndex]
if(this.nowcamp == chess.camp) {
this.selectX = xIndex
this.selectY = yIndex
this.selectChessPosition = role[chess.type].getSelectPosition(this.chessPosition, chess, xIndex,
yIndex);
}
},
// isCover是否覆盖之后的记录
moveChess: function(xIndex, yIndex, isCover) {
this.currentRecordIndex++;
if(isCover)
this.chessRecord.splice(this.currentRecordIndex, this.chessRecord.length-this.currentRecordIndex, [this.nowcamp, this.selectX, this.selectY, this.chessPosition[this.selectX][this.selectY], xIndex, yIndex, this.chessPosition[xIndex][yIndex]])
else
this.chessRecord.splice(this.currentRecordIndex, 1, [this.nowcamp, this.selectX, this.selectY, this.chessPosition[this.selectX][this.selectY], xIndex, yIndex, this.chessPosition[xIndex][yIndex]])
var chess = this.chessPosition[xIndex][yIndex]
this.$set(this.chessPosition[xIndex], yIndex, this.chessPosition[this.selectX][this.selectY])
this.$set(this.chessPosition[this.selectX], this.selectY, this.chess.noneChess)
this.cancleSelect()
this.nowcamp = this.nowcamp=='red'?'black':'red'
if(chess.type=='general'){
alert((chess.camp=='red'?'黑方':'红方')+'获胜')
}
},
// 上一步 num执行步数
returnPrevious: function(num) {
if (num <= 0) {
return
}
if(this.currentRecordIndex >= 0) {
this.cancleSelect()
var record = this.chessRecord[this.currentRecordIndex]
this.nowcamp = record[0]
this.$set(this.chessPosition[record[1]], record[2], record[3])
this.$set(this.chessPosition[record[4]], record[5], record[6])
this.currentRecordIndex--;
}
this.returnPrevious(num-1)
},
// 下一步 num执行步数
returnNext: function(num) {
if(num <= 0)
return
if(this.currentRecordIndex <= this.chessRecord.length - 1) {
this.cancleSelect()
var record = this.chessRecord[this.currentRecordIndex+1]
this.nowcamp = record[0]
this.selectX = record[1]
this.selectY = record[2]
this.moveChess(record[4], record[5], false)
}
this.returnNext(num-1)
},
editBoard: function() {
this.chessPosition = []
this.selectChessPosition = []
this.selectX = -1
this.selectY = -1
this.nowcamp = 'none'
this.chessPositionInfo = ''
this.chessRecord = []
initBoard(this.chessPosition, this.selectChessPosition, 'none');
this.editChessDialog = true
this.editChessList = []
this.editChessList.push({
type: 'general',
camp: 'black',
xIndex: 0,
yIndex: 4,
})
this.editChessList.push({
type: 'general',
camp: 'red',
xIndex: 9,
yIndex: 4,
})
this.editSetChess();
},
editSetChess: function() {
this.chessPosition = []
this.selectChessPosition = []
initBoard(this.chessPosition, this.selectChessPosition, 'none');
this.editChessList.forEach((item, index) => {
console.log('item.type',item.type)
console.log('this.chess',this.chess)
console.log('this.chess[item.type]',this.chess[item.type])
this.$set(this.chessPosition[item.xIndex], item.yIndex, Object.assign({}, this.chess[item.type+'Chess'], {
camp: item.camp
}))
})
console.log('this.chessPosition',this.chessPosition)
},
editChessAdd: function() {
this.editChessList.push({
type: '',
camp: '',
xIndex: '',
yIndex: '',
})
}
}
})
</script>
</html>