summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2022-11-01 08:21:45 +0100
committerLoic Guegan <manzerbredes@mailbox.org>2022-11-01 08:21:45 +0100
commitd2d29f4da3acb0d3cbaa37baaef95930bf96e5de (patch)
tree549e688889fda2fe6fa2f0231da7c868338cc4da
parent214608ab3aa6d8605ea9e3e14c589d4608e71bbe (diff)
Minor changes
-rwxr-xr-xsnake/snake.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/snake/snake.py b/snake/snake.py
index 0248204..dd6c16b 100755
--- a/snake/snake.py
+++ b/snake/snake.py
@@ -14,6 +14,7 @@ class Snake:
self.direction=3 # Like clock (12=up, 3=right, 6=bottom, 9=left)
self.new_apple()
pygame.init()
+ self.font=pygame.font.SysFont(pygame.font.get_default_font(), int(self.margin/2))
self.screen=pygame.display.set_mode((grid_width*grid_pts,grid_height*grid_pts+margin))
def draw_pts(self,x,y,color=(255,255,255)):
@@ -23,7 +24,8 @@ class Snake:
def draw_infos(self,color=(255,255,255),thickness=5):
rect=pygame.Rect(0, self.margin-thickness, self.grid_width*self.grid_pts, thickness)
pygame.draw.rect(self.screen,color,rect, 0)
-
+ text = self.font.render('Score '+str(self.score)+" Length "+str(len(self.snake)), True, color)
+ self.screen.blit(text, dest=(self.grid_width*self.grid_pts/3.5,self.margin/3.5))
def new_apple(self):
self.apple=(random.randint(0,self.grid_width),random.randint(0,self.grid_height))
@@ -65,6 +67,7 @@ class Snake:
clock = pygame.time.Clock()
self.direction=6
ignore_has_loose=True
+ self.score=0
while True:
self.screen.fill((0,0,0))
self.draw_snake()
@@ -98,6 +101,7 @@ class Snake:
if self.apple==self.snake[0]:
self.snake.append(self.snake[len(self.snake)-1])
self.new_apple()
+ self.score+=1
pygame.display.flip()
clock.tick(self.fps)