Loading... # 输入与while循环 ## 用这章学的东西捣鼓的玩意 究极简化版,Dragon Star Varnir原版的战斗系统是立体,有技能,有大招,能变身,有替补队员的(总共三队一前一后)。 到了我这就变成了只有前排,普攻与回血的小玩意。BOSS也人畜无害。 ![2023-01-20-12-58-36.webp](https://lolisis.com/usr/uploads/2023/01/1064850645.webp) <!--more--> ``` name_, health_, damage_, speed_ = "name", "health", "damage", "speed" boss = { name_: "BOSS", health_: 1000, damage_: 50, speed_: 5, } dragons = { "zephy":{ name_: "Zehpy", health_: 200, damage_: 50, speed_: 4, }, "charlotta":{ name_: "Charlotta", health_: 100, damage_: 100, speed_: 6, }, "minessa": { name_: "Minessa", health_: 150, damage_: 40, speed_: 3, }, "karikaro": { name_: "Karikaro", health_: 130, damage_: 50, speed_: 4, }, "laponette": { name_: "Laponette", health_: 80, damage_: 30, speed_: 1, }, "faria": { name_: "Faria", health_: 150, damage_: 40, speed_: 4, } } game_over = False all_dragons = [] message = "These are available dragons:\n" for dragon, info in dragons.items(): message += f"{info[name_]}\t" all_dragons.append(dragon.lower()) message += "\n输入名称来选择上前排的角色,总共3个,输入default选择默认\n" print(message) front_line = [] while len(front_line) < 3: dragon = input() if dragon.lower() in all_dragons: front_line.append(dragon.lower()) print(f"{dragons[dragon][name_]} added") elif dragon.lower() == "default": front_line = all_dragons[:3] else: print("Invalid input, please input again.") message = "Front line dragons:\n" for dragon in front_line: message += f"{dragon.title()}\t" print (message) dead_dragon = [] dragon_status = {} for dragon in all_dragons: dragon_status[dragon] = [0, dragons[dragon][health_]] # 第一个是移动值,第二个是血量 boss_move = 0 boss_health = boss[health_] while game_over != True: boss_move += 1 for character in front_line: dragon_status[character][0] += 1 print(f"Step {boss_move}") ## boss 活动 if boss_move % boss[speed_] == 0: print("BOSS turn starts:") for dragon in front_line: dragon_status[dragon][1] -= boss[damage_] print(f"\t{dragons[dragon][name_]} got {boss[damage_]} damage") if dragon_status[dragon][1] <= 0: print(f"\t{dragons[dragon][name_]} dead.") front_line.remove(dragon) dead_dragon.append(dragon) if front_line: print("BOSS turn over.\n") else: game_over = True You_win = False break ## 玩家活动 you_win = False for character in front_line: ##不能与下面其它for循环冲突,比如都用dragon,不然就出错 ##这里出了不少bug if you_win == True: break ##另外可以用continue跳过当前循环 if dragon_status[character][0] % dragons[character][speed_] == 0: print(f"\tBOSS HEALTH: {boss_health}") for dragon in front_line:## print(f"\t{dragons[dragon][name_]} \tHEALTH: {dragon_status[dragon][1]}\t DAMAGE: {dragons[dragon][damage_]}") print(f"轮到{dragons[character][name_]}行动\n输入1 攻击,输入2全体回复:") if int(input()) == 1: boss_health -= dragons[character][damage_] print(f"\tBOSS get {dragons[character][damage_]} damage") if boss_health <= 0: game_over = True you_win = True print("BOSS DEAD") break else: for dragon_recover in front_line: dragon_status[dragon_recover][1] += dragons[character][damage_] if dragon_status[dragon_recover][1] > dragons[dragon_recover][health_]: dragon_status[dragon_recover][1] = dragons[dragon_recover][health_] if you_win == True: print("Congratulations! You win") else: print("Oh no, You lose") ``` 结果 ``` These are available dragons: Zehpy Charlotta Minessa Karikaro Laponette Faria 输入名称来选择上前排的角色,总共3个,输入default选择默认 default Front line dragons: Zephy Charlotta Minessa Step 1 Step 2 Step 3 BOSS HEALTH: 1000 Zehpy HEALTH: 200 DAMAGE: 50 Charlotta HEALTH: 100 DAMAGE: 100 Minessa HEALTH: 150 DAMAGE: 40 轮到Minessa行动 输入1 攻击,输入2全体回复: 1 BOSS get 40 damage Step 4 BOSS HEALTH: 960 Zehpy HEALTH: 200 DAMAGE: 50 Charlotta HEALTH: 100 DAMAGE: 100 Minessa HEALTH: 150 DAMAGE: 40 轮到Zehpy行动 输入1 攻击,输入2全体回复: 1 BOSS get 50 damage Step 5 BOSS turn starts: Zehpy got 50 damage Charlotta got 50 damage Minessa got 50 damage BOSS turn over. Step 6 BOSS HEALTH: 910 Zehpy HEALTH: 150 DAMAGE: 50 Charlotta HEALTH: 50 DAMAGE: 100 Minessa HEALTH: 100 DAMAGE: 40 轮到Charlotta行动 输入1 攻击,输入2全体回复: 1 BOSS get 100 damage BOSS HEALTH: 810 Zehpy HEALTH: 150 DAMAGE: 50 Charlotta HEALTH: 50 DAMAGE: 100 Minessa HEALTH: 100 DAMAGE: 40 轮到Minessa行动 输入1 攻击,输入2全体回复: 2 Step 7 Step 8 BOSS HEALTH: 810 Zehpy HEALTH: 190 DAMAGE: 50 Charlotta HEALTH: 90 DAMAGE: 100 Minessa HEALTH: 140 DAMAGE: 40 轮到Zehpy行动 输入1 攻击,输入2全体回复: 1 BOSS get 50 damage Step 9 BOSS HEALTH: 760 Zehpy HEALTH: 190 DAMAGE: 50 Charlotta HEALTH: 90 DAMAGE: 100 Minessa HEALTH: 140 DAMAGE: 40 轮到Minessa行动 输入1 攻击,输入2全体回复: 1 BOSS get 40 damage Step 10 BOSS turn starts: Zehpy got 50 damage Charlotta got 50 damage Minessa got 50 damage BOSS turn over. Step 11 Step 12 BOSS HEALTH: 720 Zehpy HEALTH: 140 DAMAGE: 50 Charlotta HEALTH: 40 DAMAGE: 100 Minessa HEALTH: 90 DAMAGE: 40 轮到Zehpy行动 输入1 攻击,输入2全体回复: 2 BOSS HEALTH: 720 Zehpy HEALTH: 190 DAMAGE: 50 Charlotta HEALTH: 90 DAMAGE: 100 Minessa HEALTH: 140 DAMAGE: 40 轮到Charlotta行动 输入1 攻击,输入2全体回复: 1 BOSS get 100 damage BOSS HEALTH: 620 Zehpy HEALTH: 190 DAMAGE: 50 Charlotta HEALTH: 90 DAMAGE: 100 Minessa HEALTH: 140 DAMAGE: 40 轮到Minessa行动 输入1 攻击,输入2全体回复: 1 BOSS get 40 damage Step 13 Step 14 Step 15 BOSS turn starts: Zehpy got 50 damage Charlotta got 50 damage Minessa got 50 damage BOSS turn over. BOSS HEALTH: 580 Zehpy HEALTH: 140 DAMAGE: 50 Charlotta HEALTH: 40 DAMAGE: 100 Minessa HEALTH: 90 DAMAGE: 40 轮到Minessa行动 输入1 攻击,输入2全体回复: 2 Step 16 BOSS HEALTH: 580 Zehpy HEALTH: 180 DAMAGE: 50 Charlotta HEALTH: 80 DAMAGE: 100 Minessa HEALTH: 130 DAMAGE: 40 轮到Zehpy行动 输入1 攻击,输入2全体回复: 1 BOSS get 50 damage Step 17 Step 18 BOSS HEALTH: 530 Zehpy HEALTH: 180 DAMAGE: 50 Charlotta HEALTH: 80 DAMAGE: 100 Minessa HEALTH: 130 DAMAGE: 40 轮到Charlotta行动 输入1 攻击,输入2全体回复: 1 BOSS get 100 damage BOSS HEALTH: 430 Zehpy HEALTH: 180 DAMAGE: 50 Charlotta HEALTH: 80 DAMAGE: 100 Minessa HEALTH: 130 DAMAGE: 40 轮到Minessa行动 输入1 攻击,输入2全体回复: 1 BOSS get 40 damage Step 19 Step 20 BOSS turn starts: Zehpy got 50 damage Charlotta got 50 damage Minessa got 50 damage BOSS turn over. BOSS HEALTH: 390 Zehpy HEALTH: 130 DAMAGE: 50 Charlotta HEALTH: 30 DAMAGE: 100 Minessa HEALTH: 80 DAMAGE: 40 轮到Zehpy行动 输入1 攻击,输入2全体回复: 2 Step 21 BOSS HEALTH: 390 Zehpy HEALTH: 180 DAMAGE: 50 Charlotta HEALTH: 80 DAMAGE: 100 Minessa HEALTH: 130 DAMAGE: 40 轮到Minessa行动 输入1 攻击,输入2全体回复: 1 BOSS get 40 damage Step 22 Step 23 Step 24 BOSS HEALTH: 350 Zehpy HEALTH: 180 DAMAGE: 50 Charlotta HEALTH: 80 DAMAGE: 100 Minessa HEALTH: 130 DAMAGE: 40 轮到Zehpy行动 输入1 攻击,输入2全体回复: 1 BOSS get 50 damage BOSS HEALTH: 300 Zehpy HEALTH: 180 DAMAGE: 50 Charlotta HEALTH: 80 DAMAGE: 100 Minessa HEALTH: 130 DAMAGE: 40 轮到Charlotta行动 输入1 攻击,输入2全体回复: 1 BOSS get 100 damage BOSS HEALTH: 200 Zehpy HEALTH: 180 DAMAGE: 50 Charlotta HEALTH: 80 DAMAGE: 100 Minessa HEALTH: 130 DAMAGE: 40 轮到Minessa行动 输入1 攻击,输入2全体回复: 1 BOSS get 40 damage Step 25 BOSS turn starts: Zehpy got 50 damage Charlotta got 50 damage Minessa got 50 damage BOSS turn over. Step 26 Step 27 BOSS HEALTH: 160 Zehpy HEALTH: 130 DAMAGE: 50 Charlotta HEALTH: 30 DAMAGE: 100 Minessa HEALTH: 80 DAMAGE: 40 轮到Minessa行动 输入1 攻击,输入2全体回复: 1 BOSS get 40 damage Step 28 BOSS HEALTH: 120 Zehpy HEALTH: 130 DAMAGE: 50 Charlotta HEALTH: 30 DAMAGE: 100 Minessa HEALTH: 80 DAMAGE: 40 轮到Zehpy行动 输入1 攻击,输入2全体回复: 1 BOSS get 50 damage Step 29 Step 30 BOSS turn starts: Zehpy got 50 damage Charlotta got 50 damage Charlotta dead. BOSS turn over. BOSS HEALTH: 70 Zehpy HEALTH: 80 DAMAGE: 50 Minessa HEALTH: 80 DAMAGE: 40 轮到Minessa行动 输入1 攻击,输入2全体回复: 1 BOSS get 40 damage Step 31 Step 32 BOSS HEALTH: 30 Zehpy HEALTH: 80 DAMAGE: 50 Minessa HEALTH: 80 DAMAGE: 40 轮到Zehpy行动 输入1 攻击,输入2全体回复: 1 BOSS get 50 damage BOSS DEAD Congratulations! You win ``` ## 在这里面没用上的 **使用用户输入填充字典** ``` while active == True: key = input() value = input() responses[key] = value print("Continue?yes/no") if repeat == "no": active = False ``` 没验证。书上有 **删除为特定值的所有列表** ``` while "cat" in pets: pets.remove("cat") ``` Last modification:January 20, 2023 © Allow specification reprint Like 1 如果觉得我的文章对你有用,请留下评论。