有趣的Python 用Python做一个跑团游戏

上效果(部分)

  • 交换商品

                

 

  • 作战

                

 

  • 劫掠

     

  • 使用药水

                

  •  查看人物属性

        

 

还有好多好多功能。。。。。。

上代码

role部分

from equipment import *
import numpy

def fight(team=[],target=[]):
    S,DS,AR,DR = 0,0,0,0
    AS,ADS,AAR,ADR = 0,0,0,0
    
    for t in team:
        S += t.ability[2]
        DS += t.ability[3]
        AR += t.ability[4]
        DR += t.ability[5]

    for t in target:
        AS += t.ability[2]
        ADS += t.ability[3]
        AAR += t.ability[4]
        ADR += t.ability[5]

    S -= AAR
    AS -= AR

    DS -= ADR
    ADS -= DR

    Value = 0
    
    if S >= AS:
        Value += S - AS
    else:
        Value -= AS - S

    if DS >= ADS:
        Value += 2 * (DS - ADS)
    else:
        Value -= 2 * (ADS - DS)

    if Value >= 0:
        return True
    else:
        return False


class roles():

    def __init__(self,kind="people",wallet=10):
        self.kind = kind
        self.wallet = wallet

    def report(self):
        print("name:"+self.name,end="    ")
        print("gender:"+self.gender,end="   ")
        print("age:"+self.age,end="   ")



    def report_self_equipments(self):
        nameab = ["A","I","S","DS","AR","DR"]
        for t in self.equipments:
            print(t.name,end=" #")
        for t in self.equipments:
            self.ability += t.Buff
        for i in range(len(self.ability)):
            print(str(nameab[i])+" "+str(self.ability[i]),end="  ")
        print("\n")

    def eat_food(self):
        FOOD = []
        Flag = True
        for t in self.equipments:
            if t.kind == "foods":
                Flag = False
                FOOD.append(t)
        for t in FOOD:
            print(t.name+" EAT OR NOT ",end="")
            flag = input("Y or N")
            if flag == "Y":
                self.ability += t.Buff
                print("YOU EAT IT !S:"+str(self.ability[2]))
                self.equipments.remove(t)
        FOOD.clear()
        if Flag:
            print("WARNING:YOU "+self.name+" HAVE NO FOODS")


    def drag(self):
        for t in self.equipments:
            if self.check_equipments(t):
                print(self.equipments)
                print("YOU MUST DRAG SOMETHING")
                try:
                    M = eval(input("INPUT THE THING WANT TO DRAG"))
                    self.equipments.remove(M)
                except:
                    continue
                
                print("DRAG SCUESSFULLY")




    def check_equipments(self,objection):
        countweapon,countarmor,countmeleeweapon = 0,0,0
        d = {}
        for t in self.equipments:
            if t.kind == "weapons":
                countweapon += 1
                d[t.kind] = countweapon
            elif t.kind == "armor":
                countarmor += 1
                d[t.kind] = countweapon
            elif t.kind == "meleeweapon":
                countmeleeweapon += 1
                d[t.kind] = countweapon
        try:
            if d[objection.kind] == 0:    
                return False
            else:
                print("YOU, "+self.name+" CAN HAVE ONLY A "+objection.kind)
                return True 
        except:
            pass



    def report_strength(self):
        print("A NEW DAY,AFTER HARD WORKING,YOU "+self.name+" GET A DECREASE IN S")
        self.ability[2] -= 1
        print(self.name+" "+"'s S IS "+str(self.ability[2]))
        self.eat_food()
        if self.ability[2] < -2:
            print("SORRY TO TELL YOU,YOUR DEAR PARTNERS "+self.name+" IS DEAD")
            print("TRY TO SAVE HIM IN THE FUTURE")
            return True
        else:
            return False

    def exchange(self,B,t):
        print(self.name+" WANT TO EXCHANGE "+t.name+" WITH "+B.name)
        print("DEAR "+self.name+" PLEASE INPUT YOUR OFFER!(integer)",end="")
        while True:
            try:
                M = int(input())
                print("DEAR "+B.name+" PLEASE INPUT YOUR WILL!(Y/N)",end="")
                flag = input()
                if flag == "Y" and self.wallet >= M and t in B.equipments :  
                    self.wallet -= M
                    B.wallet += M
                    B.equipments.remove(t)
                    self.equipments.append(t)
                    print("SUCESSFUL TEADE!")
                    break
                else:
                    print("UNSUCESSFUL TRADE")
                    break
            except:
                print("DEAR "+self.name+" PLEASE INPUT YOUR OFFER!#F TO EXIT",end="")


    def tran_accounts(self,target):
        print(self.name+" WANT TO TRANSFER MONEY TO "+target.name)
        print(self.name+" PLEASE INPUT HOW MUCH YOU WANT TO TRANSFER",end="")
        while True:
            try:
                M = int(input())
                if self.wallet >= M:
                    self.wallet -= M
                    target.wallet += M
                    print("TRANSFER SUCESSFULLY")
                    break
                else:
                    print("INSUFFICIENT BALANCE")
                    continue
            except:
                print(self.name+" PLEASE INPUT HOW MUCH YOU WANT TO TRANSFER(F TO EXIT)",end="")
                if input() == "F":
                    print("END,TRANSFER FAILED")
                    break
            

