Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
青春狗头少年不会梦到格温学姐
【前端】vue井字棋游戏
提交
34ff110b
【
【前端】vue井字棋游戏
项目概览
青春狗头少年不会梦到格温学姐
/
【前端】vue井字棋游戏
与 Fork 源项目一致
Fork自
inscode / VueJS
通知
1
Star
4
Fork
2
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
【
【前端】vue井字棋游戏
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
34ff110b
编写于
5月 29, 2023
作者:
6
641737939035885f1803c7ba
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Auto Commit
上级
a5450115
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
149 addition
and
41 deletion
+149
-41
src/App.vue
src/App.vue
+149
-41
未找到文件。
src/App.vue
浏览文件 @
34ff110b
<
script
setup
>
import
HelloWorld
from
'
./components/HelloWorld.vue
'
import
TheWelcome
from
'
./components/TheWelcome.vue
'
<
script
>
export
default
{
data
(){
return
{
datas
:
Array
(
9
).
fill
(
''
),
history
:
[],
next
:
true
,
winner
:
''
,
cases
:
[
[
0
,
1
,
2
],
[
3
,
4
,
5
],
[
6
,
7
,
8
],
[
0
,
3
,
6
],
[
1
,
4
,
7
],
[
2
,
5
,
8
],
[
0
,
4
,
8
],
[
2
,
4
,
6
],
]
}
},
methods
:
{
//放置棋子
set
(
idx
)
{
if
(
!
this
.
datas
[
idx
]
&&
!
this
.
winner
)
{
this
.
datas
[
idx
]
=
this
.
next_player
this
.
history
.
push
({
status
:
[...
this
.
datas
],
player
:
this
.
next
});
if
(
this
.
is_win
(
this
.
next_player
))
{
this
.
winner
=
this
.
next_player
;
}
this
.
next
=
!
this
.
next
;
}
},
//跳转到第n步
jump
(
idx
)
{
this
.
datas
=
this
.
history
[
idx
].
status
;
this
.
history
.
splice
(
idx
+
1
,
this
.
history
.
length
-
idx
-
1
);
this
.
next
=
!
this
.
history
[
idx
].
player
;
this
.
winner
=
this
.
is_win
(
'
O
'
)
?
'
O
'
:
this
.
is_win
(
'
X
'
)
?
'
X
'
:
''
;
},
//判断是否胜出
is_win
(
player
)
{
return
this
.
cases
.
some
(
arr
=>
arr
.
every
(
el
=>
this
.
datas
[
el
]
===
player
));
},
//初始化
init
()
{
this
.
datas
=
Array
(
9
).
fill
(
''
);
this
.
history
=
[];
this
.
next
=
true
;
this
.
winner
=
''
;
}
},
computed
:
{
next_player
()
{
return
this
.
next
?
'
O
'
:
'
X
'
;
},
hint
()
{
return
this
.
winner
?
'
winner:
'
+
this
.
winner
:
'
下一位:
'
+
this
.
next_player
;
}
}
}
</
script
>
<
template
>
<header>
<img
alt=
"Vue logo"
class=
"logo"
src=
"./assets/logo.svg"
width=
"125"
height=
"125"
/>
<div
class=
"wrapper"
>
<HelloWorld
msg=
"You did it!"
/>
<div
id=
"main"
>
<ul
id=
"board"
class=
"white normal"
>
<li
class=
"square"
v-for=
"i, idx in datas"
@
click=
set(idx)
>
{{
i
}}
</li>
</ul>
<div
id=
"console"
>
<div
id=
"hint"
class=
"white"
>
{{
hint
}}
</div>
<button
@
click=
"init()"
>
重新开始
</button>
<!--
<ul
id=
"history"
class=
"normal"
>
<li
class=
"history"
v-for=
"i, idx in history"
>
<input
type=
"button"
class=
"white"
:value=
"'go to step' + (idx + 1)"
@
click=
jump(idx)
/>
</li>
</ul>
-->
</div>
</header>
<main>
<TheWelcome
/>
</main>
</div>
</
template
>
<
style
scoped
>
header
{
line-height
:
1.5
;
}
<
style
type=
"text/css"
>
body
{
background
:
#5af
;
}
.logo
{
display
:
block
;
margin
:
0
auto
2rem
;
}
.white
{
background
:
#fff
;
border-radius
:
11px
;
outline
:
none
;
border
:
none
;
}
@media
(
min-width
:
1024px
)
{
header
{
display
:
flex
;
place-items
:
center
;
padding-right
:
calc
(
var
(
--section-gap
)
/
2
);
.normal
{
list-style
:
none
;
padding
:
0px
;
margin
:
0px
;
}
.logo
{
margin
:
0
2rem
0
0
;
#app
{
display
:
flex
;
justify-content
:
space-between
;
width
:
450px
;
height
:
306px
;
position
:
absolute
;
top
:
0
;
bottom
:
0
;
left
:
0
;
right
:
0
;
margin
:
auto
;
}
header
.wrapper
{
#board
{
display
:
flex
;
place-items
:
flex-start
;
width
:
306px
;
height
:
306px
;
flex-wrap
:
wrap
;
overflow
:
hidden
;
}
#hint
{
width
:
100px
;
height
:
22px
;
text-align
:
center
;
margin
:
10px
;
}
#restart
{
width
:
70px
;
height
:
22px
;
margin
:
10px
;
}
#history
,
.history
{
margin
:
5px
;
}
.square
{
height
:
100px
;
width
:
100px
;
border
:
#ebebeb
solid
1px
;
flex
:
0
0
auto
;
font-size
:
50px
;
font-weight
:
900
;
line-height
:
100px
;
text-align
:
center
;
}
}
</
style
>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录