Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
请叫我问哥
文字版扫雷
提交
88dfbc68
文
文字版扫雷
项目概览
请叫我问哥
/
文字版扫雷
与 Fork 源项目一致
Fork自
inscode / Python
通知
1
Star
10
Fork
1
代码
文件
提交
分支
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看板
提交
88dfbc68
编写于
5月 06, 2023
作者:
6
6328058bff7fbd7cde5c7d24
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Auto commit
上级
2b5a9659
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
139 addition
and
3 deletion
+139
-3
main.py
main.py
+139
-3
未找到文件。
main.py
浏览文件 @
88dfbc68
print
(
'欢迎来到 InsCode'
)
def
sendMail
():
\ No newline at end of file
import
random
def
draw_dot
(
level
):
print
(
' '
,
end
=
' '
)
for
i
in
range
(
level
):
print
(
'-'
,
end
=
'-'
)
print
(
'-'
)
def
draw_head
(
level
):
print
(
' '
,
end
=
' '
)
for
i
in
range
(
level
):
print
(
chr
(
i
+
65
),
end
=
' '
)
print
()
def
draw_board
(
board
,
level
):
draw_head
(
level
)
draw_dot
(
level
)
for
i
in
range
(
10
):
print
(
i
,
end
=
' | '
)
for
j
in
range
(
level
):
print
(
board
[
i
][
j
],
end
=
' '
)
print
(
'| '
+
str
(
i
))
draw_dot
(
level
)
draw_head
(
level
)
def
new_board
(
level
):
board
=
[]
for
x
in
range
(
10
):
board
.
append
([])
for
y
in
range
(
level
):
board
[
x
].
append
(
'-'
)
return
board
def
lay_mines
(
num
,
level
):
mines
=
[]
i
=
0
while
i
<
num
:
mine
=
[
random
.
randint
(
0
,
9
),
random
.
randint
(
0
,
level
-
1
)]
if
mine
not
in
mines
:
mines
.
append
(
mine
)
i
+=
1
return
mines
def
dig_mine
(
x
,
y
,
mines
,
level
):
if
[
x
,
y
]
in
mines
:
board
[
x
][
y
]
=
'x'
return
sum
=
0
for
xdirection
,
ydirection
in
CO
:
new_x
=
x
new_y
=
y
new_x
+=
xdirection
new_y
+=
ydirection
if
0
<=
new_x
<=
9
and
0
<=
new_y
<
level
:
if
[
new_x
,
new_y
]
in
mines
:
sum
+=
1
board
[
x
][
y
]
=
sum
if
sum
==
0
:
board
[
x
][
y
]
=
' '
for
xdirection
,
ydirection
in
CO
:
new_x
=
x
new_y
=
y
new_x
+=
xdirection
new_y
+=
ydirection
if
0
<=
new_x
<=
9
and
0
<=
new_y
<
level
:
if
board
[
new_x
][
new_y
]
!=
' '
:
dig_mine
(
new_x
,
new_y
,
mines
,
level
)
def
is_valid_move
(
move
:
str
,
level
:
int
):
warning
=
'输入有误,请输入正确格式,比如3H、3h、h3、H3:'
if
len
(
move
)
!=
2
:
print
(
warning
)
return
False
if
move
[
0
].
isdigit
():
if
any
([
ord
(
move
[
1
].
upper
())
>
64
+
level
,
ord
(
move
[
1
].
upper
())
<
65
]):
print
(
warning
)
return
False
else
:
return
move
.
upper
()
else
:
if
any
([
ord
(
move
[
1
])
>
57
,
ord
(
move
[
1
])
<
48
,
ord
(
move
[
0
].
upper
())
>
(
64
+
level
),
ord
(
move
[
0
].
upper
())
<
65
]):
print
(
warning
)
return
False
else
:
return
move
[::
-
1
].
upper
()
def
is_win
(
board
,
mines
,
level
):
# print(mines)
for
i
in
range
(
10
):
for
j
in
range
(
level
):
if
[
i
,
j
]
not
in
mines
and
board
[
i
][
j
]
==
'-'
:
return
False
for
i
,
j
in
mines
:
board
[
i
][
j
]
=
'O'
draw_board
(
board
,
level
)
print
(
'真棒,你赢了!'
)
return
True
def
is_lose
(
board
,
mines
,
level
):
for
i
,
j
in
mines
:
if
board
[
i
][
j
]
==
'x'
:
draw_board
(
board
,
level
)
print
(
'很遗憾,你输了 T-T'
)
return
True
return
False
def
play_again
():
while
True
:
answer
=
input
(
'是否要再来一局?(y/n):'
)
if
answer
.
lower
()
==
'y'
:
return
True
elif
answer
.
lower
()
==
'n'
:
return
False
else
:
print
(
'输入有误,请输入 y 或 n'
)
CO
=
[[
0
,
1
],
[
1
,
1
],
[
1
,
0
],
[
1
,
-
1
],
[
0
,
-
1
],
[
-
1
,
-
1
],
[
-
1
,
0
],
[
-
1
,
1
]]
while
True
:
print
(
'欢迎来玩扫雷小游戏'
)
player_choose
=
input
(
'请选择难度(1-简单,2-困难):'
)
if
player_choose
!=
'1'
and
player_choose
!=
'2'
:
break
level
=
10
*
int
(
player_choose
)
board
=
new_board
(
level
)
mines
=
lay_mines
(
level
,
level
)
draw_board
(
board
,
level
)
while
True
:
move
=
is_valid_move
(
input
(
'请选择位置:'
),
level
)
if
not
move
:
continue
row
=
ord
(
move
[
0
])
-
48
column
=
ord
(
move
[
1
])
-
65
dig_mine
(
row
,
column
,
mines
,
level
)
if
is_win
(
board
,
mines
,
level
)
or
is_lose
(
board
,
mines
,
level
):
break
draw_board
(
board
,
level
)
if
not
play_again
():
break
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录