Commit 66b54d0e by BellCodeEditor

auto save

parent 1e59d6be
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 + "还剩下" + str(enemy.hp) + "血量"
info = info1 + info2 + info3
print(info)
else:
info3 = enemy.name + "阵亡,游戏结束"
info = info1 + info2 + info3
print(info)
exit()
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("垭瑟")
houyi.combat(yase)
yase.combat(houyi)
houyi.cure()
yase.cure()
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
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)
def cure(self): # 治疗
# super().cure()
blood = random.randint(30,50)
self.hp = self.hp + blood
if self.hp > self.max_hp:
self.hp = self.max_hp
print(self.name+"使用了治疗术,血量增加:", blood,",目前的血量为:",self.hp)
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)
class Hero:
def __init__(self, name):
self.level = 1
self.hp = 250
self.attack = 40
self.name = name
def combat(self, enemy): # 普通攻击
info1 = self.name+"对"+enemy.name+"发起进攻,"
info2 = "造成"+str(self.attack)+"点伤害,"
enemy.hp -= self.attack
if enemy.hp > 0:
info3 = enemy.name+"还剩下"+str(enemy.hp)+"血量"
info = info1+info2+info3
print(info)
else:
info3 = enemy.name+"阵亡,游戏结束"
info = info1+info2+info3
print(info)
exit()
yase = Hero("垭瑟")
houyi= Hero("后羿")
yase.combat(houyi)
class Hero:
def __init__(self, name):
self.name = name
self.level = 1
self.hp = 250
self.attack = 40
self.max_hp = self.hp
# print("父类初始化")
def combat(self, enemy): # 普通攻击
info1 = self.name+"对"+enemy.name+"发起进攻,"
info2 = "造成"+str(self.attack)+"点伤害,"
enemy.hp -= self.attack
if enemy.hp > 0:
info3 = enemy.name+"还剩下"+str(enemy.hp)+"血量"
info = info1+info2+info3
print(info)
else:
info3 = enemy.name+"阵亡,游戏结束"
info = info1+info2+info3
print(info)
exit()
class Player(Hero):
def __init__(self,name,hero_type):
super().__init__(name)
self.hp = 200
self.attack = 50
self.hero_type = hero_type
# 角色xx创建成功,当前等级xx,血量xx,攻击力xx
print("角色"+self.name+"创建成功,英雄类型为:", self.hero_type)
print("当前等级、血量、攻击力分别为:",self.level,self.hp,self.attack)
houyi = Player( "后羿", "射手")
print(houyi.hp)
# yase = Hero("垭瑟")
\ No newline at end of file
import tkinter
# 建立窗口对象
root = tkinter.Tk()
root.title("注册") # 设置窗口标题
root.geometry("400x320+500+300") # 设置窗口大小
# 输入框entry;用户输入框
e1 = tkinter.Entry(root,show=None,font=('FG平成明朝体W9',14),bg="light grey",width=18) # 显示成明文形式
e1.place(x=140, y=80)
# 密码输入框,左上角坐标:x:140,y:140
e2 = tkinter.Entry(root, show='*', font=('FG平成明朝体W9', 14), width=18)
e2.place(x=140, y=140)
# 确认密码输入框,左上角坐标:x:140,y:200
e3 = tkinter.Entry(root, show='*', font=('FG平成明朝体W9', 14), width=18)
e3.place(x=140, y=200)
# 注册界面上的文字标签
lab = tkinter.Label(root, text='您好!请填写注册信息', font=('FG平成明朝体W9', 15),
fg="black",width=40, height=2,bg="pink")
lab.place(x=0,y=0)
# 在输入框前展示文字标签:用户名:、密 码:、确认密码:
lab1 = tkinter.Label(root, text='用户名:', font=("FG平成明朝体W9", 12), fg="black")
lab1.place(x=60, y=80)
lab2 = tkinter.Label(root, text='密 码:', font=("FG平成明朝体W9", 12), fg="black")
lab2.place(x=60, y=140)
lab3 = tkinter.Label(root, text='确认密码:', font=("FG平成明朝体W9", 12), fg="black")
lab3.place(x=50, y=200)
# 保持窗口监听,进入消息循环
root.mainloop()
import tkinter
def register():
name = e1.get()
password1 = e2.get()
password2 = e3.get()
print("用户输入的信息为:",name,password1,password2)
# 建立窗口对象
root = tkinter.Tk()
root.title("注册") # 设置窗口标题
root.geometry("400x320+500+300") # 设置窗口大小
root.resizable(width=False, height=False) # True可以拉伸,False不能拉伸
# 输入框entry;用户输入框
e1 = tkinter.Entry(root,show=None,font=('宋体',14),bg="light grey",width=18) # 显示成明文形式
e1.place(x=140, y=80)
# 密码输入框,左上角坐标:x:140,y:140
e2 = tkinter.Entry(root, show='*', font=('宋体', 14), width=18)
e2.place(x=140, y=140)
# 确认密码输入框,左上角坐标:x:140,y:200
e3 = tkinter.Entry(root, show='*', font=('宋体', 14), width=18)
e3.place(x=140, y=200)
# 注册界面上的文字标签
lab = tkinter.Label(root, text='您好!请填写注册信息', font=('宋体', 15),
fg="black",width=40, height=2,bg="green")
lab.place(x=0,y=0)
# 在输入框前展示文字标签:用户名:、密 码:、确认密码:
lab1 = tkinter.Label(root, text='用户名:', font=("宋体", 12), fg="black")
lab1.place(x=60, y=80)
lab2 = tkinter.Label(root, text='密 码:', font=("宋体", 12), fg="black")
lab2.place(x=60, y=140)
lab3 = tkinter.Label(root, text='确认密码:', font=("宋体", 12), fg="black")
lab3.place(x=50, y=200)
# 提交按钮;
button = tkinter.Button(root, text='提交', bg="lightgreen",width=15,
command=register) # fg 字体颜色
button.place(x=150, y=250)
# 进入消息循环
root.mainloop()
# 玩家出拳
player = input("请出拳(石头/剪刀/布):")
print("玩家出拳:"+player)
# 计算机随机出拳
import random
list = ["石头","剪刀", "布"]
computer = random.choice(list)
print("计算机出拳:"+computer)
# 显示结果
if player == computer:
print("平局")
elif (player=="石头" and computer=="剪刀")or(player=="剪刀" and computer=="布")or(player=="布" and computer=="石头"):
print("恭喜,你赢了")
else:
print("很遗憾,你输了")
\ No newline at end of file
a = input("请输入一个数字")
b = 2
print(a+str(b))
\ No newline at end of file
import random
game_list = ["石头","剪刀","布"]
#计算机出拳
# computer = random.choice(game_list)
# player = input("请出拳(石头/剪刀/布):")
# if player == "剪刀" or player == "布" or player == "石头":
player_win = 0
computer_win = 0
# 只要任何一方没赢够两盘,游戏就一直进行
while player_win < 2 and computer_win <2:
print("-" * 30)
computer = random.choice(game_list)
player = input("请出拳(石头/剪刀/布):")
if player in game_list:
print("玩家出拳:",player)
print("计算机出拳:",computer)
if player == computer :
print("平局")
elif (player=="剪刀" and computer=="布") or (player=="石头" and computer=="剪刀") or (player=="布" and computer=="石头"):
print("恭喜你,赢了")
player_win +=1
else:
print("很遗憾,你输了")
computer_win +=1
else:
print("请输入有效的操作!")
#游戏结束显示结果:
print("-" * 30)
print("最终比分:"+"(玩家)"+str(player_win)+":"+str(computer_win)+"(电脑)")
if 玩家胜利条件:
print("恭喜你最终战胜了电脑!")
else:
print("很遗憾你被电脑击败了!")
import turtle
turtle.fillcolor("red")
turtle.begin_fill()
for i in range(5):
turtle.forward(200)
turtle.left(144)
turtle.end_fill()
turtle.done()
\ 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