Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
lesson9_3
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
1b0cd9a2
authored
Jul 13, 2024
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
2868cd77
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
93 additions
and
9 deletions
diy3.py
dvojfdi.py
diy3.py
View file @
1b0cd9a2
student1
=
{
'语文'
:
91
,
'数学'
:
88
,
'英语'
:
85
}
student1
=
{
'语文'
:
91
,
'数学'
:
88
,
'英语'
:
85
}
student2
=
{
'语文'
:
97
,
'数学'
:
98
,
'英语'
:
90
}
student2
=
{
'语文'
:
97
,
'数学'
:
98
,
'英语'
:
90
}
student3
=
{
'语文'
:
95
,
'数学'
:
100
,
'英语'
:
93
}
student3
=
{
'语文'
:
95
,
'数学'
:
100
,
'英语'
:
93
}
score
=
{
'悟空'
:
student1
,
'诺依'
:
student2
,
'小贝'
:
student3
}
student4
=
{
'语文'
:
100
,
'数学'
:
100
,
'英语'
:
100
}
score
=
{
'悟空'
:
student1
,
'诺依'
:
student2
,
'小贝'
:
student3
,
'刘俊贤'
:
student4
}
while
True
:
print
(
'*'
*
30
)
print
(
'请输入名字,退出请按q'
)
# 查询并打印出输入的名字对应的所有科目的成绩
name
=
input
(
'姓名:'
)
a
=
score
[
'诺依'
]
if
name
in
score
:
for
k
,
v
in
a
.
items
():
for
k
,
v
in
score
[
name
]
.
items
():
print
(
k
,
v
)
print
(
k
,
v
)
\ No newline at end of file
elif
name
==
'q'
:
print
(
'已退出'
)
break
else
:
print
(
'输入错误,请重新输入名字'
)
\ No newline at end of file
dvojfdi.py
View file @
1b0cd9a2
import
pygame
from
pygame
import
locals
import
random
pygame
.
init
()
# 初始化
class
Block
(
pygame
.
sprite
.
Sprite
):
def
__init__
(
self
,
image1
,
image2
,
image3
):
super
()
.
__init__
()
self
.
image
=
random
.
choice
([
image1
,
image2
,
image3
])
self
.
rect
=
self
.
image
.
get_rect
()
self
.
rect
.
x
=
1000
self
.
rect
.
y
=
500
-
self
.
rect
.
height
# 创建一个窗口
screen
=
pygame
.
display
.
set_mode
((
1000
,
600
))
FPS
=
pygame
.
time
.
Clock
()
# pygame时钟,控制游戏速度(帧数)
# 载入图片
background
=
pygame
.
image
.
load
(
'bg.png'
)
# 背景
road
=
pygame
.
image
.
load
(
'road.png'
)
# 路
stone
=
pygame
.
image
.
load
(
'stone.png'
)
# 石头
cacti
=
pygame
.
image
.
load
(
'cacti.png'
)
# 仙人掌
apple
=
pygame
.
image
.
load
(
'bush.png'
)
# 灌木丛
hero
=
[
pygame
.
image
.
load
(
'hero1.png'
),
pygame
.
image
.
load
(
'hero2.png'
),
pygame
.
image
.
load
(
'hero3.png'
),
pygame
.
image
.
load
(
'hero4.png'
),
pygame
.
image
.
load
(
'hero5.png'
)]
index
=
0
y
=
400
jumpState
=
"runing"
t
=
30
road_x
=
0
we_x
=
0
r
=
Block
(
apple
,
stone
,
cacti
)
while
True
:
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
# 接收到退出事件后退出程序
exit
()
if
jumpState
==
"runing"
:
if
event
.
type
==
locals
.
KEYDOWN
:
if
event
.
key
==
locals
.
K_SPACE
:
jumpState
=
"up"
if
jumpState
==
"up"
:
if
t
>
0
:
y
-=
t
t
-=
2
else
:
jumpState
=
"down"
if
jumpState
==
"down"
:
if
t
<=
30
:
y
+=
t
t
+=
2
else
:
jumpState
=
"runing"
t
=
30
wukong
=
hero
[
index
]
if
jumpState
==
"runing"
:
if
index
==
4
:
index
=
0
else
:
index
+=
1
# 将背景图画上去
we_x
-=
5
if
we_x
<=
-
1000
:
we_x
=
0
screen
.
blit
(
background
,
(
we_x
,
0
))
road_x
-=
8
if
road_x
<=
-
1000
:
road_x
=
0
screen
.
blit
(
road
,(
road_x
,
500
))
screen
.
blit
(
wukong
,
(
150
,
y
))
if
r
.
rect
.
x
<=
0
-
r
.
rect
.
width
:
r
=
Block
(
apple
,
stone
,
cacti
)
r
.
rect
.
x
-=
8
screen
.
blit
(
r
.
image
,(
r
.
rect
.
x
,
r
.
rect
.
y
))
# 刷新画面
pygame
.
display
.
update
()
FPS
.
tick
(
60
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment