python学生管理系统实训

大家好,本文将围绕python编写学生管理系统,用gui做ui展开说明,python学生管理系统部署说明书是一个很多人都想弄明白的事情,想搞清楚python学生管理系统设计报告需要先了解以下几个事情。

本篇文章给大家谈谈20行python代码的入门级小游戏,以及python游戏编程入门游戏代码,希望对各位有所帮助,不要忘了收藏本站喔python源码库

【项目:九宫格拼图】:

效果图展示:

部分代码:


# 初始化
()
mainClock = .Clock()
# 加载图片
gameImage = ('')
gameRect = gameImage.get_rect()
# 设置窗口
windowSurface = pygame.display.set_mode((gameRect.width, gameRect.height))
pygame.display.set_caption('拼图')
cellWidth = int(gameRect.width / VHNUMS)
cellHeight = int(gameRect.height / VHNUMS)
finish = False
gameBoard, blackCell = newGameBoard()
# 游戏主循环
while True:
  for event in ():
    if  == QUIT:
      terminate()
    if finish:
                                               老师 WX:tz16494
      continue
    if  == KEYDOWN:
      if  == K_LEFT or  == ord('a'):
        blackCell = moveLeft(gameBoard, blackCell)
      if  == K_RIGHT or  == ord('d'):
        blackCell = moveRight(gameBoard, blackCell)
      if  == K_UP or  == ord('w'):
        blackCell = moveUp(gameBoard, blackCell)
      if  == K_DOWN or  == ord('s'):
        blackCell = moveDown(gameBoard, blackCell)

效果图展示:

部分代码:

# 地雷数量
MINE_COUNT = 99

# 每个方格的大小(宽、高都为20)
SIZE = 20
# 方格的行数
BLOCK_ROW_NUM = 16
# 方格的列数
BLOCK_COL_NUM = 30
# 游戏窗口的宽、高
SCREEN_WIDTH, SCREEN_HEIGHT = BLOCK_COL_NUM * SIZE, (BLOCK_ROW_NUM + 2) * SIZE


def judge_win(board_list):
    """
    判断是否获胜
    只要有1个标记为地雷但实际不是地雷的方格,就表示未获胜,否则获胜
    """
    for line in board_list:
        for num_dict in line:
            if ("opened_num") == "雷" and ("closed_num") != "雷标记":
                return False
    else:
        return True


def set_nums_blank(row, col, board_list):
    """
    判断当前位置的周边位置是否为空,如果是则继续判断,
    最终能够实现点击一个空位置后连续的空位置都能够显示出来
    """
    mine_num = get_mine_num(row, col, board_list)
    print("row=%d, col=%d, mine_num=%d" % (row, col, mine_num))
    if mine_num == 0:
        board_list[row][col]['opened'] = True
        board_list[row][col]["opened_num"] = 0
        board_list[row][col]["closed_num"] = "空"
        # 判断对角是否是数字
        for i, j in [(-1, -1), (1, 1), (1, -1), (-1, 1)]:
            if 0 <= row + i <= 15 and 0 <= col + j <= 29:
                mine_num = get_mine_num(row + i, col + j, board_list)
                if mine_num:
                    board_list[row + i][col + j]['opened'] = True
                    board_list[row + i][col + j]["opened_num"] = mine_num
                    board_list[row + i][col + j]["closed_num"] = "空"

        # 判断剩下4个位置是否是也是0,即空
        for i, j in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
            if 0 <= row + i <= 15 and 0 <= col + j <= 29:
                if not board_list[row + i][col + j].get("opened"):

【项目:贪吃蛇】:

效果图展示:

部分代码:



while True:
    for event in ():
        if  == :
            # 接收到退出事件后退出程序
            exit()
        elif  == locals.KEYDOWN:
            if  == locals.K_RIGHT and setheading != "left":
                setheading = 'right'
                snake_head = right
            elif  == locals.K_LEFT and setheading != "right":
                setheading = 'left'
                snake_head = left
            elif  == locals.K_UP and setheading != "down":
                setheading = 'up'
                snake_head = up
            elif  == locals.K_DOWN and setheading != "up":
                setheading = 'down'
                snake_head = down

    # 设置贪吃蛇的头部坐标
    if setheading == "right":
        x += 30   #
    elif setheading == "left":
        x -= 30
    elif setheading == "up":
        y -= 30
    else:
        y += 30
    position.append((x, y))
    if x == apple_x and y == apple_y:
        # 随机生成一个格子的左上角坐标作为苹果(食物)的坐标
        num1 = random.randint(1, 22)
        num2 = random.randint(1, 16)
        apple_x = 30 * num1 - 30  # 苹果的x坐标
        apple_y = 30 * num2 - 30  # 苹果的y坐标
        score += 10
    else:

【项目:推箱子】:

效果图展示:

部分代码:

'''游戏界面'''
class gameInterface():
    def __init__(self, screen):
        self.screen = screen
        self.levels_path = ('levels_path')
        self.initGame()
    '''导入关卡地图'''
    def loadLevel(self, game_level):
        with open((self.levels_path, game_level), 'r') as f:
            lines = f.readlines()
        # 游戏地图
        self.game_map = gameMap(max([len(line) for line in lines]) - 1, len(lines))
        # 游戏surface
        height = ('block_size') * self.game_map.num_rows
        width = ('block_size') * self.game_map.num_cols
        self.game_surface = pygame.Surface((width, height))
        (('bg_color'))
        self.game_surface_blank = ()
        for row, elems in enumerate(lines):
            for col, elem in enumerate(elems):
                if elem == 'p':
                    self.player = pusherSprite(col, row)
                elif elem == '*':
                    self.game_map.addElement('wall', col, row)
                elif elem == '#':
                    self.game_map.addElement('box', col, row)
                elif elem == 'o':
                    self.game_map.addElement('target', col, row)
    '''游戏初始化'''
    def initGame(self):
        self.scroll_x = 0
        self.scroll_y = 0
    '''将游戏界面画出来'''
    def draw(self, *elems):
        self.scroll()
        (self.game_surface_blank, dest=(0, 0))
       


原文地址1:https://blog.csdn.net/www55597/article/details/135664536
参考资料:python中用turtle画一个圆形 https://blog.csdn.net/SXIAOYAN_/article/details/140061099

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值