pythonweb开发项目教程Flask版,python web和java web区别

大家好,给大家分享一下pythonweb企业级项目开发教程答案,很多人还不知道这一点。下面详细解释一下。现在让我们来看看!

粉丝疑问:为什么要建资源群?

因为资料都保存在网盘里,但是好多资料刚分享出来,链接就失效了,导致很多人没有GPT CSDN到资源,所以露露创建了一个qq交流群,方便大家保存学习资源宿迁趣品网络

文件目录

精心收集了的python电子书、知识点笔记、项目源码等等,今天一次性送给大家

资源干货不定时更新~

【项目:双人对战版中国象棋】:

效果图展示:

部分代码(在下面)

def main():`    `# 初始化pygame`    `()`    `# 创建用来显示画面的对象(理解为相框)`    `screen = pygame.display.set_mode((750, 667))`    `# 游戏背景图片`    `background_img = ("")`    `# 游戏棋盘`    `# chessboard_img = ("")`    `# 创建棋盘对象`    `chessboard = ChessBoard(screen)`    `# 创建计时器`    `clock = .Clock()`    `# 创建游戏对象(像当前走棋方、游戏是否结束等都封装到这个对象中)`    `game = Game(screen, chessboard)``   `    `# 主循环`    `while True:`        `# 事件检测(例如点击了键盘、鼠标等)`        `for event in ():`            `if  == :`                `()`                `()  # 退出程序``   `            `# 如果游戏没有获胜方,则游戏继续,否则一直显示"获胜"`            `if not game.show_win:`                `# 检测是否点击了"可落子"对象`                `clicked_dot = Dot.click()`                `if clicked_dot:`                    `chessboard.move_chess(, )`                    `# 清理「点击对象」、「可落子位置对象」`                    `Dot.clean_last_position()`                    `ClickBox.clean()`                    `# 检测落子后,是否产生了"将军"功能`                    `if chessboard.judge_attack_general(game.get_player()):`                        `print("将军....")`                        `# 检测对方是否可以挽救棋局,如果能挽救,就显示"将军",否则显示"胜利"`                        `if chessboard.judge_win(game.get_player()):`                            `print("获胜...")`                            `game.set_win(game.get_player())`                        `else:`                            `# 如果攻击到对方,则标记显示"将军"效果`                            `game.set_attack()`                    `# 落子之后,交换走棋方`                    `game.exchange()`                    `# 退出for,以便不让本次的鼠标点击串联到点击棋子`                    `break``   `                `# 检查是否点击了棋子`                `# clicked_chess = Chess.get_clicked_chess(chessboard)`                `clicked_chess = Chess.get_clicked_chess(game.get_player(), chessboard)`                `if clicked_chess:`                    `# 创建选中棋子对象`                    `ClickBox(screen, , )`                    `# 清除之前的所有的可以落子对象`                    `Dot.clean_last_position()`                    `# 计算当前被点击的棋子可以落子的位置`                    `put_down_chess_pos = chessboard.get_put_down_postion(clicked_chess)`                    `# 根据当前被点击的棋子创建可以落子的对象`                    `Dot.create_nums_dot(screen, put_down_chess_pos)

【项目:黄金矿工】:

效果图展示:

部分代码:

# 窗口设置``()``pygame.display.set_caption("黄金矿工")``screen_size = (800, 600)``screen = pygame.display.set_mode(screen_size)``backcolour = (255, 255, 255)``(backcolour)``FPS = 60``fclock = .Clock()``   ``# 图标初始化``hook = Hook()``man = mod.Matchman( - 80,  + .width / 2 - 50)``   ``# 创建精灵组,在显示开始游戏界面的时候用来让用户点击按钮``news_group = pygame.sprite.Group()``# 创建3个按钮(开始画面时要显示的按钮)``for i in range(3):`    `(mod.Button(i))``   ``screens = 0``goals = [100, 150, 300]``time_limited = [20, 30, 20]``   ``# 积分``scores = mod.Scores(0)``   ``# 播放背景音乐``()``bgm = pygame.mixer.Sound("")``()``   ``clock = .Clock()

【项目:九宫格拼图】:

效果图展示:

部分代码:

# 初始化``()``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:`      `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)`    `if  == MOUSEBUTTONDOWN and event.button == 1:`      `x, y = pygame.mouse.get_pos()`      `col = int(x / cellWidth)`      `row = int(y / cellHeight)`      `index = col + row*VHNUMS`      `if (index == blackCell-1 or index == blackCell+1 or index == blackCell-VHNUMS or index == blackCell+VHNUMS):`        `gameBoard[blackCell], gameBoard[index] = gameBoard[index], gameBoard[blackCell]`        `blackCell = index`  `if (isFinished(gameBoard, blackCell)):`    `gameBoard[blackCell] = CELLNUMS-1`    `finish = True`  `(BACKGROUNDCOLOR)`  `for i in range(CELLNUMS):`    `rowDst = int(i / VHNUMS)`    `colDst = int(i % VHNUMS)`    `rectDst = (colDst*cellWidth, rowDst*cellHeight, cellWidth, cellHeight)`    `if gameBoard[i] == -1:`      `continue`    `rowArea = int(gameBoard[i] / VHNUMS)`    `colArea = int(gameBoard[i] % VHNUMS)`    `rectArea = (colArea*cellWidth, rowArea*cellHeight, cellWidth, cellHeight)`    `(gameImage, rectDst, rectArea)`  `for i in range(VHNUMS+1):`    `(windowSurface, BLACK, (i*cellWidth, 0), (i*cellWidth, gameRect.height))`  `for i in range(VHNUMS+1):`    `(windowSurface, BLACK, (0, i*cellHeight), (gameRect.width, i*cellHeight))`  `pygame.display.update()`  `(FPS)