class robber(roles):

    def __init__(self,name="robber",gender="male",age=18,ability=np.zeros(6),equipments = [ordinarysword1,ordinarysword1,smallbread1]):

        ability[0] = 3
        ability[1] = 1
        ability[2] = 5

        roles.__init__(self)
        self.equipments = equipments
        self.ability = ability
        self.name = name
        self.gender = gender
        self.age = age

    def rob(self,target):
        if self.ability[0] >= target.ability[0] and target.equipments != []:
            print(self.name+" ROB SUCESSFULLY! ")
            t = random.choice(target.equipments)
            self.equipments.append(t)
            target.equipments.remove(t)
            print(self.name+" rob a "+t.name)
            print(target.name+" loss a "+t.name)
            return True
        else:
            print(self.name+" ROB UNSCESSFULLY! ")
            return False
        


class knight(roles):
    def __init__(self,name="knight",gender="male",age=18,ability=np.zeros(6),equipments = [ordinarysword1,smallbread1]):

        ability[0] = 2
        ability[1] = 1
        ability[2] = 7
        ability[3] = 3
        ability[5] = 3

        roles.__init__(self)
        self.equipments = equipments
        self.ability = ability
        self.name = name
        self.gender = gender
        self.age = age

    def rush(self,N=True):
        print("IF RUSH:S DECREASE 2 ;A INCREASE 3")
        print(self.name+" INPUT Y TO RUSH OTHER TO EXIT",end="")
        T = input()
        if N and T == "Y":
            ability[2] -= 2
            ability[0] += 3
        else:
            print("WILL NOT RUSH")


        

class alchemist(roles):
    def __init__(self,name="alchemist",gender="male",age=18,ability=np.zeros(6),equipments = [poison,Health_Potion,smallbread1]):

        ability[0] = 1
        ability[1] = 3
        ability[2] = 5
        ability[5] = 3

        roles.__init__(self)
        self.equipments = equipments
        self.ability = ability
        self.name = name
        self.gender = gender
        self.age = age

    def use_potion(self,target):
        while True:
            print("INPUT THE POTION YOU WANT TO USE(F TO EXIT)",end="")
            n = input()
            if n == "F":
                print("USE END")
                break
            for t in self.equipments:
                if t.name == n:
                    self.equipments.remove(t)
                    target.ability += t.Buff
                    print("HAVE USED THE "+t.name+" TO "+target.name)
                    break
                
    
    def make_potion(self):
        for i in range(3):
            print("THE "+str(i+1)+"th TRY:")
            print(self.name+",YOU WANT TO MAKE WHAT POTION")
            n = input()
            for t in [poison,adv_poison,Health_Potion]:
                if n == t.name and self.ability[2]>=random.randrange(1,9,1):
                    print("MAKE SUCESSFULLY "+t.name)
                    self.equipments.append(t)
           

