武器E-R图
盾牌E-R图
护甲E-R图
继承物品类Item,根据需求,武器有三个属性,盾牌四个属性,护甲三个属性,设置就完事了。
class Equipments(Item):
class Weapon:
def __init__(self, name, damage, weight):
self.name = name
self.damage = damage
self.weight = weight
class Shield:
def __init__(self, name, armourRating, percentage, weight):
self.name = name
self.armourRating = armourRating
self.percentage = percentage
self.weight = weight
class Armour:
def __init__(self, name, armourRating, weight):
self.name = name
self.armourRating = armourRating
self.weight = weight
附加文档也提供了一些装备的属性作为参考:
从附加文档的参考装备中挑选一部分作为系统物品库,放入ItemList列表中存待用。
def getItemsList():
w1 = Equipments.Weapon('Redsword', 15, 1)
s1 = Equipments.Shield('Redshield', 10, 1.5, 0.1)
a1 = Equipments.Armour('Redarmour', 10, 2)
w2 = Equipments.Weapon('Orangesword', 15, 1)
s2 = Equipments.Shield('Orangeshield', 15, 2, 0.15)
a2 = Equipments.Armour('Orangearmour', 15, 2.5)
w3 = Equipments.Weapon('Yellowsword', 20, 1.5)
s3 = Equipments.Shield('Yellowshield', 20, 2.5, 0.2)
a3 = Equipments.Armour('Yellowarmour', 10, 2)
w4 = Equipments.Weapon('Greensword', 40, 2.5)
s4 = Equipments.Shield('Greenshield', 30, 3, 0.25)
a4 = Equipments.Armour('Greenarmour', 30, 3.5)
w5 = Equipments.Weapon('Cyansword', 50, 3)
s5 = Equipments.Shield('Cyanshield', 40, 3.5, 0.3)
a5 = Equipments.Armour('Cyanarmour', 40, 4)
w6 = Equipments.Weapon('Bluesword', 60, 3.5)
s6 = Equipments.Shield('Blueshield', 50, 4, 0.35)
a6 = Equipments.Armour('Bluearmour', 50, 4.5)
potion1 = Potions("healthPotion")
potion2 = Potions("damagePotion")
itemsList = [w1, w2, w3, w4, w5, w6, s1, s2, s3, s4, s5, s6, a1, a2, a3, a4, a5, a6, potion1, potion2]
return itemsList
带着名字就能创建一个勇士,勇士初始装备设置为新手套装,hp你看着改
def initAdventurer(name):
w1 = Equipments.Weapon('新手刀', 10, 1)
s1 = Equipments.Shield('新手盾', 2, 0.3, 1)
a1 = Equipments.Armour('新手甲', 3, 1)
potion1 = Potions("healthPotion")
potion2 = Potions("damagePotion")
myInventory = Inventory()
myInventory.getItem(potion1)
myInventory.getItem(potion2)
adventurer = Adventurer(name, w1, s1, a1, myInventory, 100)
return adventurer
def initEnemy(enemyNum):
enemyName = f"怪物{enemyNum}号"
w1 = Equipments.Weapon('新手刀', 10, 1)
s1 = Equipments.Shield('新手盾', 2, 0.3, 1)
a1 = Equipments.Armour('新手甲', 3, 1)
enemy = Adventurer(enemyName, w1, s1, a1, Inventory(), 50)
return enemy
随机化的,取个随机数从物品库里面随机取就行,和后面奖励机制一样
def randomEnemy(enemyNum):
enemyName = f"怪物{enemyNum}号"
wNum = random.randint(0, 5)
sNum = random.randint(6, 11)
aNum = random.randint(12, 17)
randomHP = random.randint(40+6*enemyNum, 80+6*enemyNum)
enemy = Adventurer(enemyName, itemsList[wNum], itemsList[sNum], itemsList[aNum], Inventory(), randomHP)
return enemy
if adv.getWeight() <= enemy.getWeight():
while adv.isAlive() == "true" and enemy.isAlive() == "true":
enemySub, advAdd, advSub, enemyAdd = 0, 0, 0, 0
enemySub, advAdd = actions.action(adv, enemy)
if enemySub == -99 and advAdd == -99:
return
advSub, enemyAdd = actions.enemyAction(enemy, adv)
settleRound(adv, enemy, enemySub, advAdd, advSub, enemyAdd)
else:
while adv.isAlive() == "true" and enemy.isAlive() == "true":
enemySub, advAdd, advSub, enemyAdd = 0, 0, 0, 0
advSub, enemyAdd = actions.enemyAction(enemy, adv)
enemySub, advAdd = actions.action(adv, enemy)
if enemySub == -99 and advAdd == -99:
return
settleRound(adv, enemy, enemySub, advAdd, advSub, enemyAdd)
if enemy.alive == 'false':
print("===========================牛批,恭喜你战胜了怪兽===================================================")
win = 1
def action(adv, enemy):
eSub, aAdd = 0, 0
if adv.stunned == 'true':
print("你被对面用盾牌格挡眩晕了,将跳过这回合")
adv.stunned = 'false'
return eSub, aAdd
print("你有如下选择:")
print("1.攻击attack")
print("2.格挡block")
print("3.使用物品use an item")
print("4.逃跑run away")
while 1:
choice = input("请输入你的选择:")
if choice == "1":
eSub = attack(adv, enemy)
elif choice == "2":
aAdd = defend(adv, enemy)
elif choice == "3":
usePotion(adv, enemy)
elif choice == "4":
runAway()
return -99, -99
else:
print("输入指令无效,请重新输入:")
continue
break
return eSub, aAdd
def attack(attacker=initAdventurer("无衣"), victim=randomEnemy(0)):
attacker.blocking = 'false'
eSub = attacker.weapon.damage - victim.armour.armourRating
return eSub
def defend(attacker=initAdventurer("无衣"), victim=randomEnemy(0)):
attacker.blocking = "true"
aAdd = attacker.shield.armourRating
safePer = random.random()
if safePer <= attacker.shield.percentage:
print("============格挡成功并眩晕了=========")
victim.stunned = "true"
else:
print("==============格挡失败,不眩晕===========")
victim.stunned = "false"
return aAdd
def usePotion(adv=initAdventurer("无衣"), enemy=randomEnemy(0)):
adv.blocking = 'false'
adv.showInventory()
while 1:
dex = input("请输入序号选择你要使用的物品(没有药的话用-1后退),战斗状态只能用药品,希望你不要不识好歹:")
if dex == "-1":
action(adv, enemy)
break
else:
dex = int(dex)
item = adv.inventory.items[dex - 1]
if "Potion" in item.name:
adv.inventory.items.pop(dex - 1)
if item.name == "healthPotion":
adv.hp += 200
if adv.hp > adv.maxHP:
adv.hp = adv.maxHP
if item.name == "damagePotion":
enemy.hp -= 50
if enemy.hp <= 0:
enemy.alive = "false"
break
else:
print("重新选!只能使用药品")
def runAway():
print("不要气馁,再试试能不能抽到较弱的怪兽,实在不行就自杀吧。")
怪物不能用药和逃跑,所以只有攻击和格挡
def enemyAction(enemy, adv):
aSub, eAdd = 0, 0
if enemy.stunned == 'true':
print("怪兽被你用盾牌格挡眩晕了,将跳过这回合")
enemy.stunned = 'false'
return aSub, eAdd
ran = random.randint(1, 2)
if ran == 1:
print("=======怪兽选择进攻======")
aSub = attack(enemy, adv)
if ran == 2:
print("=======怪兽选择格挡=====")
eAdd = defend(enemy, adv)
return aSub, eAdd
if enemy.blocking == 'false':
if adv.blocking == 'true':
if advSub > advAdd:
adv.hp = adv.hp - advSub + advAdd
elif advSub != 0:
adv.hp -= 1
else:
if advSub > 0:
adv.hp = adv.hp - advSub
elif advSub != 0:
adv.hp -= 1
else:
if adv.blocking == 'false':
if enemy.blocking == 'true':
if enemySub > enemyAdd:
enemy.hp = enemy.hp - enemySub + enemyAdd
elif enemySub != 0:
enemy.hp -= 1
else:
if enemySub > 0:
enemy.hp = enemy.hp - enemySub
elif enemySub != 0:
enemy.hp -= 1
else:
adv.showStatus()
enemy.showStatus()
adv.blocking = 'false'
enemy.blocking = 'false'
if adv.hp <= 0:
adv.alive = 'false'
if enemy.hp <= 0:
enemy.alive = 'false'
def inventoryManagement(adv, itemsList):
global enemyNum
print("===========================即将迎接下一个怪兽,请做好准备===================================================")
empty0 = adv.inventory.empty
while 1:
print("你有如下选择:")
print("1.挑选胜利奖品pick up items")
print("2.丢弃物品栏物品drop held items")
print("3.装备物品栏物品equip held items")
print("4.继续战斗fight next enemy")
choice = input("请输入你的胜利选择(-1表示退出):")
if choice == "1":
if win == 1:
if empty0 - adv.inventory.empty < 3:
actions.pickUpItem(adv, itemsList)
else:
print("你已经挑选了三个奖品了,请不要利用漏洞多选哦~")
else:
print("\n----------------你击败了怪兽吗就想领奖励?逃跑可是没有战利品的------------------\n")
elif choice == "2":
actions.dropItem(adv)
elif choice == "3":
actions.equipItem(adv)
elif choice == "4":
enemyNum += 1
battle(adv)
elif choice == '-1':
break
else:
print("输入指令无效,请重新输入:")
continue
def pickUpItem(adv, itemsList):
wNum = random.randint(0, 5)
sNum = random.randint(6, 11)
aNum = random.randint(12, 17)
potionNum = random.randint(18, 19)
winList = [itemsList[wNum], itemsList[sNum], itemsList[aNum], itemsList[potionNum]]
for i in range(len(winList)):
item = winList[i]
print(f"item{i + 1}:{item.name}")
for i in range(1, 4):
dex = input("请输入序号选择你要的物品(-1返回上一级表示你不要物品,将直接开始战斗):")
if dex == "-1":
break
elif len(re.findall("\d", dex)) == 0:
print("输入指令无效,请重新输入:")
continue
else:
ack = input("你确认要这件物品?(Y or N):")
if ack == "Y":
dex = int(dex)
item = winList[dex - 1]
adv.inventory.getItem(item)
else:
print("已取消捡起,请重新选择")
continue
def dropItem(adv=initAdventurer(" ")):
adv.showInventory()
while 1:
dex = input("请输入序号选择你要丢弃的物品(-1返回上一级):")
if dex == "-1":
break
else:
ack = input("你确认要丢这件物品?(Y or N)")
if ack == "Y":
dex = int(dex)
adv.inventory.items.pop(dex - 1)
else:
print("已取消丢弃,请重新选择")
continue
def equipItem(adv):
adv.showInventory()
while 1:
dex = input("请输入序号选择你要装备的物品(没有装备的话用-1后退),不能用药品,希望你不要不识好歹:")
if dex == "-1":
print("退出换装")
break
else:
dex = int(dex)
item = adv.inventory.items[dex - 1]
if "Potion" in item.name:
print("重新选!只能使用装备")
elif "sword" in item.name:
adv.inventory.dropItem(dex-1)
adv.inventory.getItem(adv.weapon)
adv.weapon = item
adv.showInventory()
continue
elif "shield" in item.name:
adv.inventory.dropItem(dex-1)
adv.inventory.getItem(adv.weapon)
adv.shield = item
adv.showInventory()
continue
elif "armour" in item.name:
adv.inventory.dropItem(dex-1)
adv.inventory.getItem(adv.weapon)
adv.armour = item
adv.showInventory()
continue
else:
print("这是bug,可能是我给装备改名字了")
elif choice == "4":
enemyNum += 1
battle(adv)
战斗结束条件
while adventurer.alive == "true":
if __name__ == '__main__':
enemyNum = 0
itemsList = getItemsList()
name = input("欢迎来到冒险岛,请为勇士创建一个名字:")
adventurer = initAdventurer(name)
adventurer.showHero()
print()
print("欢迎来到新世界,努力打倒敌人变得更强吧,勇士,请踏上你的征程!")
print("*****************************************************************")
print()
while adventurer.alive == "true":
enemyNum += 1
battle(adventurer)
inventoryManagement(adventurer, itemsList)
https://github.com/jz51/adventurer
武器: 攻击力 重量
Redsword 15 1
Orangesword 20 1.5
Yellowsword 30 2
Greensword 40 2.5
Cyansword 50 3
Bluesword 60 3.5
Purplesword 70 4
Lightsword 80 4.5
Darksword 90 5
Excalibur 100 1
盾牌: 防御值 重量 眩晕值
Redshield 10 1.5 0.1
Orangeshield 15 2 0.15
Yellowshield 20 2.5 0.2
Greenshield 30 3 0.25
Cyanshield 40 3.5 0.3
Blueshield 50 4 0.35
Purpleshield 60 4.5 0.4
Lightshield 70 5 0.45
Darkshield 80 5.5 0.5
Mirrorshield 90 6 0.6
盔甲: 防御值 重量
Redarmour 10 2
Orangearmour 15 2.5
Yellowarmour 20 3
Greenarmour 30 3.5
Cyanarmour 40 4
Bluearmour 50 4.5
Purplearmour 60 5
Lightarmour 70 5.5
Darkarmour 80 6
Goldenarmour 100 8
欢迎来到神秘岛:trade_mark:文字冒险游戏! 在异国情调的场景中移动并通过键入您的动作与它们进行交互:始终是动词,后接名词。 例如:“往北”,“往南”或“爬山”。 祝您探索顺利! 小心点
我的Python学习过程的一部分。
我想先和你谈谈一个项目一般是怎么完成的。更具体的说,程序员是如何思考和解决问题的呢?我认为其中一个很重要的能力是【问题拆解】。问题拆解,指的是在做一件事或面对一个问题的时候,将其拆解成多个步骤或多个层次,逐步执行和解决问题,直至达到最终效果。我会将完成一个项目的流程总结为以下三步:明确项目目标,是指我们希望程序达成什么目的,实现什么功能,从而帮我们将项目拆解成不同的单元;而一个妥当的拆解方案,难度适度递增,能帮我们逐步顺利执行,最终完成项目。这三个步骤可以说是环环相扣的。
python文字冒险游戏狼人之夜源代码,拥有6大结局和22大成就。道具对你来说,必不可少,而通关的旅途,更是出人意料!你,究竟能不能,在这月圆之夜,生存下去,拯救村庄?在这里,你是一个杰出的屠狼师,令狼人们闻风丧胆!月圆之夜,你是选择踏上征程,抑或是待在家里?
目录序言背景思路代码及解析跋文
最近都工作比较忙,还在备考【系统集成项目管理工程师】,所以一直没时间更新了,今天先分享分享之前开发过的文字游戏,前一段时间也一直想更新这款游戏,增加剧情啊,以及玩法啊等等,也是一直没时间,等考试结束了,准备着手开始开发。
一直以来还蛮喜欢玩文字游戏的,但是手机上的游戏要不就需要氪金,要不就是得刷刷刷,太累了。当时正好在学习Python,一不做二不休,干脆就自己开发一个咯。然后经过一段时间的设计,开发,测试,并有了现在这个【文字修仙】。
目前版本的界面如下:
AIDungeon2Read more about AIDungeon2 and how it was built here.Play the mobile app version of the game by following the links herePlay the game online by following this link herePlay the game in Colab...
该书三四五六章分别介绍用户输入、条件语句、函数、列表,直接跳到第七章:循环,因为例程包含了前几章的技术:func 玩 {库存 = ['匕首','金币(5)','面包棍']println("逃出生天!")loop {输入 = 获取命令()if ['n', 'N'].__contains__(输入) {println("往北!")} elif ['s', 'S'].__contains__(输入) {...