Pygame坦克大战游戏开发实战详解代码

导语

哈喽!哈喽——我是木木子

今天来升级下之前写的坦克大战游戏嘛,哈哈哈 其实也不算是修改,就是稍微的调试一下!​​

因为之前写的界面都是英文的 ,有的小伙伴儿英文一点儿都不会的可能看着别扭,今天来一款中

文版的给大家嘛!

俗话说的好:“雨露均沾”。哈哈哈.jpg

小简介:

《坦克大战》,1985年由日本开发商南梦宫(Namco)开发,是第一款可以双打的红白机游戏。

当时使用的还是小霸王。

很多小朋友以学习的名义买了以后偷偷打的打游戏还被家长发现了有 没得!

《坦克大战》红白机原版共有35关,每一关的地形和障碍都不同。图为原版坦克大战最后一关,你

有没有打通关过?(小声bb,我这个游戏水平可能达不到!)

正文​

1)游戏规则:

游戏过程是这样的,玩家操作坦克消灭电脑控制的坦克,并保护自己基地。基地图标是一只傲娇的张着翅膀的老鹰。小时候自

己失手把飞鹰轰成烧鸡的惨案经常发生。

双打的时候,为了看谁刷得分高,都争着打坦克,大本营的老鹰被烤熟了都不管。。

坦克大战中的宝贝有战车、星星、时钟等,小编当时最喜欢的是时钟,敌不能动我能动的感觉妙极了。图中的坦克图标吃了是

可以加一条命的,当时为了抢宝贝都抢先把队友的坦克打晕。。。

2)环境安装

Python3、Pycharm、Pygame、以及自带或自定义的模块。

pip install +模块名 或pip install -i https://pypi.douban.com/simple/ +模块名

3)代码演示​​

(之前不是写过的嘛,今天的话就是修改下的,这种小游戏代码肯定都很多的,所以这里直接贴主程序了。

需要完整的打包好的代码跟素材哪些的话 直接滴滴我即可或者看我主页左侧哪里有源码基地的哈!)

主程序:

import pygame
from pygame.locals import *
import sys
import scene
import bullet
import food
import tanks
import home