class assassin(roles):
    def __init__(self,name="assassin",gender="male",age=18,ability=np.zeros(6),equipments = [poison,Health_Potion,smallbread1]):

        ability[0] = 2
        ability[1] = 2
        ability[2] = 5

        roles.__init__(self)
        self.equipments = equipments
        self.ability = ability
        self.name = name
        self.gender = gender
        self.age = age

    def assassinate(self):
        print("NOTHING HAPPEDED!! HAHA!")
        

        

class craftsman(roles):
    def __init__(self,name="craftsman",gender="male",age=18,ability=np.zeros(6),equipments = [ordinarysword1,smallbread1]):

        ability[0] = 1
        ability[1] = 2
        ability[2] = 2
        ability[4] = 3

        roles.__init__(self)
        self.equipments = equipments
        self.ability = ability
        self.name = name
        self.gender = gender
        self.age = age

class peasant(roles):
    def __init__(self,name="peasant",gender="male",age=18,ability=np.zeros(6),equipments = [ordinarysword1,smallbread1]):

        ability[0] = 1
        ability[1] = 2
        ability[2] = 2

        roles.__init__(self)
        self.equipments = equipments
        self.ability = ability
        self.name = name
        self.gender = gender
        self.age = age

class merchant(roles):
    def __init__(self,name="merchant",gender="male",age=18,ability=np.zeros(6),equipments = [ordinarysword1,smallbread1]):

        ability[0] = 1
        ability[1] = 5
        ability[2] = 1

        roles.__init__(self)
        self.equipments = equipments
        self.ability = ability
        self.name = name
        self.gender = gender
        self.age = age

class soldier(roles):
    def __init__(self,name="soldier",gender="male",age=18,ability=np.zeros(6),equipments = [ordinarysword1,smallbread1]):

        ability[0] = 1
        ability[1] = 1
        ability[2] = 5
        ability[4] = 2
        ability[5] = 2

        roles.__init__(self)
        self.equipments = equipments
        self.ability = ability
        self.name = name
        self.gender = gender
        self.age = age

equipment部分

import numpy as np
import random

class sword():

    def __init__(self,kind="weapons"):
        self.kind = kind

    def tell_us(self):
        print(dir(self))


class ordinarysword(sword):

    def __init__(self,name="ordinarysword",Buff=np.zeros(6),value=0):
       Buff[2] = 3
       
       sword.__init__(self)
       self.Buff = Buff
       self.value = random.randrange(5,10,1)
       self.name = name



ordinarysword1 = ordinarysword(name="ordinarysword1")
#############sword##########
class armor():

    def __init__(self,name,value,Buff,kind="armor"):
        self.kind = kind
        self.value = value
        self.Buff = Buff
        self.name = name

    def tell_us(self):
        print(dir(self))

class meleeweapon():

    def __init__(self,name,value,Buff,kind="meleeweapon"):
        self.kind = kind
        self.value = value
        self.Buff = Buff
        self.name = name

    def tell_us(self):
        print(dir(self))

lightarmor = armor(name="lightarmor",value=6,Buff=np.array([-1,0,0,0,3,1]))
adv_armor = armor(name="adv_armor",value=12,Buff=np.array([0,1,-1,0,5,2]))
glove = armor(name="glove",value=5,Buff=np.array([1,1,0,0,2,1]))
fly_cutter = meleeweapon(name="fly_cutter",value=4,Buff=np.array([3,0,1,0,0,0]))
dagger = meleeweapon(name="dagger",value=3,Buff=np.array([2,0,1,0,0,0]))

########potion###################
class potion():

    def __init__(self,name,value,kind="potions",Buff=np.zeros(6)):
        self.kind = kind
        self.Buff = Buff
        self.name = name
        self.value = value
        
    def tell_us(self):
        print(dir(self))

