-
Notifications
You must be signed in to change notification settings - Fork 0
/
beadando_horvath_mate.py
182 lines (141 loc) · 5.27 KB
/
beadando_horvath_mate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import teknős
behozatali idő
véletlenszerű importálás
késleltetés = 0,1
# Pontszám
pontszám = 0
high_score = 0
# Állítsa be a képernyőt
wn = teknős . Képernyő ()
wn . cím ( "Snake Game by @TokyoEdTech" )
wn . bgcolor ( "zöld" )
wn . beállítás ( szélesség = 600 , magasság = 600 )
wn . nyomkövető ( 0 ) # Kikapcsolja a képernyőfrissítéseket
# Kígyófej
fej = teknős . Teknős ()
fej . sebesség ( 0 )
fej . forma ( "négyzet" )
fej . szín ( "fekete" )
fej . felemelés ()
fej . goto ( 0 , 0 )
fej . irány = "stop"
# Kígyóeledel
étel = teknős . Teknős ()
ételt . sebesség ( 0 )
ételt . forma ( "kör" )
ételt . szín ( "piros" )
ételt . felemelés ()
ételt . goto ( 0 , 100 )
szegmensek = []
# Toll
toll = teknős . Teknős ()
toll . sebesség ( 0 )
toll . forma ( "négyzet" )
toll . szín ( "fehér" )
toll . felemelés ()
toll . rejtőzködő teknős ()
toll . goto ( 0 , 260 )
toll . write ( "Pontszám: 0 Magas pontszám: 0" , align = "center" , font = ( "Courier" , 24 , "normal" ))
# Funkciók
def go_up ():
ha fej . irány != "le" :
fej . irány = "fel"
def go_down ():
ha fej . irány != "fel" :
fej . irány = "le"
def go_left ():
ha fej . irány != "jobbra" :
fej . irány = "balra"
def go_right ():
ha fej . irány != "balra" :
fej . irány = "jobbra"
def move ():
ha fej . irány == "fel" :
y = fej . ycor ()
fej . sety ( y + 20 )
ha fej . irány == "le" :
y = fej . ycor ()
fej . sety ( y - 20 )
ha fej . irány == "balra" :
x = fej . xcor ()
fej . setx ( x - 20 )
ha fej . irány == "jobbra" :
x = fej . xcor ()
fej . setx ( x + 20 )
# Billentyűzetkötések
wn . figyelj ()
wn . onkeypress ( go_up , "w" )
wn . onkeypress ( go_down , "s" )
wn . onkeypress ( go_left , "a" )
wn . onkeypress ( go_right , "d" )
# Fő játékhurok
míg igaz :
wn . frissítés ()
# Ellenőrizze, nincs-e ütközés a határral
ha fej . xcor () > 290 vagy fej . xcor () < - 290 vagy fej . ycor () > 290 vagy fej . ycor () < - 290 :
idő . aludni ( 1 )
fej . goto ( 0 , 0 )
fej . irány = "stop"
# A szegmensek elrejtése
szegmensekben : _ _ _
szegmens . goto ( 1000 , 1000 )
# Törölje a szegmensek listáját
szegmensek . tiszta ()
# Állítsa vissza a pontszámot
pontszám = 0
# Állítsa vissza a késleltetést
késleltetés = 0,1
toll . tiszta ()
toll . write ( "Pontszám: {} Magas pontszám: {}" . formátum ( score , high_score ), align = "center" , font = ( "Courier" , 24 , "normal" ))
# Ellenőrizze, hogy nem ütközött-e az élelmiszerrel
ha fej . távolság ( étel ) < 20 :
# Helyezze az ételt egy véletlenszerű helyre
x = véletlenszerű . randint ( - 290 , 290 )
y = véletlenszerű . randint ( - 290 , 290 )
ételt . goto ( x , y )
# Szegmens hozzáadása
new_segment = teknős . Teknős ()
új_szegmens . sebesség ( 0 )
új_szegmens . forma ( "négyzet" )
új_szegmens . szín ( "szürke" )
új_szegmens . felemelés ()
szegmensek . hozzáfűzés ( új_szegmens )
# Rövidítse le a késleltetést
késleltetés -= 0,001
# Növelje a pontszámot
pontszám += 10
ha pontszám > high_score :
high_score = pontszám
toll . tiszta ()
toll . write ( "Pontszám: {} Magas pontszám: {}" . formátum ( score , high_score ), align = "center" , font = ( "Courier" , 24 , "normal" ))
# Mozgassa először a végszegmenseket fordított sorrendben
a tartományban lévő indexhez ( len ( szegmensek ) - 1 , 0 , - 1 ):
x = szegmensek [ index - 1 ]. xcor ()
y = szegmensek [ index - 1 ]. ycor ()
szegmensek [ index ]. goto ( x , y )
# Mozgassa a 0. szegmenst oda, ahol a fej van
ha len ( szegmensek ) > 0 :
x = fej . xcor ()
y = fej . ycor ()
szegmensek [ 0 ]. goto ( x , y )
mozogni ()
# Ellenőrizze, hogy a fej nem ütközik-e a testrészekkel
szegmensekben : _ _ _
ha szegmens . távolság ( fej ) < 20 :
idő . aludni ( 1 )
fej . goto ( 0 , 0 )
fej . irány = "stop"
# A szegmensek elrejtése
szegmensekben : _ _ _
szegmens . goto ( 1000 , 1000 )
# Törölje a szegmensek listáját
szegmensek . tiszta ()
# Állítsa vissza a pontszámot
pontszám = 0
# Állítsa vissza a késleltetést
késleltetés = 0,1
# Frissítse a pontszám kijelzőt
toll . tiszta ()
toll . write ( "Pontszám: {} Magas pontszám: {}" . formátum ( score , high_score ), align = "center" , font = ( "Courier" , 24 , "normal" ))
idő . alvás ( késés )
wn . főhurok ()