Pygame CoinGame 捡金币游戏

这篇博客介绍了如何利用Python的Pygame库创建一个有趣的捡金币游戏。通过阅读,你可以了解到游戏的基本结构、如何实现金币的生成与收集,以及Pygame在游戏开发中的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

还是find.py

from cryptography.fernet import Fernet
import json

# 生成密钥
key = b'dNcf9UYoAaqUcyrPS0CLIdEQbGzMRyniE9RUMlgGKfg='

# 初始化加密器
cipher = Fernet(key)

class File:
    @staticmethod
    def into(data):
        json_data = json.dumps(data).encode()
        encrypted_data = cipher.encrypt(json_data)
        # 将加密后的数据写入文件
        with open('data.dat', 'wb') as f:
            f.write(encrypted_data)

    @staticmethod
    def read():
        with open('data.dat', 'rb') as f:
            encrypted_data = f.read()
        # 解密数据
        decrypted_data = cipher.decrypt(encrypted_data)
        json_data = decrypted_data.decode()
        data = json.loads(json_data)
        return data

CoinGame.py

import pygame
import sys
import time
from random import randint
import find

pygame.init()
pygame.mixer.music.load('bg.mp3')
pygame.mixer.music.set_volume(0.6)
pygame.mixer.music.play(-1)
get = pygame.mixer.Sound('get.mp3')
get.set_volume(1)
over = pygame.mixer.Sound('over.mp3')
over.set_volume(1)
rect = pygame.Rect((425, 400), (150, 80))
middle = pygame.Rect((430, 405), (140, 70))
start = rect.copy()
middle_start = middle.copy()
f = find.File()
history = f.read()

def Top():
    H = game.font.render('Top Score: ' + str(history), True, 'blue')
    HW, HH = game.font.size('Top Score: ' + str(history))
    game.screen.blit(H, (500 - HW / 2, 632 - HH))

class Actor:
    x = 0
    y = 0
    image = None

    def __init__(self, image):
        self.image = pygame.image.load(image)

    def draw(self):
        game.screen.blit(self.image, (self.x, self.y))


class Game:
    screen_mode = (0, 0)
    screen = None
    caption = 'Get Coin 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值