poison = potion(Buff=np.array([0,0,-5,-5,0,0]),name="poison",value=random.randrange(5,10,1))
adv_poison = potion(Buff=np.array([0,0,-10,-10,0,0]),name="adv_poison",value=random.randrange(15,20,1))
Health_Potion = potion(Buff=np.array([0,0,5,0,0,0]),name="Health_Potion",value=random.randrange(5,10,1))
Inte_Potion = potion(Buff=np.array([0,5,0,0,0,0]),name="Inte_Potion",value=random.randrange(5,20,1))

#########potion###################
    
class wand():

    def __init__(self,name,value,kind="weapons",Buff=np.zeros(6)):

        self.kind = kind
        self.name = name
        self.Buff = Buff
        self.value = value

    def tell_us(self):
        print(dir(self))

ordinarywand = wand(name="ordinarywand",value = 10,Buff=np.array([1,1,4,5,0,2]))
adv_wand = wand(name="adv_wand",value = 25,Buff=np.array([2,2,6,15,4,6]))

###########food#####################    
class food():

    def __init__(self,kind="foods"):
        self.kind = kind

    def tell_us(self):
        print(dir(self))

class smallbread(food):

    def __init__(self,name="smallbread",Buff=np.zeros(6),value=1):
        Buff[2] = 3

        food.__init__(self)
        self.Buff = Buff
        self.value = 1
        self.name = name

    def tell_us(self):
        print(dir(self))
        
smallbread1 = smallbread(name="smallbread1")
bigbread = smallbread(name="bigbread",Buff=np.array([0,0,5,0,0,0]),value=2)
fish = smallbread(name="fish",Buff=np.array([0,0,4,0,0,0]),value=1)
jerky = smallbread(name="jerky",Buff=np.array([0,0,6,0,0,0]),value=2)
###########food###############
class knapsack():

    def __init__(self,name):

        pass
        

occurence部分

import numpy as np

class weathers():

    def __init__(self,kind="weather"):
        self.kind = kind
        
class rainy_day(weathers):

    def __init__(self,ability = np.zeros(6)):

        ability[0] = -2
        ability[1] = -1
        ability[2] = -2
        ability[3] = -1
        ability[4] = -1
        ability[5] = -1

        self.ability = ability
        
class hot_day(weathers):

    def __init__(self,ability = np.zeros(6)):

        ability[0] = -1
        ability[1] = -1
        ability[2] = -4
        ability[3] = -1
        ability[4] = -2
        ability[5] = 0

        self.ability = ability

class windy_day(weathers):

    def __init__(self,ability = np.zeros(6)):

        ability[0] = -1
        ability[3] = -1

        self.ability = ability 
###############weather#####################
class locations():

    def __init__(self,kind="location"):
        self.kind = kind

class Castle():

    def __init__(self,ability = np.zeros(6)):

        
        self.ability = ability

class jail():

    def __init__(self,ability = np.zeros(6)):
        ability[0] = -2
        ability[1] = -2
        ability[2] = -2

        self.ability = ability 

class plant():

    def __init__(self,ability = np.zeros(6)):
        ability[2] = -1
        ability[4] = -1
        ability[5] = -1

        self.ability = ability         

main部分

from role import *
from occurrence import *
import random
import numpy as np

C = robber()
#C.report_self_equipments()
#C.report_strength()
B = knight()
A = alchemist()
D = assassin()


rainy = rainy_day()
hot = hot_day()
windy = windy_day()

king_castle = Castle()

TEAM = [C,B]
WEATHER = [rainy,hot,windy]


#C.exchange(B,ordinarysword1)
#exec(input())
while True:
    print("executing program")
    c = eval(input())
    print(c)

当然啦,这个游戏不够完整,游戏情节完全可以由读者自行设计,有任何想法都可以留言交流哦!

欢迎欢迎!!

游戏基本理念

!原则
A    I    S    DS    AR    DR    