【项目:球球大作战】:

效果图展示:

部分代码:

#定义球球类``class Ball():`    `def __init__(self,xpos,ypos,weight,color): #定义球的x,y,重量,颜色`        ` = xpos`        ` = ypos`        `self.radius = weightToRadius(weight)`        `self.weight = weight`        `self.speed = weightToSpeed(weight)`        `self.color = color``   `    `def move(self,direction):  #小球移动`        `rec = (-HALFWWIDTH, -HALFWHEIGHT, WORLDWIDTH, WORLDHEIGHT)`        `if direction == UP:`            `if  <  - self.radius: #限制在上边界以下`                ` -= int(self.speed//20)`        `elif direction == DOWN:`            `if rec.bottom >  +self.radius:`                ` += int(self.speed//20)`        `elif direction == RIGHT:`            `if rec.right >  + self.radius:`                ` += int(self.speed//20)`        `elif direction == LEFT:`            `if  <  - self.radius:`                ` -= int(self.speed//20)``   `    `def split(self,direction): #分裂小球函数`        `newweight = math.floor((self.weight // 2) * SPLITBASE)`        `newball = Ball(, , newweight, self.color)`        `if direction == UP:`            `#分裂流畅动画`            `for i in range(10):`                ` -= round(0.2*self.radius)`                `drawBall(newball)`                `pygame.display.update()`        `elif direction == DOWN:`            `for i in range(10):`                ` += round(0.2*self.radius)`                `drawBall(newball)`                `pygame.display.update()`        `elif direction == LEFT:`            `for i in range(10):`                ` -= round(0.2*self.radius)`                `drawBall(newball)`                `pygame.display.update()`        `elif direction == RIGHT:`            `for i in range(10):`                ` += round(0.2*self.radius)`                `drawBall(newball)`                `pygame.display.update()`        `self.setWeight(newweight) #分裂完后设置球的重量`        `selfBalls.append(newball)``   `    `def setWeight(self,newweight):`        `self.weight = newweight`        `self.speed = weightToSpeed(newweight)`        `self.radius = weightToRadius(newweight)``   `    `def eatFood(self): #吃食物`        `global foodlist`        `selfworldx = `        `selfworldy = `        `for food in foodlist:`            `distance = (()*()+()*())`            `if distance < self.radius:`                `self.setWeight(self.weight+food.weight)`                `foodlist.remove(food)``   

【项目:扫雷】:

效果图展示:

部分代码:

# 地雷数量``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"):`                    `set_nums_blank(row + i, col + j, board_list)`    `else:`        `board_list[row][col]['opened'] = True`        `board_list[row][col]["opened_num"] = mine_num`        `board_list[row][col]["closed_num"] = "空"``   ``   ``def get_mine_flag_num(board_list):`    `"""`    `计算还剩多少颗雷`    `"""`    `num = 0`    `for line in board_list:`        `for num_dict in line:`            `if ("closed_num") == "雷标记":`                `num += 1``   `    `return num``   

【项目:贪吃蛇】:

效果图展示:

部分代码:

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:`        `(0)`    `if x < 0 or x > 630 or y < 0 or y > 450:`        `exit()`    `# 将背景图画上去`    `(background, (0, 0))`    `# 将贪吃蛇的头画上去`    `(snake_head, position[-1])  #`    `# 将贪吃蛇的身体画上去`    `for i in range(len(position)-1):`        `(body, position[i])`    `# 将果实画上去`    `(food, (apple_x, apple_y))`    `# 绘制分数`    `scoreSurf = basic_font.render('Score: '+str(score), True, (0, 0, 0))`    `scoreRect = scoreSurf.get_rect()`    `scoreRect.topleft = (660 - 120, 10)`    `(scoreSurf, scoreRect)`    `# 刷新画面`    `pygame.display.update()`    `(3)

【项目:推箱子】:

效果图展示:

部分代码:

'''游戏界面'''``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))`        `for elem in elems:`            `(self.game_surface)`        `(self.game_surface, dest=(self.scroll_x, self.scroll_y))`    `'''因为游戏界面面积>游戏窗口界面, 所以需要根据人物位置滚动'''`    `def scroll(self):`        `x, y = .center`        `width = self.game_surface.get_rect().w`        `height = self.game_surface.get_rect().h`        `if (x + ('WIDTH') // 2) > ('WIDTH'):`            `if -1 * self.scroll_x + ('WIDTH') < width:`                `self.scroll_x -= 2`        `elif (x + ('WIDTH') // 2) > 0:`            `if self.scroll_x < 0:`                `self.scroll_x += 2`        `if (y + ('HEIGHT') // 2) > ('HEIGHT'):`            `if -1 * self.scroll_y + ('HEIGHT') < height:`                `self.scroll_y -= 2`        `elif (y + 250) > 0:`            `if self.scroll_y < 0:`                `self.scroll_y += 2

点击下方GPT CSDN前往获取

CSDN大礼包:《Python入门&进阶学习资源包》GPT CSDN分享

👉Python实战案例👈

光学理论是没用的,要学会跟着一起敲,要动手实操,才能将自己的所学运用到实际当中去,这时候可以搞点实战案例来学习。

👉Python书籍和视频合集👈

观看零基础学习视频,看视频学习是最快捷也是最有效果的方式,跟着视频中老师的思路,从基础到深入,还是很容易入门的。

👉PythonGPT CSDN创收路线👈

这些资料都是非常不错的,朋友们如果有需要《Python学习路线&GPT CSDN》,点击下方GPT CSDN前往获取

CSDN大礼包:《Python入门&进阶学习资源包》GPT CSDN分享

本文转自网络,如有侵权,请联系删除。

  • 5
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值