布丁兔制作的py游戏
Kitty_Rabbit · · 休闲·娱乐
可以直接拷贝使用but不可侵权(你不会拷的吧。。。) 一年没登luogu了能记得我的都是这个[动画表情]
"""
Author:Kitty
Time:2025/3/16 11:55
File:甜品记忆岛.py
Tool:PyCharm
"""
import random as r
import time as t
from tkinter import Tk, Button, DISABLED, Label, messagebox, StringVar, OptionMenu
import pygame
import sys
# 模拟游戏启动
print("正在启动中...")
print("加载完毕\n")
a = 0
b = 0
cnt = 0
timer = None
countdown_seconds = 0
def choose_background_color(choice):
global color
if choice == "默认":
color = "#FFFFFF"
elif choice == "红":
color = "#FFC8C8"
elif choice == "橙":
color = "#FFCEB8"
elif choice == "黄":
color = "#FFF6B8"
elif choice == "绿":
color = "#BDFFB0"
elif choice == "蓝":
color = "#A4DFFF"
elif choice == "紫":
color = "#B9BDFF"
elif choice == "褐":
color = "#CFCAC7"
elif choice == "灰":
color = "#DBDBDB"
color_window.destroy()
def start_game():
start_window.destroy()
def choose_level(level):
global a, b, countdown_seconds
if level == "简单":
a = 4
b = 6
countdown_seconds = 1 * 60
elif level == "中等":
a = 5
b = 8
countdown_seconds = 2 * 60
elif level == "微难":
a = 6
b = 10
countdown_seconds = 4 * 60
level_window.destroy()
def show_symbol(x, y):
global first, X, Y, cnt
button[x, y]['text'] = b_e[x, y]
button[x, y].update_idletasks()
if first:
X = x
Y = y
first = False
elif X != x or Y != y:
if button[X, Y]['text'] != button[x, y]['text']:
t.sleep(0.5)
button[X, Y]['text'] = ''
button[x, y]['text'] = ''
else:
button[X, Y]['command'] = DISABLED
button[x, y]['command'] = DISABLED
touch_sound = pygame.mixer.Sound(r"touch.wav")
touch_sound.set_volume(0.5)
touch_sound.play()
cnt += 1
if a == 4 and b == 6:
if cnt == 12:
touch_sound = pygame.mixer.Sound(r"win.wav")
touch_sound.set_volume(1.0)
touch_sound.play()
stop_countdown()
messagebox.showinfo("成就达成", "恭喜获得成就:记忆萌新")
print("游戏结束")
sys.exit(0)
elif a == 5 and b == 8:
if cnt == 20:
# 中等
touch_sound = pygame.mixer.Sound(r"win.wav")
touch_sound.set_volume(1.0)
touch_sound.play()
stop_countdown()
messagebox.showinfo("成就达成", "恭喜获得成就:记忆大师")
print("游戏结束")
sys.exit(0)
elif a == 6 and b == 10:
if cnt == 30:
# 微难
touch_sound = pygame.mixer.Sound(r"win.wav")
touch_sound.set_volume(1.0)
touch_sound.play()
stop_countdown()
messagebox.showinfo("成就达成", "恭喜获得成就:记忆王者")
print("游戏结束")
sys.exit(0)
first = True
def update_countdown():
global countdown_seconds, timer
if countdown_seconds > 0:
minutes, seconds = divmod(countdown_seconds, 60)
countdown_label.config(text=f"倒计时: {minutes:02d}:{seconds:02d}")
countdown_seconds -= 1
timer = window.after(1000, update_countdown)
else:
countdown_label.config(text="时间到!任务失败")
game_over()
def stop_countdown():
global timer
if timer:
window.after_cancel(timer)
def game_over():
for x in range(b):
for y in range(a):
button[x, y]['command'] = DISABLED
lose_sound = pygame.mixer.Sound(r"lost.wav")
lose_sound.set_volume(1.0)
lose_sound.play()
messagebox.showinfo("游戏结束", "很遗憾,时间到了,你输了!")
sys.exit(0)
color_window = Tk()
color_window.title('选择背景色--©布丁兔🐰')
color_var = StringVar(color_window)
color_var.set("默认")
choices = ["默认", "红", "橙", "黄", "绿", "蓝", "紫", "褐", "灰"]
color_menu = OptionMenu(color_window, color_var, *choices, command=choose_background_color)
color_menu.pack(pady=30)
color_label = Label(color_window, text="点击“默认”,请选择背景颜色……", font=('黑体', 16))
color_label.pack(pady=30)
color_window.mainloop()
pygame.mixer.init()
pygame.mixer.music.load(r"sweet.wav")
pygame.mixer.music.set_volume(0.5)
pygame.mixer.music.play(-1, 0)
start_window = Tk()
start_window.title('开始游戏--©布丁兔🐰')
start_window.configure(bg=color)
welcome_label = Label(start_window, text=" 甜品记忆岛 ", font=('黑体', 24), bg=color)
welcome_label.pack(pady=50)
# 游戏介绍
welcome_label = Label(start_window, text=" “眼疾手快”益智游戏,提升人的观察力、记忆力和专注力。 ", font=('黑体', 16), bg=color)
welcome_label.pack(pady=30)
welcome_label = Label(start_window, text=" 游戏规则:甜品两两配对,所有的甜品配对完成,游戏过关。 ", font=('黑体', 16), bg=color)
welcome_label.pack(pady=30)
start_button = Button(start_window, text="开始游戏", command=start_game, font=('黑体', 30), bg=color)
start_button.pack(pady=30)
# 设计者介绍
welcome_label = Label(start_window, text=" 游戏设计:王韵春 ", font=('黑体', 18), fg='blue', bg=color)
welcome_label.pack(pady=50)
start_window.mainloop()
level_window = Tk()
level_window.title('选择难度--©布丁兔🐰')
level_window.configure(bg=color)
choice_label = Label(level_window, text=" 甜品记忆岛 ", font=('黑体', 24), bg=color)
choice_label.pack(pady=35)
choice_label = Label(level_window, text=" 请选择游戏难度 ", font=('Arial', 20), bg=color)
choice_label.pack(pady=30)
easy_button = Button(level_window, text="简单", command=lambda: choose_level("简单"), font=('Arial', 18), bg=color)
easy_button.pack(pady=20)
medium_button = Button(level_window, text="中等", command=lambda: choose_level("中等"), font=('Arial', 18), bg=color)
medium_button.pack(pady=20)
hard_button = Button(level_window, text="微难", command=lambda: choose_level("微难"), font=('Arial', 18), bg=color)
hard_button.pack(pady=20)
level_window.mainloop()
window = Tk()
window.title('甜品记忆岛--©布丁兔🐰')
window.resizable(width=False, height=False)
button = {}
first = True
X = 0
Y = 0
b_e = {}
if a == 4 and b == 6:
emoji = ["🎂", "🎂", "🥐", "🥐", "🍬", "🍬",
"🥪", "🥪", "🥯", "🥯", "🍧", "🍧",
"🍫", "🍫", "🍔", "🍔", "🍮", "🍮",
"🥖", "🥖", "🥨", "🥨", "🍭", "🍭"]
elif a == 5 and b == 8:
emoji = ["🎂", "🎂", "🥐", "🥐", "🍬", "🍬", "🍧", "🍧",
"🍔", "🍔", "🌭", "🌭", "🍿", "🍿", "🥟", "🥟",
"🥯", "🥯", "🍉", "🍉", "🍞", "🍞", "🍡", "🍡",
"🍫", "🍫", "🥛", "🥛", "🍮", "🍮", "🫐", "🫐",
"🥖", "🥖", "🥨", "🥨", "🥠", "🥠", "🍭", "🍭"]
elif a == 6 and b == 10:
emoji = ["🎂", "🎂", "🥐", "🥐", "🍬", "🍬", "🍩", "🍩", "🍧", "🍧",
"🍓", "🍓", "🍎", "🍎", "🍊", "🍊", "🍕", "🍕", "🧀", "🧀",
"🍔", "🍔", "🍟", "🍟", "🌭", "🌭", "🍿", "🍿", "🥟", "🥟",
"🥪", "🥪", "🥯", "🥯", "🍉", "🍉", "🍞", "🍞", "🍡", "🍡",
"🍫", "🍫", "🥛", "🥛", "🍮", "🍮", "🧋", "🧋", "🫐", "🫐",
"🥖", "🥖", "🥨", "🥨", "🍗", "🍗", "🥠", "🥠", "🍭", "🍭"]
r.shuffle(emoji)
size = 28
countdown_label = Label(window, text="", font=('Arial', 18), bg=color)
countdown_label.grid(row=0, columnspan=b)
for x in range(b):
for y in range(a):
button2 = Button(command=lambda x=x, y=y: show_symbol(x, y), width=3, height=2, font=('Arial', size,), bg=color)
button2.grid(column=x, row=y + 1)
button[x, y] = button2
b_e[x, y] = emoji.pop()
update_countdown()
window.mainloop()
可能会报错因为音频不在, 感谢你的游玩!