游戏经过
    每回合开始前,先计算每个人物的A,I,S,AR,DR值
        然后每个人物的S值均会-1,吃饭判定,小于-2即死亡

    S战斗部分
        A 判定获得攻击权
            攻击者A总和
        
        S 判定攻击成功
            攻击者S总和-被攻击者AR总和
            被攻击者S总和-攻击者AR总和

    DS战斗部分
        DS 判定成功    
            攻击者DS总和-被攻击者DR总和
            被攻击者DS总和-攻击者DR总和

    盗窃部分
        盗窃者A总和判定

    炼金部分
        炼金术士I总和判定    


    玩家需要通过国王城堡到达叛军城堡
    从叛军城堡攻回到国王城堡
    
    


游戏地点
            A    I    S    AR    DR    DS
    国王城堡    0    0    0    0    0    0
    监狱        -2    -2    -2    0    0    0
    原野1        0    0    -1    -1    -1    0
    原野2        -1    0    0    0    0    0    
    原野3        -1    0    0    0    -1    0
    湖泊东岸    -1    0    0    -1    -1    0
    湖泊西岸    -1    0    -1    0    0    0
    桥梁        0    0    1    0    0    0
    森林1        -2    -2    -2    0    -1    0
    森林2        -1    -1    -1    0    0    0    
    小溪        -2    0    0    0    0    0
    原野4        -1    0    0    0    0    0
    反抗军堡垒    0    0    0    0    0    0
    
    
    


游戏人物

    人物属性
        敏捷Agile            可正可负
        智力Intelligence        可正可负
        体力Strength        不能小于-2
        
        装甲防护Armor-Resistance
        魔法防护Devil-Resistance

        背包knapsack
        
        
                A    I    S    AR    DR    Special skills        DS
    盗贼            3    1    5    0    0                    0
    炼金术士        1    3    5    0    3                    3
    骑士            2    1    7    2    0                    0
    刺客            2    2    5    0    0                    0
    
    工匠            1    2    2    3    0    生产装备    交易商品    0
    农民            1    2    2    0    0    生产食物    交易商品    0
    商人            1    5    1    0    0    交易商品            0
    士兵            1    1    5    2    2                    0
    

游戏装备
                A    I    S    AR    DR    Speciall skills        value        DS
    高级宝剑        1    1    5    1    0                    15>10    0
    普通宝剑        0    0    3    0    0                    10>5        0
    
    铠甲            -1    0    0    3    1                    8>4        0
    高级铠甲        0    1    -1    5    2                    16>8        0
    手套            1    1    0    2    1                    6>3        0

    飞刀            3    0    1    0    0                    6>3        0    
    匕首            2    0    1    0    0                    4>2        0    

    魔杖            1    1    4    0    2                    25>15    5
    高级魔杖        2    2    6    4    6                    40>30    15
    
    毒药            0    0    -5    0    0    单回合对单对象        10>5        -5
    高级毒药        0    0    -10    0    0    单回合对单对象        20>15    -10
    生命药水        0    0    5    0    0    将任一对象S值提升至2    10>5        0
    敏捷药水        5    0    0    0    0    单回合对单对象有效    10>5        0
    智力药水        0    5    0    0    0    单回合对单对象有效    20>5        0
    魔法药水        0    0    0    0    5                    20>5        5
        
    小麦面包        0    0    3    0    0                    1        0
    大面包        0    0    5    0    0                    2        0
    鱼肉            0    0    4    0    0                    1        0    
    肉干            0    0    6    0    0                    2        1

    背包            -1    0    -1    0    0    20                5        0
    大背包        -2    0    -2    0    0    20                7        0

    金币                                

游戏随机事件
    天气
                A    I    S    AR    DR    DS
        下雨        -2    -1    -2    -1    -1    -1
        高温        -1    -1    -4    -2    0    -1
        狂风        -1    0    0    0    0    -1
        
    队伍
        内讧        -5    -5    -5    -5    -5
        集体主义    1    1    1    1    1
        被偷窃
        召集
        感化    
        
    随机人物
        商人
            所有

        农民
            仅粮食

        士兵
            不忠诚的士兵
                所有
            忠诚的士兵
                仅战斗掉落

        工匠
            仅装备

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

River Chandler

谢谢,我会更努力学习工作的!!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值