Python实验-大富翁(伪)

# 规则
'''
1、游戏开始
每位玩家有1500元作为资产或每位玩家有15000元作为资产
2、掷骰
每次同时掷出两颗骰子,两颗骰子的点数相同的话可以多一个回合,若在此回合入狱,则多出来的回合取消。连续三次点数相同直接入狱。
3、物业
玩家到达无人拥有的地皮,玩家可选择要不要购买。如不买则银行立刻拍卖之。银行的钱是无限,但建筑物有限(32间房子及12间旅馆)。玩家之间可以进行金钱、物业和保释卡之间的交易。
4、房子与旅馆
如拥有全部同色未抵押地皮,则可以在任何玩家掷骰前选择盖房子,因掷出相同点数而得额外的回合除外。房子必须盖在同组中目前房子最少的地上,也就是说房子得平均地盖。
5、套取现金
玩家可以半价把房子卖给银行,卖的时候依然得保持同色地房子数量的平均,也就是说得卖房子最多的地。玩家可在任何玩家掷骰前赎回地皮,因掷出相同点数而得额外的回合除外。赎地时要加付抵押值10%的利息,遇小数无条件进入。
6、交易
在任何时间,玩家可与对手交易没有建筑物的地皮,先商谈的交易先处理。玩家间不得借贷。
7、入狱
入狱时仍可以收租、盖房子或是交易,只是不能移动。入狱时,玩家可在掷骰前选择用监狱通行证或是付50元罚金以马上出狱。在入狱时,唯有掷出相同的点数才能移动(出狱),此时并不会有额外的回合。
8、破产
如在卖出或抵押所有资产后仍无足够的现金以支付债务,则玩家宣告破产。所有资产直接转让给债主,其已抵押地皮转让给债主时,债主要马上付抵押值10%的交易税。
9、胜利条件
最后一位没有破产的玩家得胜。限时结束时,总资产最高者得胜。
'''
import random
import time

EVENT = ["起点","北京","上海","广州","深圳","向前五步","天津","成都","西安","重庆","向后两步","石家庄","幸运","监狱","沈阳","大连","炸弹","哈尔滨","齐齐哈尔"]
CITY = ["北京","上海","广州","深圳","天津","成都","西安","重庆","沈阳","大连","哈尔滨","齐齐哈尔"]
def dice():
    point = random.randint(1, 6)
    #point = random.randint(2, 12)
    return point
def city_event(people,i):
    people[i]["num"] = people[i]["num"] + dice()
    event = EVENT[people[i]["num"]%len(EVENT)]
    if event in CITY:
        if event in people[(i+1)%3]["city"] or event in people[(i+2)%3]["city"]:
            people[i]["money"]=people[i]["money"]-500
            print("{}花费过路费500".format(people[i]["name"]))
        else:
            people[i]["money"] = people[i]["money"] - 2000
            people[i]["city"] = people[i]["city"] + event
            print("{}花费2000买了城市{}".format(people[i]["name"],event))
    return people
def checkboardInit():
    checkboard = []
    for i in EVENT:
        checkboard.append(i)
def personInit(num):
    name = ["李华","小玲","小明","小红"]
    people = []
    for i in range(0,num):
        person = {"name":name[random.randint(0,len(name)-1)],"money":15000,"num":0,"status":0,"city":""}
        name.remove(person["name"])
        people.append(person)
    return people
def trigger_event(person):
    point = dice()
    person["num"] = person["num"]+point
    print("{}掷骰子掷出了{},当前点数变为{}".format(person["name"],point,person["num"]))
    print("{}当前钱数为{}".format(person["name"],person["money"]))
    #person["num"] = person["num"]+point
    if person["num"]%3 ==0:
        person["money"] = person["money"]+10000
    elif person["num"]%3 == 1:
        person["money"] = person["money"] - 1100
    elif person["num"]%3 == 2:
        person["money"] = person["money"] - 9000
    return person
people = []
people = personInit(3)
while True:
    for i in range(0, 3):
        time.sleep(1)
        if people[i]["money"]<0:
            continue
        else:
            city_event(people,i)

你可能感兴趣的:(Python,python)