
17.05.2023, 20:47
|
|
Познающий
Регистрация: 31.03.2023
Сообщений: 67
С нами:
1644762
Репутация:
8
|
|
Сообщение от woodware
скинь код свой
Python:
[CODE]
import
random
import
pygame
as
pg
WSIZE
=
(
720
,
480
)
screen
=
pg
.
display
.
set_mode
(
WSIZE
)
TSIDE
=
30
MSIZE
=
WSIZE
[
0
]
//
TSIDE
,
WSIZE
[
1
]
//
TSIDE
start_pos
=
MSIZE
[
0
]
//
2
,
MSIZE
[
1
]
//
2
snake
=
[
start_pos
]
alive
=
True
direction
=
0
directions
=
[
(
1
,
0
)
,
(
0
,
1
)
,
(
-
1
,
0
)
,
(
0
,
-
1
)
]
apple
=
random
.
randint
(
0
,
MSIZE
[
0
]
-
1
)
,
random
.
randint
(
0
,
MSIZE
[
1
]
-
1
)
fps
=
5
clock
=
pg
.
time
.
Clock
(
)
pg
.
font
.
init
(
)
font_score
=
pg
.
font
.
SysFont
(
"Arial"
,
25
)
font_gameover
=
pg
.
font
.
SysFont
(
"Arial"
,
45
)
font_space
=
pg
.
font
.
SysFont
(
"Arial"
,
18
)
running
=
True
while
running
:
clock
.
tick
(
fps
)
screen
.
fill
(
"black"
)
for
event
in
pg
.
event
.
get
(
)
:
if
event
.
type
==
pg
.
QUIT
:
running
=
False
if
event
.
type
==
pg
.
KEYDOWN
:
if
alive
:
if
event
.
key
==
pg
.
K_RIGHT
and
direction
!=
2
:
direction
=
0
if
event
.
key
==
pg
.
K_DOWN
and
direction
!=
3
:
direction
=
1
if
event
.
key
==
pg
.
K_LEFT
and
direction
!=
0
:
direction
=
2
if
event
.
key
==
pg
.
K_UP
and
direction
!=
1
:
direction
=
3
else
:
if
event
.
key
==
pg
.
K_SPACE
:
alive
=
True
snake
=
[
start_pos
]
apple
=
random
.
randint
(
0
,
MSIZE
[
0
]
-
1
)
,
random
.
randint
(
0
,
MSIZE
[
1
]
-
1
)
fps
=
5
[
pg
.
draw
.
rect
(
screen
,
"green"
,
(
x
*
TSIDE
,
y
*
TSIDE
,
TSIDE
-
1
,
TSIDE
-
1
)
)
for
x
,
y
in
snake
]
pg
.
draw
.
rect
(
screen
,
"red"
,
(
apple
[
0
]
*
TSIDE
,
apple
[
1
]
*
TSIDE
,
TSIDE
-
1
,
TSIDE
-
1
)
)
if
alive
:
new_pos
=
snake
[
0
]
[
0
]
+
directions
[
direction
]
[
0
]
,
snake
[
0
]
[
1
]
+
directions
[
direction
]
[
1
]
if
not
(
0
|
|
|