Commit efeb1bf1 by BellCodeEditor

auto save

parent 29ade251
Showing with 147 additions and 0 deletions
import pygame,os
from pygame import locals
pygame.init() # 初始化
# 创建窗口
screen = pygame.display.set_mode((640, 480))
# 载入图片、资源
bg_img = pygame.image.load('background.png') # 背景图
play_img = pygame.image.load('play.png') # 播放按钮
stop_img = pygame.image.load('stop.png') # 暂停按钮
last_img = pygame.image.load('last.png') # 上一曲按钮
next_img = pygame.image.load('next.png') # 下一曲按钮
logo_img = pygame.image.load('logo.png') # 中间logo
#music_list = ['歌曲1.wav','歌曲2.wav','歌曲3.wav','歌曲4.ogg'] # 歌单列表
music_list = []
path = r'C:\Users\WangTian\Desktop\test' # 路径
filelist = os.listdir(path) # 以列表的形式返回当前文件下的所有目录
for i in filelist:
if i[-4:] == '.wav' or i[-4:] == '.ogg': # 用切片找到满足条件的音频文件
music_list.append(i) # 将需要的文件名添加到列表里
volume = 0.8
pygame.mixer.music.set_volume(volume) # 初始播放音量
click = 0
play_button = stop_img
num = -1
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
exit()
if event.type == locals.KEYDOWN:
if event.key == locals.K_UP:
volume += 0.1
if volume>1:
volume = 1
pygame.mixer.music.set_volume(volume) # 音乐播放器音量
if event.key == locals.K_DOWN:
volume -= 0.1
if volume<0:
volume = 0
pygame.mixer.music.set_volume(volume) # 音乐播放器音量
if event.type == locals.MOUSEBUTTONDOWN: # 鼠标点击事件
if event.button == 1:
x,y = event.pos
if x > 270 and x < 370 and y >350 and y < 450: # 设置鼠标点击范围
click += 1
if click % 2 == 0:
pygame.mixer.music.unpause()
play_button = stop_img # 点击可暂停图片
else:
pygame.mixer.music.pause()
play_button = play_img # 点击可播放图片
if x > 120 and x < 220 and y > 350 and y < 400:
num -= 1
if num < 0:
num = len(music_list)-1
pygame.mixer.music.load(path+'\\'+music_list[num]) # 加载音频文件,如果是本地文件夹就要添加上路径。
pygame.mixer.music.play() # 播放音乐
click = 0
play_button = stop_img
if pygame.mixer.music.get_busy() == False: # 布尔值检测音乐是否在播放
num += 1
if num > len(filelist)-1:
num = 0
pygame.mixer.music.load(path+'\\'+music_list[num]) # 加载音频文件,如果是本地文件夹就要添加上路径。
pygame.mixer.music.play() # 播放音乐
# 绘制画面
screen.blit(bg_img, (0, 0)) # 填充背景
screen.blit(play_button, (270, 330)) # 暂停按钮
screen.blit(logo_img, (170, 60)) # 中间logo图
screen.blit(last_img, (120, 350)) # 上一曲
screen.blit(next_img, (420, 350)) # 下一曲
# 刷新画面
pygame.display.update()
\ No newline at end of file
import random
class Hero(object):
def __init__(self, name):
self.name = name
self.level = 1
self.hp = 250
self.attack = 40
self.max_hp = self.hp
def cure(self): # 治疗
self.hp = self.hp + 60
if self.hp > self.max_hp:
self.hp = self.max_hp
print(self.name+"使用了治疗术,血量增加:", 60,",目前的血量为:",self.hp)
def combat(self, enemy): # 攻击
info1 = self.name+"对"+enemy.name+"发起进攻,"
info2 = "造成"+str(self.attack)+"点伤害,"
enemy.hp -= self.attack
if enemy.hp < 0:
info3 = enemy.name+"阵亡,游戏结束"
info = info1+info2+info3
print(info)
exit()
else:
info3 = enemy.name+"还剩下"+str(enemy.hp)+"血量"
info = info1+info2+info3
print(info)
class Player(Hero):
def __init__(self,hero_type,name):
super().__init__(name)
self.hp = 200
self.attack = 50
self.max_hp = self.hp
self.hero_type = hero_type
print("角色"+self.name+"创建成功,英雄类型为:", self.hero_type)
print("当前等级、血量、攻击力分别为:",self.level,self.hp,self.attack)
houyi = Player("射手", "后羿")
yase = Hero("垭瑟")
print(30 * '-')
print(' 战斗开始')
while True:
print("-" * 30)
# 玩家攻击
choice = input("请选择释放英雄技能(1攻击/2治疗):")
if choice == "q":
print("游戏结束")
break
elif choice == "1":
houyi.combat(yase)
elif choice == "2":
houyi.cure()
else:
print("请重新输入1或者2")
continue
# 敌方攻击
status = random.randint(1, 3)
if status == 1:
yase.cure()
else:
yase.combat(houyi)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment