还是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