console_snake/out.py

42 lines
1.1 KiB
Python
Raw Normal View History

2022-10-26 21:57:29 +03:00
from settings import *
from player import Player
from frame import Frame
class Out:
2022-10-27 00:29:36 +03:00
def __init__(self, pl: Player) -> None:
2022-10-26 21:57:29 +03:00
self.width = WIDTH
self.height = HEIGHT
self.fps = FPS
2022-10-27 00:29:36 +03:00
self.pl = pl
2022-10-26 21:57:29 +03:00
2022-10-27 00:29:36 +03:00
def draw(self) -> None:
2022-10-26 21:57:29 +03:00
frame = Frame(self.width, self.height)
2022-10-27 00:29:36 +03:00
pl = self.pl
2022-10-26 21:57:29 +03:00
for point in pl.body:
if point.x < 0 or point.y < 0:
raise IndexError("Snake has collision with walls")
elif point.x >= WIDTH or point.y >= HEIGHT:
raise IndexError("Snake has collision with walls")
frame.draw(
x=point.x, y=point.y,
value=WALL,
width=1, height=1
)
if frame.see(pl.food.x, pl.food.y) == WALL:
frame.draw(
x=pl.food.x, y=pl.food.y,
value=WALL_FOOD
)
else:
frame.draw(
x=pl.food.x, y=pl.food.y,
value=FOOD
)
frame.show()
2022-10-27 00:29:36 +03:00
print(f"Score: {pl.score}")