Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
aa152147
五子棋
提交
529d3358
五
五子棋
项目概览
aa152147
/
五子棋
与 Fork 源项目一致
Fork自
inscode / VueJS
通知
1
Star
43
Fork
23
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
五
五子棋
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
529d3358
编写于
7月 11, 2023
作者:
6
63db3122f0950a2aef64df95
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Auto Commit
上级
014e8bbf
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
75 addition
and
2 deletion
+75
-2
src/App.vue
src/App.vue
+4
-2
src/assets/main.css
src/assets/main.css
+5
-0
src/components/RandomTree.vue
src/components/RandomTree.vue
+66
-0
未找到文件。
src/App.vue
浏览文件 @
529d3358
<
script
setup
>
import
{
onMounted
,
ref
,
computed
}
from
"
vue
"
import
{
is_empty
,
checkWin
,
is_black
,
is_white
,
robotPlay
}
from
"
./utils
"
import
RandomTree
from
"
./components/RandomTree.vue
"
;
// import { robotPlay } from './utils/api'
// 配置
const
size
=
ref
(
20
)
...
...
@@ -80,8 +81,8 @@ async function playChess(item, row, col) {
<label
for=
"win_size"
class=
"space-nowrap"
>
胜利棋数:
</label>
<input
v-model=
"win_size"
id=
"win_size"
type=
"number"
min=
"3"
max=
"8"
>
</p>
<button
@
click=
"confirm"
class=
"space-nowrap mr-6px"
>
重新开始
</button>
<button
@
click=
"back"
class=
"space-nowrap"
>
返回上一步
</button>
<button
@
click=
"confirm"
class=
"space-nowrap mr-6px
px-6px
"
>
重新开始
</button>
<button
@
click=
"back"
class=
"space-nowrap
px-6px
"
>
返回上一步
</button>
</div>
<div
class=
"content border-top content-lattice"
>
<p
class=
"row"
v-for=
"(lattice, r_i) in lattices"
:key=
"r_i"
>
...
...
@@ -90,5 +91,6 @@ async function playChess(item, row, col) {
</p>
</p>
</div>
<RandomTree
/>
</
template
>
src/assets/main.css
浏览文件 @
529d3358
...
...
@@ -9,6 +9,7 @@ html,
body
,
#app
{
height
:
100%
;
position
:
relative
;
}
#app
{
...
...
@@ -36,6 +37,10 @@ body,
.mr-6px
{
margin-right
:
6px
;
}
.px-6px
{
padding-left
:
6px
;
padding-right
:
6px
;
}
input
{
width
:
60px
;
...
...
src/components/RandomTree.vue
0 → 100644
浏览文件 @
529d3358
<
template
>
<canvas
width=
"300"
height=
"300"
ref=
"canvas"
></canvas>
</
template
>
<
script
setup
>
import
{
ref
,
onMounted
}
from
"
vue
"
const
canvas
=
ref
(
null
)
onMounted
(()
=>
{
const
c
=
document
.
querySelector
(
"
canvas
"
)
const
a
=
c
.
getContext
(
'
2d
'
);
const
ctx
=
canvas
.
value
?.
getContext
(
'
2d
'
)
ctx
.
translate
(
canvas
.
value
.
width
/
2
,
canvas
.
value
.
height
)
ctx
.
scale
(
1
,
-
1
)
drawBranch
(
ctx
,
[
0
,
0
],
15
,
56
,
90
)
})
function
drawRound
(
ctx
,
v0
)
{
ctx
.
beginPath
();
ctx
.
arc
(...
v0
,
6
,
0
,
2
*
Math
.
PI
);
ctx
.
fillStyle
=
"
#8DB1A9
"
ctx
.
fill
();
}
/**
*
* @param {CanvasRenderingContext2D} ctx 2d 绘图上下文
* @param {[number, number]} v0 起点坐标
* @param {number} thick 树枝粗细
* @param {number} len 一截树枝长短
* @param {number} dir 倾斜角度
*/
function
drawBranch
(
ctx
,
v0
,
thick
,
len
,
dir
)
{
if
((
thick
<
5
&&
Math
.
random
()
<
0.3
))
return
;
if
(
thick
<
2
)
{
drawRound
(
ctx
,
v0
)
return
;
}
ctx
.
beginPath
();
ctx
.
moveTo
(...
v0
);
const
v1
=
[
v0
[
0
]
+
len
*
Math
.
cos
((
dir
*
Math
.
PI
)
/
180
),
v0
[
1
]
+
len
*
Math
.
sin
((
dir
*
Math
.
PI
)
/
180
)
]
ctx
.
lineTo
(...
v1
);
ctx
.
strokeStyle
=
"
#333
"
;
ctx
.
lineCap
=
"
round
"
;
ctx
.
lineWidth
=
thick
;
ctx
.
stroke
();
drawBranch
(
ctx
,
v1
,
thick
*
0.8
,
len
*
0.8
,
dir
+
Math
.
random
()
*
46
);
drawBranch
(
ctx
,
v1
,
thick
*
0.8
,
len
*
0.8
,
dir
-
Math
.
random
()
*
46
);
}
</
script
>
<
style
>
canvas
{
position
:
absolute
;
right
:
10px
;
bottom
:
10px
;
border-radius
:
50%
;
overflow
:
hidden
;
border
:
1px
solid
#999
;
}
</
style
>
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录