Meleuo

Python 命令行小游戏
Python新手,代码写的很渣,见笑(PS:视频约14MB)
扫描右侧二维码阅读全文
02
2019/07

Python 命令行小游戏


代码

#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Author:Meleuo
# Blog:www.zheli.ink
import  time
import random
import re
hero_list = [("战士","5000","1000","战士这个职业具有综合性作战能力"),
             ("法师","4000","2000","法师具有强大的攻击力,但是生命值比较低"),
             ("肉盾","7000","800","人如其名,肉盾具有非常多的生命值,但攻击力是他的软肋")]
Map = {"峡谷": ("BOSS:恶龙", "生命值5000", "攻击力1300", "攻击成功可能性60%",),
       "荒漠": ("BOSS:鳄鱼", "生命值7000", "攻击力1800", "攻击成功可能性50%"),
       "海洋": ("BOOS:鲲鹏", "生命值9000", "攻击力2000", "攻击成功可能性40%"),
       "地狱": ("BOOS:撒旦", "生命值10000", "攻击力3000", "攻击成功可能性30%")}
local_hero = []
gemstone = 5
def Division():
    """分割线"""
    print("=====================================")
    return
def scene0():
    '''人物简介'''
    Division()
    hero_subscript = 1
    if  hero_subscript <= 4:
        for i in hero_list:
            print(hero_subscript,":",i[0],"\n简介:",i[3])
            hero_subscript +=1
    return
def scene():
    '''场景选择'''
    Division()
    print("请选择你要进入的场景")
    print("1:使用能量宝石强化自己,PS:能量宝石有50%的可能性随机提升你的攻击力和生命值\n","\033[1;31m宝石数量剩余:", gemstone,"\033[0m"
          "\n2:进入BOSS场景,于BOSS进行战斗,每次战斗胜利都将获得5个能量宝石\n",
          "\n3:查看英雄属性")
    return
def scene2():
    '''地图打印'''
    Division()
    map_subscript = 1
    for key in Map:
        print(map_subscript,": 地图", key)
        map_subscript += 1
        for i in Map[key]:
            print("\033[1;32m", i, "\033[0m")
    return
def fighting_start(Getinto):
    '''战斗过程'''
    global gemstone
    boss_life = int(re.sub("\D", "", Map_list[Getinto][1]))
    boss_fighting = int(re.sub("\D", "", Map_list[Getinto][2]))
    boss_probability = int(re.sub("\D", "", Map_list[Getinto][3]))
    subscript = "1"
    print("开始攻击")
    Division()
    time.sleep(0.5)
    while True:
        Progress_bar = "\n正在进行第"
        fighting = Progress_bar + subscript + "次攻击"
        for i in range(25):
            print(fighting, end='')
            time.sleep(0.05)
            fighting = ">"
        random4 = random.randint(0, 100)
     #   print(random4)
        if random4 <= boss_probability:
            print("\033[5;32m 攻击成功 \033[0m")
            boss_life = boss_life - (int(local_hero[2]))
            if boss_life > 0:
                print("BOSS当前血量",boss_life)
            else:
                print('''
                恭喜你骚年,你成功的击杀了BOSS
                这是你应得的奖励;5颗能量宝石
                      ☼ ☼ ☼ ☼ ☼
                ''')
                gemstone += 5
                break
        else:
            print("\033[1;31m sorry啊~ 攻击失败\033[0m")
            local_hero[1] = (int(local_hero[1]) - boss_fighting)
            if local_hero[1]  > 0:
                print("你当前生命值",local_hero[1])
            else:
                print("骚年,你凉了~~~bay~~~")
                local_hero[1] = 0
                break

        subscript = int(subscript)
        subscript += 1
        subscript = str(subscript)

#  程序开始
print("\033[1;32m =====欢迎来到召唤峡谷,召唤师===== \033[0m")
print("============全局支持q退出============")

print("\033[1;33m 请选择你的英雄 \033[0m")

while True:
    scene0()
    hero =  input("本局你选择的英雄是: ")
    hero2 = hero
    if hero2.isdigit():
        hero = int(hero2)
        subscript = hero - 1
        Division()
        local_hero.append(hero_list[subscript][0])
        local_hero.append(hero_list[subscript][1])
        local_hero.append(hero_list[subscript][2])
        print("你的英雄是:",local_hero[0],
              "\n生命值:",local_hero[1],
              "\n攻击力:",local_hero[2])

        Division()
        while True:
            scene()
            Getinto =  input("你的场景是:")
            Getinto2 = Getinto
            if  Getinto2.isdigit():
                Getinto = int(Getinto2)
                if Getinto == 1:
                    print("宝石剩余:", gemstone, "确认强化嘛")
                    if gemstone <= 0:
                        print("sorry 你没有宝石了")
                        continue
                   # confirm1 = input("\033[1;34m 任意键确认,n返回上级: \033[0m")
                   #  if confirm1 == "n":
                   #      continue
                   #  else:
                    gemstone -= 1
                    print("你的当前的英雄是:", local_hero[0],
                          "\n生命值:", local_hero[1],
                          "\n攻击力:", local_hero[2])
                    random1 = random.randint(0, 1)
                    random2 = random.randint(500,3000)
                    random3 = random.randint(300,700)
                    if random1 == 1:
                        local_hero[1] = (int(local_hero[1]) + random2)
                        local_hero[2] = (int(local_hero[2]) + random3)
                        Progress_bar = "[强化中]"
                        for i in range(20):
                            print(Progress_bar, end='')
                            time.sleep(0.05)
                            Progress_bar = ">"
                        print("\033[1;31m 强化成功\033[0m")
                        print("\033[2;32m 你的生命值提升了 %a \033[2;31m 总生命值 %a \033[0m \n \033[2;32m你的攻击力提升了 %a \033[2;31m 总攻击力 %a \033[0m"
                              % (random2,local_hero[1],random3,local_hero[2]) )
                        print("你的宝石剩余",gemstone)
                    else:
                        print("\033[1;31m sorry啊~,强化失败\033[0m ")
                    time.sleep(0.5)
                elif Getinto == 2:
                    scene2()
                    Getinto = input("选择你要进入的地图:")
                    Getinto2 = Getinto
                    Map_list = list(Map.values())
                    if Getinto2.isdigit():
                        Getinto = int(Getinto2) - 1
                       # print(Map_list[Getinto])

                        Progress_bar = "[正在进入]"
                        Division()
                        for i in range(30):
                            print(Progress_bar, end='')
                            time.sleep(0.06)
                            Progress_bar = ">"
                        print("\n \033[;31m准备好了小老弟!\n",
                              Map_list[Getinto][3],
                              "\n 攻击失败受到伤害的就是你"
                              "\n 挑战成功后可以获得5颗能量宝石\033[0m")
                        fighting_start(Getinto = Getinto)
                    else:
                        print("error4")
                elif Getinto == 3:
                    print("你的英雄是:", local_hero[0],
                          "\n生命值:", local_hero[1],
                          "\n攻击力:", local_hero[2])
                else:
                    print("error3")
            elif Getinto2 == "q":
                print("bay~~")
                gemstone = 5
                local_hero = []
                break
            else:
                pass
    elif hero ==  "q":
        print("bay~~~~")
        exit()
    else:
        pass

Last modification:July 2nd, 2019 at 11:16 pm
如果觉得我的文章对你有用,请随意赞赏

Leave a Comment