# 开始界面显示
def show_start_interface(screen, width, height):
    tfont = pygame.font.Font('./font/simkai.ttf', width // 4)
    cfont = pygame.font.Font('./font/simkai.ttf', width // 20)
    title = tfont.render(u'坦克大战', True, (255, 0, 0))
    content1 = cfont.render(u'按1键进入单人游戏', True, (0, 244, 222))
    content2 = cfont.render(u'按2键进入双人人游戏', True, (0, 0, 255))
    #显示字体pygame.font.Font.render(text文本, antialias是否抗锯齿, color颜色, background=None)
    trect = title.get_rect()
    # 默认title左上角的坐标是 (0, 0)
    trect.midtop = (width / 2, height / 5)
    crect1 = content1.get_rect()
    crect1.midtop = (width / 2, height / 1.8)
    crect2 = content2.get_rect()
    crect2.midtop = (width / 2, height / 1.6)
    screen.blit(title, trect)
    screen.blit(content1, crect1)
    screen.blit(content2, crect2)
    # 在指定位置绘制指定文字对象
    pygame.display.update()
    # 更新界面
    while True:
        for event in pygame.event.get():
            if event.type == QUIT:
                sys.exit()
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_1:
                    return 1
                if event.key == pygame.K_2:
                    return 2

# 结束界面显示
def show_end_interface(screen, width, height, is_win):
    bg_img = pygame.image.load("./images/others/background.png")
    screen.blit(bg_img, (0, 0))
    if is_win:
        font = pygame.font.Font('./font/simkai.ttf', width // 10)
        content = font.render(u'恭喜通关!', True, (255, 0, 0))
        rect = content.get_rect()
        rect.midtop = (width / 2, height / 2)
        screen.blit(content, rect)
    else:
        fail_img = pygame.image.load("./images/others/gameover.png")
        rect = fail_img.get_rect()
        rect.midtop = (width / 2, height / 2)
        screen.blit(fail_img, rect)
    pygame.display.update()
    while True:
        for event in pygame.event.get():
            if event.type == QUIT:
                sys.exit()

# 关卡切换
def show_switch_stage(screen, width, height, stage):
    bg_img = pygame.image.load("./images/others/background.png")
    screen.blit(bg_img, (0, 0))
    font = pygame.font.Font('./font/simkai.ttf', width // 10)
    content = font.render(u'第%d关' % stage, True, (0, 255, 0))
    rect = content.get_rect()
    rect.midtop = (width / 2, height / 2)
    screen.blit(content, rect)
    pygame.display.update()
    delay_event = pygame.constants.USEREVENT
    pygame.time.set_timer(delay_event, 1000)
    #定时器延时
    while True:
        for event in pygame.event.get():
            if event.type == QUIT:
                sys.exit()
            if event.type == delay_event:
                return

def main():
    pygame.init()
    pygame.mixer.init()
    screen = pygame.display.set_mode((630, 630))
    pygame.display.set_caption('坦克大战')
    bg_img = pygame.image.load('./images/others/background.png')
    # 加载音效
    add_sound = pygame.mixer.Sound("./audios/add.wav")
    add_sound.set_volume(1)
    bang_sound = pygame.mixer.Sound("./audios/bang.wav")
    bang_sound.set_volume(1)
    blast_sound = pygame.mixer.Sound("./audios/blast.wav")
    blast_sound.set_volume(1)
    fire_sound = pygame.mixer.Sound("./audios/fire.wav")
    fire_sound.set_volume(1)
    Gunfire_sound = pygame.mixer.Sound("./audios/Gunfire.wav")
    Gunfire_sound.set_volume(1)
    hit_sound = pygame.mixer.Sound("./audios/hit.wav")
    hit_sound.set_volume(1)
    start_sound = pygame.mixer.Sound("./audios/start.wav")
    start_sound.set_volume(1)
    # 开始界面
    num_player = show_start_interface(screen, 630, 630)
    # 播放游戏开始的音乐
    start_sound.play()
    # 关卡
    stage = 0
    num_stage = 2
    # 游戏是否结束
    is_gameover = False
    # 时钟
    clock = pygame.time.Clock()
    # 主循环
    while not is_gameover:
        # 关卡
        stage += 1
        if stage > num_stage:
            break
        show_switch_stage(screen, 630, 630, stage)
        # 该关卡坦克总数量
        enemytanks_total = min(stage * 18, 80)
        # 场上存在的敌方坦克总数量
        enemytanks_now = 0
        # 场上可以存在的敌方坦克总数量
        enemytanks_now_max = min(max(stage * 2, 4), 8)
        # 精灵组,独立运行的动画组
        tanksGroup = pygame.sprite.Group()
        mytanksGroup = pygame.sprite.Group()
        enemytanksGroup = pygame.sprite.Group()
        bulletsGroup = pygame.sprite.Group()
        mybulletsGroup = pygame.sprite.Group()
        enemybulletsGroup = pygame.sprite.Group()
        myfoodsGroup = pygame.sprite.Group()
        # 自定义事件
        # 	-生成敌方坦克事件
        genEnemyEvent = pygame.constants.USEREVENT
        pygame.time.set_timer(genEnemyEvent, 100)
        # 	-敌方坦克静止恢复事件
        recoverEnemyEvent = pygame.constants.USEREVENT
        pygame.time.set_timer(recoverEnemyEvent, 8000)
        # 	-我方坦克无敌恢复事件
        noprotectMytankEvent = pygame.constants.USEREVENT
        pygame.time.set_timer(noprotectMytankEvent, 8000)
        # 关卡地图
        map_stage = scene.Map(stage)
        # 我方坦克
        tank_player1 = tanks.myTank(1)
        tanksGroup.add(tank_player1)
        mytanksGroup.add(tank_player1)
        if num_player > 1:
            tank_player2 = tanks.myTank(2)
            tanksGroup.add(tank_player2)
            mytanksGroup.add(tank_player2)
        is_switch_tank = True
        player1_moving = False
        player2_moving = False
        # 为了轮胎的动画效果
        time = 0
        # 敌方坦克
        for i in range(0, 3):
            if enemytanks_total > 0:
                enemytank = tanks.enemyTank(i)
                tanksGroup.add(enemytank)
                enemytanksGroup.add(enemytank)
                enemytanks_now += 1
                enemytanks_total -= 1
        # 大本营
        myhome = home.Home()
        # 出场特效
        appearance_img = pygame.image.load("./images/others/appear.png").convert_alpha()
        appearances = []
        appearances.append(appearance_img.subsurface((0, 0), (48, 48)))
        appearances.append(appearance_img.subsurface((48, 0), (48, 48)))
        appearances.append(appearance_img.subsurface((96, 0), (48, 48)))
        # 关卡主循环
        while True:
            if is_gameover is True:
                break
            if enemytanks_total < 1 and enemytanks_now < 1:
                is_gameover = False
                break
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    pygame.quit()
                    sys.exit()
                if event.type == genEnemyEvent:
                    if enemytanks_total > 0:
                        if enemytanks_now < enemytanks_now_max:
                            enemytank = tanks.enemyTank()
                            if not pygame.sprite.spritecollide(enemytank, tanksGroup, False, None):
                                tanksGroup.add(enemytank)
                                enemytanksGroup.add(enemytank)
                                enemytanks_now += 1
                                enemytanks_total -= 1
                if event.type == recoverEnemyEvent:
                    for each in enemytanksGroup:
                        each.can_move = True
                if event.type == noprotectMytankEvent:
                    for each in mytanksGroup:
                        mytanksGroup.protected = False
            # 检查用户键盘操作
            key_pressed = pygame.key.get_pressed()
            # 玩家一
            # WSAD -> 上下左右
            # 空格键射击
            if key_pressed[pygame.K_w]:
                tanksGroup.remove(tank_player1)
                tank_player1.move_up(tanksGroup, map_stage.brickGroup, map_stage.ironGroup, myhome)
                tanksGroup.add(tank_player1)
                player1_moving = True
            elif key_pressed[pygame.K_s]:
                tanksGroup.remove(tank_player1)
                tank_player1.move_down(tanksGroup, map_stage.brickGroup, map_stage.ironGroup, myhome)
                tanksGroup.add(tank_player1)
                player1_moving = True
            elif key_pressed[pygame.K_a]:
                tanksGroup.remove(tank_player1)
                tank_player1.move_left(tanksGroup, map_stage.brickGroup, map_stage.ironGroup, myhome)
                tanksGroup.add(tank_player1)
                player1_moving = True
            elif key_pressed[pygame.K_d]:
                tanksGroup.remove(tank_player1)
                tank_player1.move_right(tanksGroup, map_stage.brickGroup, map_stage.ironGroup, myhome)
                tanksGroup.add(tank_player1)
                player1_moving = True
            elif key_pressed[pygame.K_SPACE]:
                if not tank_player1.bullet.being:
                    fire_sound.play()
                    tank_player1.shoot()
            # 玩家二
            # ↑↓←→ -> 上下左右
            # 小键盘0键射击
            if num_player > 1:
                if key_pressed[pygame.K_UP]:
                    tanksGroup.remove(tank_player2)
                    tank_player2.move_up(tanksGroup, map_stage.brickGroup, map_stage.ironGroup, myhome)
                    tanksGroup.add(tank_player2)
                    player2_moving = True
                elif key_pressed[pygame.K_DOWN]:
                    tanksGroup.remove(tank_player2)
                    tank_player2.move_down(tanksGroup, map_stage.brickGroup, map_stage.ironGroup, myhome)
                    tanksGroup.add(tank_player2)
                    player2_moving = True
                elif key_pressed[pygame.K_LEFT]:
                    tanksGroup.remove(tank_player2)
                    tank_player2.move_left(tanksGroup, map_stage.brickGroup, map_stage.ironGroup, myhome)
                    tanksGroup.add(tank_player2)
                    player2_moving = True
                elif key_pressed[pygame.K_RIGHT]:
                    tanksGroup.remove(tank_player2)
                    tank_player2.move_right(tanksGroup, map_stage.brickGroup, map_stage.ironGroup, myhome)
                    tanksGroup.add(tank_player2)
                    player2_moving = True
                elif key_pressed[pygame.K_KP0]:
                    if not tank_player2.bullet.being:
                        fire_sound.play()
                        tank_player2.shoot()
            # 背景
            screen.blit(bg_img, (0, 0))
            # 石头墙
            for each in map_stage.brickGroup:
                screen.blit(each.brick, each.rect)
            # 钢墙
            for each in map_stage.ironGroup:
                screen.blit(each.iron, each.rect)
            # 冰
            for each in map_stage.iceGroup:
                screen.blit(each.ice, each.rect)
            # 河流
            for each in map_stage.riverGroup:
                screen.blit(each.river, each.rect)
            # 树
            for each in map_stage.treeGroup:
                screen.blit(each.tree, each.rect)
            time += 1
            if time == 5:
                time = 0
                is_switch_tank = not is_switch_tank
            # 我方坦克
            if tank_player1 in mytanksGroup:
                if is_switch_tank and player1_moving:
                    screen.blit(tank_player1.tank_0, (tank_player1.rect.left, tank_player1.rect.top))
                    player1_moving = False
                else:
                    screen.blit(tank_player1.tank_1, (tank_player1.rect.left, tank_player1.rect.top))
                if tank_player1.protected:
                    screen.blit(tank_player1.protected_mask1, (tank_player1.rect.left, tank_player1.rect.top))
            if num_player > 1:
                if tank_player2 in mytanksGroup:
                    if is_switch_tank and player2_moving:
                        screen.blit(tank_player2.tank_0, (tank_player2.rect.left, tank_player2.rect.top))
                        player1_moving = False
                    else:
                        screen.blit(tank_player2.tank_1, (tank_player2.rect.left, tank_player2.rect.top))
                    if tank_player2.protected:
                        screen.blit(tank_player1.protected_mask1, (tank_player2.rect.left, tank_player2.rect.top))
            # 敌方坦克
            for each in enemytanksGroup:
                # 出生特效
                if each.born:
                    if each.times > 0:
                        each.times -= 1
                        if each.times <= 10:
                            screen.blit(appearances[2], (3 + each.x * 12 * 24, 3))
                        elif each.times <= 20:
                            screen.blit(appearances[1], (3 + each.x * 12 * 24, 3))
                        elif each.times <= 30:
                            screen.blit(appearances[0], (3 + each.x * 12 * 24, 3))
                        elif each.times <= 40:
                            screen.blit(appearances[2], (3 + each.x * 12 * 24, 3))
                        elif each.times <= 50:
                            screen.blit(appearances[1], (3 + each.x * 12 * 24, 3))
                        elif each.times <= 60:
                            screen.blit(appearances[0], (3 + each.x * 12 * 24, 3))
                        elif each.times <= 70:
                            screen.blit(appearances[2], (3 + each.x * 12 * 24, 3))
                        elif each.times <= 80:
                            screen.blit(appearances[1], (3 + each.x * 12 * 24, 3))
                        elif each.times <= 90:
                            screen.blit(appearances[0], (3 + each.x * 12 * 24, 3))
                    else:
                        each.born = False
                else:
                    if is_switch_tank:
                        screen.blit(each.tank_0, (each.rect.left, each.rect.top))
                    else:
                        screen.blit(each.tank_1, (each.rect.left, each.rect.top))
                    if each.can_move:
                        tanksGroup.remove(each)
                        each.move(tanksGroup, map_stage.brickGroup, map_stage.ironGroup, myhome)
                        tanksGroup.add(each)
            # 我方子弹
            for tank_player in mytanksGroup:
                if tank_player.bullet.being:
                    tank_player.bullet.move()
                    screen.blit(tank_player.bullet.bullet, tank_player.bullet.rect)
                    # 子弹碰撞敌方子弹
                    for each in enemybulletsGroup:
                        if each.being:
                            if pygame.sprite.collide_rect(tank_player.bullet, each):
                                tank_player.bullet.being = False
                                each.being = False
                                enemybulletsGroup.remove(each)
                                break
                        else:
                            enemybulletsGroup.remove(each)
                    # 子弹碰撞敌方坦克
                    for each in enemytanksGroup:
                        if each.being:
                            if pygame.sprite.collide_rect(tank_player.bullet, each):
                                if each.is_red == True:
                                    myfood = food.Food()
                                    myfood.generate()
                                    myfoodsGroup.add(myfood)
                                    each.is_red = False
                                each.blood -= 1
                                each.color -= 1
                                if each.blood < 0:
                                    bang_sound.play()
                                    each.being = False
                                    enemytanksGroup.remove(each)
                                    enemytanks_now -= 1
                                    tanksGroup.remove(each)
                                else:
                                    each.reload()
                                tank_player.bullet.being = False
                                break
                        else:
                            enemytanksGroup.remove(each)
                            tanksGroup.remove(each)
                    # 子弹碰撞石头墙
                    if pygame.sprite.spritecollide(tank_player.bullet, map_stage.brickGroup, True, None):
                        tank_player.bullet.being = False
                    # 子弹碰钢墙
                    if tank_player.bullet.stronger:
                        if pygame.sprite.spritecollide(tank_player.bullet, map_stage.ironGroup, True, None):
                            tank_player.bullet.being = False
                    else:
                        if pygame.sprite.spritecollide(tank_player.bullet, map_stage.ironGroup, False, None):
                            tank_player.bullet.being = False
                    # 子弹碰大本营
                    if pygame.sprite.collide_rect(tank_player.bullet, myhome):
                        tank_player.bullet.being = False
                        myhome.set_dead()
                        is_gameover = True
            # 敌方子弹
            for each in enemytanksGroup:
                if each.being:
                    if each.can_move and not each.bullet.being:
                        enemybulletsGroup.remove(each.bullet)
                        each.shoot()
                        enemybulletsGroup.add(each.bullet)
                    if not each.born:
                        if each.bullet.being:
                            each.bullet.move()
                            screen.blit(each.bullet.bullet, each.bullet.rect)
                            # 子弹碰撞我方坦克
                            for tank_player in mytanksGroup:
                                if pygame.sprite.collide_rect(each.bullet, tank_player):
                                    if not tank_player.protected:
                                        bang_sound.play()
                                        tank_player.life -= 1
                                        if tank_player.life < 0:
                                            mytanksGroup.remove(tank_player)
                                            tanksGroup.remove(tank_player)
                                            if len(mytanksGroup) < 1:
                                                is_gameover = True
                                        else:
                                            tank_player.reset()
                                    each.bullet.being = False
                                    enemybulletsGroup.remove(each.bullet)
                                    break
                            # 子弹碰撞石头墙
                            if pygame.sprite.spritecollide(each.bullet, map_stage.brickGroup, True, None):
                                each.bullet.being = False
                                enemybulletsGroup.remove(each.bullet)
                            # 子弹碰钢墙
                            if each.bullet.stronger:
                                if pygame.sprite.spritecollide(each.bullet, map_stage.ironGroup, True, None):
                                    each.bullet.being = False
                            else:
                                if pygame.sprite.spritecollide(each.bullet, map_stage.ironGroup, False, None):
                                    each.bullet.being = False
                            # 子弹碰大本营
                            if pygame.sprite.collide_rect(each.bullet, myhome):
                                each.bullet.being = False
                                myhome.set_dead()
                                is_gameover = True
                else:
                    enemytanksGroup.remove(each)
                    tanksGroup.remove(each)
            # 家
            screen.blit(myhome.home, myhome.rect)
            # 食物
            for myfood in myfoodsGroup:
                if myfood.being and myfood.time > 0:
                    screen.blit(myfood.food, myfood.rect)
                    myfood.time -= 1
                    for tank_player in mytanksGroup:
                        if pygame.sprite.collide_rect(tank_player, myfood):
                            # 消灭当前所有敌人
                            if myfood.kind == 0:
                                for _ in enemytanksGroup:
                                    bang_sound.play()
                                enemytanksGroup = pygame.sprite.Group()
                                enemytanks_total -= enemytanks_now
                                enemytanks_now = 0
                            # 敌人静止
                            if myfood.kind == 1:
                                for each in enemytanksGroup:
                                    each.can_move = False
                            # 子弹增强
                            if myfood.kind == 2:
                                add_sound.play()
                                tank_player.bullet.stronger = True
                            # 使得大本营的墙变为钢板
                            if myfood.kind == 3:
                                map_stage.protect_home()
                            # 坦克获得一段时间的保护罩
                            if myfood.kind == 4:
                                add_sound.play()
                                for tank_player in mytanksGroup:
                                    tank_player.protected = True
                            # 坦克升级
                            if myfood.kind == 5:
                                add_sound.play()
                                tank_player.up_level()
                            # 坦克生命+1
                            if myfood.kind == 6:
                                add_sound.play()
                                tank_player.life += 1
                            myfood.being = False
                            myfoodsGroup.remove(myfood)
                            break
                else:
                    myfood.being = False
                    myfoodsGroup.remove(myfood)
            pygame.display.flip()
            clock.tick(60)
    if not is_gameover:
        show_end_interface(screen, 630, 630, True)
    else:
        show_end_interface(screen, 630, 630, False)

if __name__ == '__main__':
    main()

4)效果展示

视频展示效果——

视频播放链接:https://live.csdn.net/v/embed/181068

【Pygame实战】经典的坦克大战游戏,勾起童年无限回忆!

静态截图效果——

游戏界面:

​第一关单人游戏:

双人第一关游戏:

总结

​好啦!中文版的坦克大战都看的懂了哈,想咋玩儿咋玩儿。

​这是程序员的浪漫,这也是我们的浪漫。

到此这篇关于Pygame坦克大战游戏开发实战详解代码的文章就介绍到这了,更多相关Pygame 坦克大战内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

(0)

相关推荐

  • python+pygame实现坦克大战

    本文实例为大家分享了python+pygame实现坦克大战的具体代码,供大家参考,具体内容如下 一.首先导入pygame库 二.源码分享 #coding=utf-8 import pygame import time import random from pygame.sprite import Sprite SCREEN_WIDTH=800 SCREEN_HEIGHT=500 BG_COLOR=pygame.Color(0,0,0) TEXT_COLOR=pygame.Color(255,0,

  • python使用pygame模块实现坦克大战游戏

    本文实例为大家分享了pygame模块实现坦克大战游戏的具体代码,供大家参考,具体内容如下 首先,第一步,游戏简单素材的准备. 炮弹,炮弹,坦克移动.音乐-开火素材. 其次,思路整理. 我们需要几个类,分别是玩家类,敌人类,炮弹类及地图类,开始游戏界面以及结束界面,血条等等. 开始coding. 主函数,new一个对象(java乱入emmm),声明一个对象. # encoding : utf-8 # anthor : comi from gameloop import * from pygame

  • 面向对象学习之pygame坦克大战

    经过一天多的奋战,查阅文献,参考别人的代码等等,完成了第一个面向对象的小项目,也深深体会到面向对象编程思想在游戏编程中所扮演的角色. 附上代码,参考了别人的代码,以及对他们代码的完善,又加上了自己的一些东西,收获颇深. import pygame import sys import time from pygame.locals import * from random import randint MOVE_SLEEP = 0.01 class MyTank: width = 600 heig

  • python+pygame实现坦克大战小游戏的示例代码(可以自定义子弹速度)

    python+pygame实现坦克大战小游戏-可以自定义子弹速度: 运行环境–python3.7.pycharm: 源码需要请:点赞留言邮箱: 正常版子弹速度: 普通速度版 加速版子弹速度: 子弹加速版 另外还有多种道具,支持两人一起玩.main()方法如下: def main(): pygame.init() pygame.mixer.init() resolution = 630, 630 screen = pygame.display.set_mode(resolution) pygame

  • Pygame坦克大战游戏开发实战详解代码

    导语 哈喽!哈喽——我是木木子 今天来升级下之前写的坦克大战游戏嘛,哈哈哈 其实也不算是修改,就是稍微的调试一下!​​ 因为之前写的界面都是英文的 ,有的小伙伴儿英文一点儿都不会的可能看着别扭,今天来一款中 文版的给大家嘛! 俗话说的好:“雨露均沾”.哈哈哈.jpg 小简介: <坦克大战>,1985年由日本开发商南梦宫(Namco)开发,是第一款可以双打的红白机游戏. 当时使用的还是小霸王. 很多小朋友以学习的名义买了以后偷偷打的打游戏还被家长发现了有 没得! <坦克大战>红白机原

  • Python图形用户界面与游戏开发实例详解

    目录 前言 基于tkinter模块的GUI 基于wxPython模块的GUI Pygame游戏开发 1.在游戏窗口中绘图 2.图形的处理 3.动画效果 4.碰撞检测 5.事件处理 总结 前言 对于使用过计算机的人,应该对图形用户界面(GUI)应该都不会太陌生,这里就不在赘述.那么对于python这样的动态语言有没有GUI相关的库呢?答案是肯定有的,那么常见的有哪些呢?主要有tkinter.wxPython.PyQt.PyGTK等模块,而tkinter是python默认的模块,没有功能特别强大的G

  • Spring Boot整合RabbitMQ开发实战详解

    这篇文章主要讲基本的整合.先把代码跑起来,再说什么高级特性. RabbitMQ 中的一些术语 如果你打开 RabbitMQ web 控制台,你会发现其中有一个 Exhanges 不好理解.下面简单说明一下. 交换器(Exchange) 交换器就像路由器,我们先是把消息发到交换器,然后交换器再根据路由键(routingKey)把消息投递到对应的队列.(明白这个概念很重要,后面的代码里面充分体现了这一点) 队列(Queue) 队列很好理解,就不用解释了. 绑定(Binding) 交换器怎么知道把这条

  • Pygame实现游戏最小系统功能详解

    目录 前言 一.什么是pygame 1.1 学习pygame的用处 1.2 pygame里的游戏世界 二.pygame简单讲解 2.1 安装pygame 2.2 游戏最小系统 前言 “我有一个梦想,那就是有生之年做出一款属于自己的游戏.” 不知道屏幕前的你是否曾经有和我一样的想法,总觉得市面上的游戏不完全符合你的胃口,想要自己开发出一款属于自己的独有的游戏. 此时,如果你正好学了Python,那么你的机会来了,python也是可以做游戏的!本篇文章将介绍Python一个非常有趣又功能强大库,它所

  • 经典再现 基于JAVA平台开发坦克大战游戏

    一.需求描述  1.功能性需求 在功能需求分析阶段,我们的主要任务是指定系统必须提供哪些服务,定义软件完成哪些功能,提供给那些人使用,功能需求是软件开发的一项基本需求,是需求分析必不可少的一部分.坦克大战是一款经典游戏了,本游戏学习了一些前辈们的经验,整体来说讲,游戏分为敌我双方,主要参与战斗的坦克有玩家控制,敌人坦克可以智能随机出现在屏幕上,并且移动,发射一定数量的子弹:玩家可以在规定的区域内随意移动坦克,当有子弹击中玩家时,玩家死亡,游戏结束:敌人坦克智能运行,敌方坦克由于需要具有一定智能性

  • Flutter开发之对角棋游戏实现实例详解

    目录 前沿 演示效果 对角棋规则 实现思路 具体实现 1. 绘制棋盘 2. 绘制棋子 3. 手势处理 4. 游戏规则 优化 总结 前沿 关于对角棋相信大家都不陌生,其凭借着规则简单又灵活多变成为我们童年不可缺少的益智游戏. 今天我将用Flutter来实现一个对角棋游戏,即巩固自己Flutter的绘制和手势知识,也希望这篇文章对大家有所帮助. 演示效果 老规矩,我们先演示下实现的最终效果: 对角棋规则 首先我们还是回顾下对角棋游戏的规则,这里借用 百度百科 的规则说明: 棋盘:象棋棋盘中,将士所在

  • 基于Python_脚本CGI、特点、应用、开发环境(详解)

    CGI CGI 目前由NCSA维护,NCSA定义CGI如下: CGI(Common Gateway Interface),通用网关接口,它是一段程序,运行在服务器上如:HTTP服务器,提供同客户端HTML页面的接口. CGI程序可以是Python脚本.Perl脚本.Shell脚本.C或者C++程序等. 服务器 在你进行CGI编程前,确保您的Web服务器支持CGI及已经配置了CGI的处理程序. 所有的HTTP服务器执行CGI程序都保存在一个预先配置的目录.这个目录被称为CGI目录,并按照惯例,它被

  • 基于python实现坦克大战游戏

    本文实例为大家分享了python实现坦克大战游戏的具体代码,供大家参考,具体内容如下 游戏界面 pygame游戏引擎的安装 pip安装 windows + R --> cmd --> 命令行输入 pip install 模块名==版本号 pycharm中安装 File --> setting --> Project --> Project Interpreter --> 右侧 + install --> 搜索框输入pygame --> 下方 installP

  • vite2.0+vue3移动端项目实战详解

    一.涉及技术点 vite版本 vue3 ts 集成路由 集成vuex 集成axios 配置Vant3 移动端适配 请求代理 二.步骤 vite+ts+vue3只需要一行命令 npm init @vitejs/app my-vue-app --template vue-ts 配置路由 npm install vue-router@4 --save 在src下新建router目录,新建index.ts文件 import { createRouter, createWebHashHistory, Ro

随机推荐