大家好,我是 Jack~
这年头魔幻的事越来越多了,最近网上流传了一张图,看后我直呼,好家伙
有一家公司为了掌握员工的动态,开发了离职倾向监控系统,员工每天上班浏览的网站,都会被系统记录下来。
可以看到,“高危”、“疑似”、“可疑”等标签,招聘网站的浏览次数都会被记录下来。
各大招聘网站赫然在列,更离谱的是,投递出去的简历都可以直接下载,甚至还有离职倾向分析。
打工人,何苦难为打工人哦~
看来摸鱼不能逛这类网站了,推荐给大家一些适合摸鱼学习的小项目。
正好最近,不少小伙伴问我,初学 Python,想边玩边学,有什么项目推荐不。
用 Python 写的小游戏很适合啊,摸鱼、学习两不误!

坦克大战

用 pygame 实现的,用了一些简单的碰撞检测算法,坦克大战,小时候应该都玩过~
# -*- coding: utf-8 -*-

import
 pygame

import
 sys

import
 traceback

import
 wall

import
 myTank

import
 enemyTank

import
 food



defmain():
    pygame.init()

    pygame.mixer.init()


    resolution = 
630
630
    screen = pygame.display.set_mode(resolution)

    pygame.display.set_caption(
"Tank War "
)


# 加载图片,音乐,音效.
    background_image     = pygame.image.load(
r"..\image\background.png"
)

    home_image           = pygame.image.load(
r"..\image\home.png"
)

    home_destroyed_image = pygame.image.load(
r"..\image\home_destroyed.png"
)


    bang_sound          = pygame.mixer.Sound(
r"..\music\bang.wav"
)

    bang_sound.set_volume(
1
)

    fire_sound           = pygame.mixer.Sound(
r"..\music\Gunfire.wav"
)

    start_sound          = pygame.mixer.Sound(
r"..\music\start.wav"
)

    start_sound.play()


# 定义精灵组:坦克,我方坦克,敌方坦克,敌方子弹
    allTankGroup     = pygame.sprite.Group()

    mytankGroup      = pygame.sprite.Group()

    allEnemyGroup    = pygame.sprite.Group()

    redEnemyGroup    = pygame.sprite.Group()

    greenEnemyGroup  = pygame.sprite.Group()

    otherEnemyGroup  = pygame.sprite.Group()  

    enemyBulletGroup = pygame.sprite.Group()

# 创建地图 
    bgMap = wall.Map()

# 创建食物/道具 但不显示
    prop = food.Food()

# 创建我方坦克
    myTank_T1 = myTank.MyTank(
1
)

    allTankGroup.add(myTank_T1)

    mytankGroup.add(myTank_T1)

    myTank_T2 = myTank.MyTank(
2
)

    allTankGroup.add(myTank_T2)

    mytankGroup.add(myTank_T2)

# 创建敌方 坦克
for
 i 
in
 range(
1
4
):

            enemy = enemyTank.EnemyTank(i)

            allTankGroup.add(enemy)

            allEnemyGroup.add(enemy)

if
 enemy.isred == 
True
:

                redEnemyGroup.add(enemy)

continue
if
 enemy.kind == 
3
:

                greenEnemyGroup.add(enemy)

continue
            otherEnemyGroup.add(enemy)

# 敌军坦克出现动画
    appearance_image = pygame.image.load(
r"..\image\appear.png"
).convert_alpha()

    appearance = []

    appearance.append(appearance_image.subsurface(( 
0
0
), (
48
48
)))

    appearance.append(appearance_image.subsurface((
48
0
), (
48
48
)))

    appearance.append(appearance_image.subsurface((
96
0
), (
48
48
)))

这里省略了很多代码,核心代码一共500多行,文章结尾一起提供给大家~

2048

2048 这游戏火过一阵子,Python 版本的代码也早都有了。

愤怒的小鸟

愤怒的小鸟就不用多介绍了,强大的网友代码都给大家安排上了。

其它

除了这些,还有扫雷游戏、五子棋游戏、俄罗斯方块、贪吃蛇等各种小游戏。
代码太多了,就不贴了,公众号:jackcui-ai,后台回复:game 即可获取。
祝大家摸鱼学习快乐~
·················END·················

推荐阅读

继续阅读
阅读原文