Skip to content

Commit a493024

Browse files
committed
pygame hello_world
1 parent 9c9bd3c commit a493024

File tree

4 files changed

+186
-0
lines changed

4 files changed

+186
-0
lines changed

python_game/0.test_module/test.py

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
#coding:utf-8
2+
'''
3+
这个文件用于测试新装好的pygame中的小模块是否都齐全
4+
我出现的问题是music模块和游戏手柄模块没有
5+
6+
'''
7+
import pygame
8+
i = 0
9+
if pygame.font is None:
10+
print "the ",i," module is not availavle"
11+
exit()
12+
else:
13+
print "hello world",i
14+
i += 1
15+
if pygame.cdrom is None:
16+
print "the ",i," module is not availavle"
17+
exit()
18+
else:
19+
print "hello world",i
20+
i+=1
21+
if pygame.cursors is None:
22+
print "the ",i," module is not availavle"
23+
exit()
24+
else:
25+
print "hello world",i
26+
i+=1
27+
if pygame.display is None:
28+
print "the ",i," module is not availavle"
29+
exit()
30+
else:
31+
print "hello world",i
32+
i+=1
33+
if pygame.draw is None:
34+
print "the ",i," module is not availavle"
35+
exit()
36+
else:
37+
print "hello world",i
38+
i+=1
39+
if pygame.event is None:
40+
print "the ",i," module is not availavle"
41+
exit()
42+
else:
43+
print "hello world",i
44+
i+=1
45+
if pygame.image is None:
46+
print "the ",i," module is not availavle"
47+
exit()
48+
else:
49+
print "hello world",i
50+
i+=1
51+
if pygame.key is None:
52+
print "the ",i," module is not availavle"
53+
exit()
54+
else:
55+
print "hello world",i
56+
i+=1
57+
if pygame.mixer is None:
58+
print "the ",i," module is not availavle"
59+
exit()
60+
else:
61+
print "hello world",i
62+
i+=1
63+
if pygame.mouse is None:
64+
print "the ",i," module is not availavle"
65+
exit()
66+
else:
67+
print "hello world",i
68+
i+=1
69+
if pygame.music is None:
70+
print "the ",i," module is not availavle"
71+
exit()
72+
else:
73+
print "hello world",i
74+
i+=1
75+
if pygame.overlay is None:
76+
print "the ",i," module is not availavle"
77+
exit()
78+
else:
79+
print "hello world",i
80+
i+=1
81+
if pygame is None:
82+
print "the ",i," module is not availavle"
83+
exit()
84+
else:
85+
print "hello world",i
86+
i+=1
87+
if pygame.rect is None:
88+
print "the ",i," module is not availavle"
89+
exit()
90+
else:
91+
print "hello world",i
92+
i+=1
93+
if pygame.sndarray is None:
94+
print "the ",i," module is not availavle"
95+
exit()
96+
else:
97+
print "hello world",i
98+
i+=1
99+
if pygame.sprite is None:
100+
print "the ",i," module is not availavle"
101+
exit()
102+
else:
103+
print "hello world",i
104+
i+=1
105+
if pygame.surface is None:
106+
print "the ",i," module is not availavle"
107+
exit()
108+
else:
109+
print "hello world",i
110+
i+=1
111+
if pygame.surfarray is None:
112+
print "the ",i," module is not availavle"
113+
exit()
114+
else:
115+
print "hello world",i
116+
i+=1
117+
if pygame.time is None:
118+
print "the ",i," module is not availavle"
119+
exit()
120+
else:
121+
print "hello world",i
122+
i+=1
123+
if pygame.transform is None:
124+
print "the ",i," module is not availavle"
125+
exit()
126+
else:
127+
print "hello world",i
128+
i+=1
129+
if pygame.movie is None:
130+
print "the ",i," module is not availavle"
131+
exit()
132+
else:
133+
print "hello world",i
134+
i+=1
135+
if pygame.movie is None:
136+
print "the ",i," module is not availavle"
137+
exit()
138+
else:
139+
print "hello world",i
140+
i+=1
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#coding:utf-8
2+
'''
3+
本测试样例将创建一个窗口,然后显示一张图片,
4+
'''
5+
#!/usr/bin/env python
6+
7+
background_image_filename = '1.jpg'
8+
mouse_image_filename = '2.jpg'
9+
#制定图像文件名称
10+
11+
import pygame
12+
from pygame.locals import *
13+
from sys import exit
14+
#从sys中使用结束函数
15+
16+
pygame.init()
17+
#初始化pygame、
18+
19+
screen = pygame.display.set_mode((640,480),0,32)
20+
#创建一个窗口,并且制定大小。
21+
22+
pygame.display.set_caption("hello, world! ly first game!")
23+
#设置窗口标题
24+
25+
background = pygame.image.load(background_image_filename).convert()
26+
27+
mouse_cursor = pygame.image.load(mouse_image_filename).convert_alpha()
28+
29+
while True:
30+
31+
for event in pygame.event.get():
32+
if event.type == QUIT:
33+
exit()
34+
#若接受到退出事件后退出程序
35+
screen.blit(background,(0,0))
36+
#画出背景图
37+
x,y = pygame.mouse.get_pos()
38+
#获取鼠标的坐标
39+
x -= mouse_cursor.get_width()/2
40+
#获取鼠标图像的宽高计算新的xy的值,目的是为了能居中
41+
y -= mouse_cursor.get_height()/2
42+
43+
screen.blit(mouse_cursor,(x,y))
44+
#在新的值画上x,y。以及鼠标的图案。
45+
pygame.display.update()
46+
#刷新一下画面

0 commit comments

Comments
 (0)