Python:游戏:扫雷(附源码)

  import sys

  import time

  from enum import Enum

  import pygame

  from pygame.locals import *

  from mineblock import *

  # 游戏屏幕的宽

  SCREEN_WIDTH=BLOCK_WIDTH * SIZE

  # 游戏屏幕的高

  SCREEN_HEIGHT=(BLOCK_HEIGHT + 2) * SIZE

  class GameStatus(Enum):

  readied =1,

  started =2,

  over =3,

  win =4

  def print_text(screen, font, x, y, text, fcolor=(255, 255, 255)):

  imgText = font.render(text, True, fcolor)

  screen.blit(imgText, (x, y))

  def main():

  pygame.init()

  screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))

  pygame.display.set_caption('365bet')

  font1 =pygame.font.Font('resources/a.TTF', SIZE * 2) # 得分的字体

  fwidth, fheight=font1.size('999')

  red =(200, 40, 40)

  # 加载资本图片,因为资本文件大年夜小纷歧,所以做了一致的缩放处理

  img0=pygame.image.load('resources/0.bmp').convert()

  img0 = pygame.transform.smoothscale(img0, (SIZE, SIZE))

  img1 =pygame.image.load('resources/1.bmp').convert()

  img1 = pygame.transform.smoothscale(img1, (SIZE, SIZE))

  img2 =pygame.image.load('resources/2.bmp').convert()

  img2 = pygame.transform.smoothscale(img2, (SIZE, SIZE))

  img3 =pygame.image.load('resources/3.bmp').convert()

  img3 = pygame.transform.smoothscale(img3, (SIZE, SIZE))

  img4 =pygame.image.load('resources/4.bmp').convert()

  img4 = pygame.transform.smoothscale(img4, (SIZE, SIZE))

  img5 =pygame.image.load('resources/5.bmp').convert()

  img5 = pygame.transform.smoothscale(img5, (SIZE, SIZE))

  img6 =pygame.image.load('resources/6.bmp').convert()

  img6 = pygame.transform.smoothscale(img6, (SIZE, SIZE))

  img7 =pygame.image.load('resources/7.bmp').convert()

  img7 = pygame.transform.smoothscale(img7, (SIZE, SIZE))

  img8 =pygame.image.load('resources/8.bmp').convert()

  img8 = pygame.transform.smoothscale(img8, (SIZE, SIZE))

  img_blank =pygame.image.load('resources/blank.bmp').convert()

  img_blank = pygame.transform.smoothscale(img_blank, (SIZE, SIZE))

  img_flag =pygame.image.load('resources/flag.bmp').convert()

  img_flag = pygame.transform.smoothscale(img_flag, (SIZE, SIZE))

  img_ask =pygame.image.load('resources/ask.bmp').convert()

  img_ask = pygame.transform.smoothscale(img_ask, (SIZE, SIZE))

  img_mine =pygame.image.load('resources/mine.bmp').convert()

  img_mine = pygame.transform.smoothscale(img_mine, (SIZE, SIZE))