<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12


      import pygame
      import sys
      import random
      import math
      from pygame.math import Vector2

      pygame.init()

      CELL_SIZE = 30
      GRID_WIDTH = 20
      GRID_HEIGHT = 15
      SCREEN_WIDTH = CELL_SIZE * GRID_WIDTH
      SCREEN_HEIGHT = CELL_SIZE * GRID_HEIGHT
      FPS = 60

      BACKGROUND = (15, 15, 30)
      GRID_COLOR = (30, 30, 50)
      SNAKE_HEAD = (50, 205, 50)
      SNAKE_BODY = (40, 180, 40)
      FOOD_COLOR = (220, 60, 60)
      TEXT_COLOR = (220, 220, 220)
      UI_BACKGROUND = (20, 20, 40, 200)
      UI_BORDER = (70, 130, 200)

      screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
      pygame.display.set_caption("Python貪吃蛇")
      clock = pygame.time.Clock()

      try:
      font_large = pygame.font.Font(None, 48)
      font_medium = pygame.font.Font(None, 36)
      font_small = pygame.font.Font(None, 28)
      except:

      font_large = pygame.font.SysFont(None, 48)
      font_medium = pygame.font.SysFont(None, 36)
      font_small = pygame.font.SysFont(None, 28)
      

      class Snake:
      def init(self):
      self.reset()

      def reset(self):
          
          self.body = [Vector2(5, 7), Vector2(4, 7), Vector2(3, 7)]
          self.direction = Vector2(1, 0)
          self.new_direction = Vector2(1, 0)
          self.grow = False
          self.speed = 8  
          self.move_counter = 0
          
      def update(self):
          
          if self.new_direction != -self.direction:
              self.direction = self.new_direction
          
          
          self.move_counter += self.speed / FPS
          if self.move_counter >= 1:
              self.move_counter -= 1
              
              
              head = self.body[0] + self.direction
              self.body.insert(0, head)
              
              if not self.grow:
                  self.body.pop()
              else:
                  self.grow = False
                  
      def draw(self, surface):
          
          for i, segment in enumerate(self.body):
              
              if i == 0:
                  color = SNAKE_HEAD
              
              else:
                  color = SNAKE_BODY
              
              
              rect = pygame.Rect(segment.x * CELL_SIZE, segment.y * CELL_SIZE, CELL_SIZE, CELL_SIZE)
              pygame.draw.rect(surface, color, rect, 0, 7)
              
              
              if i > 0:
                  prev = self.body[i-1]
                  
                  if prev.x == segment.x:  
                      if prev.y < segment.y:  
                          pygame.draw.rect(surface, color, 
                                         (segment.x * CELL_SIZE + 3, 
                                          segment.y * CELL_SIZE - 3, 
                                          CELL_SIZE - 6, 6))
                      else:  
                          pygame.draw.rect(surface, color, 
                                         (segment.x * CELL_SIZE + 3, 
                                          segment.y * CELL_SIZE + CELL_SIZE - 3, 
                                          CELL_SIZE - 6, 6))
                  else:  
                      if prev.x < segment.x:  
                          pygame.draw.rect(surface, color, 
                                         (segment.x * CELL_SIZE - 3, 
                                          segment.y * CELL_SIZE + 3, 
                                          6, CELL_SIZE - 6))
                      else:  
                          pygame.draw.rect(surface, color, 
                                         (segment.x * CELL_SIZE + CELL_SIZE - 3, 
                                          segment.y * CELL_SIZE + 3, 
                                          6, CELL_SIZE - 6))
          
          
          eye_size = CELL_SIZE // 5
          
          if self.direction == Vector2(1, 0):  
              left_eye = (self.body[0].x * CELL_SIZE + CELL_SIZE - eye_size - 2, 
                          self.body[0].y * CELL_SIZE + eye_size + 2)
              right_eye = (self.body[0].x * CELL_SIZE + CELL_SIZE - eye_size - 2, 
                           self.body[0].y * CELL_SIZE + CELL_SIZE - eye_size*2 - 2)
          elif self.direction == Vector2(-1, 0):  
              left_eye = (self.body[0].x * CELL_SIZE + 2, 
                          self.body[0].y * CELL_SIZE + eye_size + 2)
              right_eye = (self.body[0].x * CELL_SIZE + 2, 
                           self.body[0].y * CELL_SIZE + CELL_SIZE - eye_size*2 - 2)
          elif self.direction == Vector2(0, 1):  
              left_eye = (self.body[0].x * CELL_SIZE + eye_size + 2, 
                          self.body[0].y * CELL_SIZE + CELL_SIZE - eye_size - 2)
              right_eye = (self.body[0].x * CELL_SIZE + CELL_SIZE - eye_size*2 - 2, 
                           self.body[0].y * CELL_SIZE + CELL_SIZE - eye_size - 2)
          else:  
              left_eye = (self.body[0].x * CELL_SIZE + eye_size + 2, 
                          self.body[0].y * CELL_SIZE + 2)
              right_eye = (self.body[0].x * CELL_SIZE + CELL_SIZE - eye_size*2 - 2, 
                           self.body[0].y * CELL_SIZE + 2)
          
          pygame.draw.circle(surface, (0, 0, 0), left_eye, eye_size)
          pygame.draw.circle(surface, (0, 0, 0), right_eye, eye_size)
      

      class Food:
      def init(self, snake):
      self.position = self.generate_position(snake)

      def generate_position(self, snake):
          
          while True:
              x = random.randint(0, GRID_WIDTH - 1)
              y = random.randint(0, GRID_HEIGHT - 1)
              position = Vector2(x, y)
              
              if position not in snake.body:
                  return position
                  
      def draw(self, surface):
          
          center = (self.position.x * CELL_SIZE + CELL_SIZE // 2,
                    self.position.y * CELL_SIZE + CELL_SIZE // 2)
          radius = CELL_SIZE // 2 - 2
          
          
          pygame.draw.circle(surface, FOOD_COLOR, center, radius)
          
        
          leaf_points = [
              (center[0] - radius//2, center[1] - radius),
              (center[0] + radius//2, center[1] - radius),
              (center[0], center[1] - radius - radius//2)
          ]
          pygame.draw.polygon(surface, (50, 180, 50), leaf_points)
          
          
          pygame.draw.line(surface, (100, 70, 30), 
                           (center[0], center[1] - radius),
                           (center[0], center[1] - radius - radius//3), 2)
      

      class Game:
      def init(self):
      self.snake = Snake()
      self.food = Food(self.snake)
      self.score = 0
      self.game_over = False
      self.paused = False
      self.special_food_timer = 0
      self.special_food = None
      self.special_food_active = False

      def update(self):
          if self.game_over or self.paused:
              return
              
          self.snake.update()
          
          
          if self.snake.body[0] == self.food.position:
              self.snake.grow = True
              self.food = Food(self.snake)
              self.score += 10
              
             
              if random.random() < 0.3 and self.snake.speed < 15:
                  self.snake.speed += 0.5
          
          
          head = self.snake.body[0]
          if (head.x < 0 or head.x >= GRID_WIDTH or 
              head.y < 0 or head.y >= GRID_HEIGHT or 
              head in self.snake.body[1:]):
              self.game_over = True
              
          
          if self.special_food_active:
              self.special_food_timer -= 1
              if self.special_food_timer <= 0:
                  self.special_food_active = False
                  
              if self.snake.body[0] == self.special_food:
                  self.snake.grow = True
                  self.special_food_active = False
                  self.score += 30
                  
         
          if not self.special_food_active and random.random() < 0.005:
              self.special_food = Food(self.snake).position
              self.special_food_active = True
              self.special_food_timer = FPS * 5  
      def draw(self, surface):
          
          for x in range(GRID_WIDTH):
              for y in range(GRID_HEIGHT):
                  rect = pygame.Rect(x * CELL_SIZE, y * CELL_SIZE, CELL_SIZE, CELL_SIZE)
                  pygame.draw.rect(surface, GRID_COLOR, rect, 1)
      
          
          self.food.draw(surface)
          
          
          if self.special_food_active:
              center = (self.special_food.x * CELL_SIZE + CELL_SIZE // 2,
                        self.special_food.y * CELL_SIZE + CELL_SIZE // 2)
              radius = CELL_SIZE // 3
              
              
              if pygame.time.get_ticks() % 500 < 250:
                  pygame.draw.circle(surface, (255, 215, 0), center, radius)
                  pygame.draw.circle(surface, (255, 255, 100), center, radius - 2)
          
          
          self.snake.draw(surface)
          
          
          score_text = font_medium.render(f"分數: {self.score}", True, TEXT_COLOR)
          surface.blit(score_text, (10, 10))
          
          
          speed_text = font_small.render(f"速度: {self.snake.speed:.1f}", True, TEXT_COLOR)
          surface.blit(speed_text, (SCREEN_WIDTH - 120, 10))
          
          
          if self.game_over:
              self.draw_game_over(surface)
              
          
          if self.paused:
              self.draw_paused(surface)
      
      def draw_game_over(self, surface):
          
          overlay = pygame.Surface((SCREEN_WIDTH, SCREEN_HEIGHT), pygame.SRCALPHA)
          overlay.fill((0, 0, 0, 180))
          surface.blit(overlay, (0, 0))
          
          
          game_over_text = font_large.render("游戲結束!", True, (220, 60, 60))
          score_text = font_medium.render(f"最終分數: {self.score}", True, TEXT_COLOR)
          restart_text = font_small.render("按R鍵重新開始", True, TEXT_COLOR)
          
          surface.blit(game_over_text, (SCREEN_WIDTH//2 - game_over_text.get_width()//2, 
                                       SCREEN_HEIGHT//2 - 60))
          surface.blit(score_text, (SCREEN_WIDTH//2 - score_text.get_width()//2, 
                                   SCREEN_HEIGHT//2))
          surface.blit(restart_text, (SCREEN_WIDTH//2 - restart_text.get_width()//2, 
                                    SCREEN_HEIGHT//2 + 50))
      
      def draw_paused(self, surface):
          
          overlay = pygame.Surface((SCREEN_WIDTH, SCREEN_HEIGHT), pygame.SRCALPHA)
          overlay.fill((0, 0, 0, 120))
          surface.blit(overlay, (0, 0))
          
          
          pause_text = font_large.render("游戲暫停", True, (70, 130, 200))
          continue_text = font_medium.render("按P鍵繼續", True, TEXT_COLOR)
          
          surface.blit(pause_text, (SCREEN_WIDTH//2 - pause_text.get_width()//2, 
                                  SCREEN_HEIGHT//2 - 30))
          surface.blit(continue_text, (SCREEN_WIDTH//2 - continue_text.get_width()//2, 
                                      SCREEN_HEIGHT//2 + 30))
      
      def reset(self):
          self.snake.reset()
          self.food = Food(self.snake)
          self.score = 0
          self.game_over = False
          self.paused = False
          self.special_food_active = False
      

      game = Game()

      while True:

      for event in pygame.event.get():
          if event.type == pygame.QUIT:
              pygame.quit()
              sys.exit()
              
          if event.type == pygame.KEYDOWN:
              if not game.game_over:
                  
                  if event.key == pygame.K_UP:
                      game.snake.new_direction = Vector2(0, -1)
                  elif event.key == pygame.K_DOWN:
                      game.snake.new_direction = Vector2(0, 1)
                  elif event.key == pygame.K_LEFT:
                      game.snake.new_direction = Vector2(-1, 0)
                  elif event.key == pygame.K_RIGHT:
                      game.snake.new_direction = Vector2(1, 0)
                      
                  
                  elif event.key == pygame.K_p:
                      game.paused = not game.paused
              
              
              if event.key == pygame.K_r:
                  game.reset()
                  
              
              if event.key == pygame.K_ESCAPE:
                  pygame.quit()
                  sys.exit()
      
      
      game.update()
      
      
      screen.fill(BACKGROUND)
      game.draw(screen)
      
      pygame.draw.rect(screen, UI_BORDER, (0, 0, SCREEN_WIDTH, SCREEN_HEIGHT), 3)
      
      
      title_text = font_small.render("Python貪吃蛇", True, (100, 180, 255))
      screen.blit(title_text, (SCREEN_WIDTH // 2 - title_text.get_width() // 2, 
                             SCREEN_HEIGHT - 30))
      
      
      if not game.game_over and not game.paused:
          controls_text = font_small.render("方向鍵移動 | P暫停 | R重開 | ESC退出", True, (180, 180, 200))
          screen.blit(controls_text, (SCREEN_WIDTH // 2 - controls_text.get_width() // 2, 
                                    SCREEN_HEIGHT - 60))
      
      
      pygame.display.flip()
      
      
      clock.tick(FPS)
      
      posted on 2025-06-22 01:40  湯圓233  閱讀(12)  評論(0)    收藏  舉報

      主站蜘蛛池模板: 日韩无人区码卡1卡2卡| 国产福利微视频一区二区| 亚洲精品男男一区二区| 国产福利萌白酱在线观看视频| 国产精品久久久久av福利动漫| 麻豆国产传媒精品视频| av无码小缝喷白浆在线观看| 久久天天躁夜夜躁狠狠| av在线播放国产一区| 亚洲暴爽av人人爽日日碰| 2019国产精品青青草原| 国产91久久精品一区二区| 日韩狼人精品在线观看| 国产999精品2卡3卡4卡| 欧美牲交a欧美牲交aⅴ一| 又黄又无遮挡AAAAA毛片| 亚洲人成网站18禁止无码| 国产精品一区久久人人爽| 特黄少妇60分钟在线观看播放| 欧美成人无码a区视频在线观看| 国产成年码av片在线观看| 中文字幕日韩人妻一区| 久久精品99国产国产精| 夜夜嗨久久人成在日日夜夜| 四虎国产精品成人免费久久| 国产成人午夜福利高清在线观看| 乡城县| 国产精品人成视频免| 久久av无码精品人妻出轨| 精品国产综合成人亚洲区| 中文无码热在线视频| 激情综合网激情综合网五月| 黄页网站在线观看免费视频| 在线 | 国产精品99传媒a | 精品国产一区二区三区蜜臀| 国产精品国产亚洲看不卡| 欧美日韩v| 色欧美片视频在线观看| 国产精品视频免费一区二区三区 | 91中文字幕一区在线| 亚洲欧美日韩一区在线观看|