Minor changes

This commit is contained in:
Loic Guegan 2022-11-01 09:23:24 +01:00
parent 73bd3decdc
commit 368bf244a8

View file

@ -9,16 +9,21 @@ class Snake:
self.grid_height=grid_height
self.grid_pts=grid_pts
self.margin=margin
self.fps=fps
self.snake=[(0,0)]*length
self.direction=3 # Like clock (12=up, 3=right, 6=bottom, 9=left)
self.new_apple()
self.default_length=length
self.attempt=0
self.fps=fps
pygame.init()
self.font=pygame.font.SysFont(pygame.font.get_default_font(), int(self.margin/2))
self.font_small=pygame.font.SysFont(pygame.font.get_default_font(), int(self.margin/2.5))
self.screen=pygame.display.set_mode((grid_width*grid_pts,grid_height*grid_pts+margin))
def new_game(self):
self.snake=[(0,0)]*self.default_length
self.direction=3 # Like clock (12=up, 3=right, 6=bottom, 9=left)
self.new_apple()
self.score=0
self.attempt+=1
def draw_pts(self,x,y,color=(255,255,255)):
rect=pygame.Rect(self.grid_pts*x, self.grid_pts*y+self.margin, self.grid_pts, self.grid_pts)
pygame.draw.rect(self.screen,color,rect, 0)
@ -73,10 +78,8 @@ class Snake:
def run(self):
clock = pygame.time.Clock()
self.direction=6
ignore_has_loose=True
self.score=0
self.attempt+=1
self.new_game()
while True:
self.screen.fill((0,0,0))
self.draw_snake()
@ -116,4 +119,5 @@ class Snake:
game=Snake()
game.run()
for i in range(0,10):
game.run()