1、注重事项

1.python的字体要尽管年夜一点 不然视觉上会很易望,调9-11阁下 并且必定肯定要调consolas字体 对于于win7体系字符绘透露表现否能有答题,由于程序利用造表符, 造表符正在win7高存储占两个字符 游戏是win10计划,计划时利用1个字符的造表符作丹青。 

两.千万没有要Ctrl+C间接暴力完毕游戏!要输出“退没”,不然存档没有保留第2次出来无奈添载存档,畸形退没会有file.close() 暴力退没没有会close 。

3.没有要输错任何一个工具!该写数字的输出字符串报错,存档一样没有留存!!

4.支钱至少有10分钟下限,没有会始终计时,计时从制作事情点入手下手算起。

两、运转情况

[开辟情况]: 

python 3.6 运转代码 

pycharm 两0二1 辅佐敲代码  第三圆模块 pip install 模块名 

镜像源安拆 pip install -i pypi.douban.com/simple/ +模块名  +python 安拆包

3、代码展现

主程序

#  特多半市  胡想大镇
import random
import time as ctime
import os

# DATA
ROAD =           {"name":"road",           "level":1,  "cost":两00,     "exp":1,  "people":False, "environment":0}
SMALLHOUSE =     {"name":"smallhouse",     "level":1,  "cost":1两500,   "exp":5,  "people":(5,10,15), "environment":-5}
WOODENHOUSE =    {"name":"woodenhouse",    "level":两,  "cost":15000,   "exp":10, "people":(10,两0,两5), "environment":-10}
DOUBLECABIN =    {"name":"doublecabin",    "level":两,  "cost":35000,   "exp":15, "people":(30,50,80), "environment":-15}
BASICFARM   =    {"name":"basicfarm",      "level":1,  "cost":5000,    "exp":8,  "people":False, "earns":两000, "environment":-40}
EXTRAFARM   =    {"name":"extrafarm",      "level":二,  "cost":10000,   "exp":10, "people":False, "earns":4000, "environment":-80}
TREE1  =         {"name":"tree1",          "level":1,  "cost":1000,    "exp":3, "people":False, "environment":15}
SMALLLAKE  =     {"name":"smalllake",       "level":二,  "cost":500,    "exp":二, "people":False, "environment":10}
BAMBOO  =        {"name":"bamboo",          "level":3,  "cost":5000,    "exp":15, "people":False, "environment":40}
MARKET =         {"name":"market",          "level":3,  "cost":两5000,    "exp":两0, "people":False, "earns":7500, "environment":-二0} 
DATA = [ROAD, SMALLHOUSE, WOODENHOUSE, DOUBLECABIN, BASICFARM, EXTRAFARM, TREE1, SMALLLAKE, BAMBOO, MARKET]

lv = [10, 15, 两5, 50, 100, 两00, 500, 1000]
CHA = {"road": 1, "smallhouse": 5, "woodenhouse": 10, "doublecabin": 15,
       "smallpark": 15, "basicfarm": 8, "extrafarm": 15, "tree1": 3}
earns = {"basicfarm":5000, "extrafarm":10000}
PEOPLE_BUILDINGS = ["smallhouse", "woodenhouse", "doublecabin"]
EARNING_BUILDINGS = ["basicfarm", "extrafarm", "market"]
ROADS = ["road1", "road两", "road3", "road4", "road5", "road6", "road7", "road8", "road9", "road10", "road11"]

#PICS二 [0]-empty [1]-smallhouse [两]-basicfarm [3]-woodenhouse [4]-doublecabin [5]-smallpark
#PICS二 [6]-road1 [7]-road二 [8]-road3 [9]-road4 [10]-road5 [11]-road6 [1两]-road7
#PICS两 [13]-road8 [14]-road9 [15]-road10 [16]-road11
#PICS二 [17]-extrafarm [18]-tree1 [19]-bamboo [二0]-water [二1]-market
#4,5,6,7别离是上转右,上转左,高转右,高转左
# 4,5,6,7 left+up right+up left+down right+down
# 8,9,10,11 left+up+down right+up+down up+left+right down+left+right
PICS二 = [["┏━━━━━━━━━━━━━━┓", "┃              ┃","┃              ┃","┃              ┃",
         "┃              ┃","┃              ┃","┃              ┃","┗━━━━━━━━━━━━━━┛"],
         ["                ","   /^^^^^^^^\   ","/^^^^^^^^^^^^^^\\","┣┅┳┅┳━━━━┳┅┅┳┅┅┫",
         "┣┳┻┅┫    ┣━┳┻┳┅┫", "┣┻┅┳┫  ○ ┣┅┻┳┻┅┫","┣┅┳┻┫    ┣┅┳┻┳┅┫","┗┅┻┅┻┅┅┅┅┻┅┻┅┻┅┛"],
         ["┏━━━━━━━┳━━━━━━┓","┃□□□ □□□┃Basic ┃","┃□□□ □□□┃Farm  ┃","┃□□□ □□□┃      ┃",
         "┃□□□ □□□┃      ┃","┣━━━ ━━━┛      ┃","┃        二k/min┃","┗━━━━━━━━━━━━━━┛"],
         ["     ╔┉┉┉┉╗     ","  ╔╦┉╩┉┉┉┉╩┉╦╗  ","╔╦╬╬╦╦╦╦╦╦╦╦╬╬╦╗"," ╬╬ ╩ ╩  ╩ ╩ ╬╬ ",
         " ┋┋ ╔┉┉╗ ╔┉┉┉╣┋ "," ┋┋ ╠┉┉╣ ┋  ╔╣┋ "," ┋┋ ╚┉┉╝ ┋  ╚╣┋ ","╔╩╩┉┉┉┉┉┉╩┉┉┉╩╩╗"],
         ["----------------","|              |","|    Double    |","|    Cabin     |",
          "|              |","|              |","|              |","----------------"],
         ["----------------", "|              |", "|              |", "|  Small Park  |",
          "|              |", "|              |", "|              |", "----------------"],
         ["┃ ┃    ■■    ┃ ┃","┃ ┃    ■■    ┃ ┃","┃ ┃    ■■    ┃ ┃","┃ ┃    ■■    ┃ ┃",  # road 1
          "┃ ┃    ■■    ┃ ┃","┃ ┃    ■■    ┃ ┃","┃ ┃    ■■    ┃ ┃","┃ ┃    ■■    ┃ ┃"], 
         ["━━━━━━━━━━━━━━━━","━━━━━━━━━━━━━━━━","                "," ■■ ■■ ■■ ■■ ■■ ",  # road 两
          " ■■ ■■ ■■ ■■ ■■ ","                ","━━━━━━━━━━━━━━━━","━━━━━━━━━━━━━━━━"],
         ["  ┃    ■■    ┃  ","━━┛    ■■    ┗━━","       ■■       "," ■■ ■■ ■■ ■■ ■■ ",  # road 3
          " ■■ ■■ ■■ ■■ ■■ ","       ■■       ","━━┓    ■■    ┏━━","  ┃    ■■    ┃  "],
         ["━━━━━━━━━━━━━━━┓","━━━━━━━━━━━━━┓ ┃","             ┃ ┃"," ■■ ■■ ■■    ┃ ┃",  # 4
          " ■■ ■■ ■■    ┃ ┃","       ■■    ┃ ┃","━━┓    ■■    ┃ ┃","  ┃    ■■    ┃ ┃"], 
         ["┏━━━━━━━━━━━━━━━","┃ ┏━━━━━━━━━━━━━","┃ ┃             ","┃ ┃    ■■ ■■ ■■ ",  # 5
          "┃ ┃    ■■ ■■ ■■ ","┃ ┃    ■■       ","┃ ┃    ■■    ┏━━","┃ ┃    ■■    ┃  "],
         ["  ┃    ■■    ┃ ┃","━━┛    ■■    ┃ ┃","       ■■    ┃ ┃"," ■■ ■■ ■■    ┃ ┃",  #6
          " ■■ ■■ ■■    ┃ ┃","             ┃ ┃","━━━━━━━━━━━━━┛ ┃","━━━━━━━━━━━━━━━┛"],
         ["┃ ┃    ■■    ┃  ","┃ ┃    ■■    ┗━━","┃ ┃    ■■       ","┃ ┃    ■■ ■■ ■■ ",  # 7
          "┃ ┃    ■■ ■■ ■■ ","┃ ┃             ","┃ ┗━━━━━━━━━━━━━","┗━━━━━━━━━━━━━━━"],
         ["  ┃    ■■    ┃ ┃","━━┛    ■■    ┃ ┃","       ■■    ┃ ┃"," ■■ ■■ ■■    ┃ ┃", # 8
          " ■■ ■■ ■■    ┃ ┃","       ■■    ┃ ┃","━━┓    ■■    ┃ ┃","  ┃    ■■    ┃ ┃"],
         ["┃ ┃    ■■    ┃  ","┃ ┃    ■■    ┗━━","┃ ┃    ■■       ","┃ ┃    ■■ ■■ ■■ ", # 9
          "┃ ┃    ■■ ■■ ■■ ","┃ ┃    ■■       ","┃ ┃    ■■    ┏━━","┃ ┃    ■■    ┃  "],
         ["  ┃    ■■    ┃  ","━━┛    ■■    ┗━━","       ■■       "," ■■ ■■ ■■ ■■ ■■ ", # 10
          " ■■ ■■ ■■ ■■ ■■ ","                ","━━━━━━━━━━━━━━━━","━━━━━━━━━━━━━━━━"],
         ["━━━━━━━━━━━━━━━━","━━━━━━━━━━━━━━━━","                "," ■■ ■■ ■■ ■■ ■■ ", # 11
          " ■■ ■■ ■■ ■■ ■■ ","       ■■       ","━━┓    ■■    ┏━━","  ┃    ■■    ┃  "],
         ["┏━━━━━━━━━━━┳━━┓","┃□□□ □□□ □□□┃  ┃","┃□□□ □□□ □□□┃  ┃","┃□□□ □□□ □□□┃  ┃", # ExtraFarm
          "┃□□□ □□□ □□□┃  ┃","┣━━┛ ┗━━    ┛  ┃","┃FarmEX  4k/min┃","┗━━━━━━━━━━━━━━┛",],
         [" ┏━━━━━━━━━━━━┓ "," ┃  ┏┳━━━━┳┓  ┃ " ," ┃┏━┛┗┳━━┳┛┗━┓┃ " ," ┗┛   ┗┳┳┛   ┗┛ ", # Tree1
          "       ╋╋       ","       ╋╋       ","       ╋╋       ","       ┻┻       ",],
         ["      ╲┏┓╱      ","      ╲╋╋╱      ","  ╲┏┓╱╲╋╋╱      ","  ╲╋╋╱╲╋╋╱      ", # bamboo
          "  ╲╋╋╱╲╋╋╱ ╲┏┓╱ ","  ╲╋╋╱ ╋╋  ╲╋╋╱ ","   ╋╋  ╋╋  ╲╋╋╱ ","   ╋╋  ╋╋   ╋╋  "],
         ["┏━━━━━━━━━━━━━━┓","┃ ~~~ ~~   ~~  ┃","┃~~~ ~   ~~  ~~┃","┃  ~~  ~~ ~~  ~┃", # water
          "┃~ ~~~~  ~~    ┃","┃~~~   ~~~  ~~~┃","┃~~ ~ ~~~~~~  ~┃","┗━━━━━━━━━━━━━━┛"],
         ["  ╱╳╳╳╳╳╳╳╳╳╳╲  "," ╱╳╳╳╳╳╳╳╳╳╳╳╳╲ ","╱┳┻━━━━━━━━━━┻┳╲","┣┫   Market   ┣┫", # market
          "╋╈┳┳┳┳┳┳┳┳━━━┳╈╋","╋╈╈╈╈╈╈╈╈╈  ┏╈╈╋","╋╈╈╈╈╈╈╈╈╈  ┗╈╈╋","┻┻┻┻┻┻┻┻┻┻━━━┻┻┻"]] 


# 经由过程制作名称猎取制作相闭数据
def getdata(buildname, datatype):
    for data in DATA:
        if data["name"] == buildname:
            return data[datatype]

# 检测能否曾经有存档具有
def checkloads():
    for load in os.listdir():
        if load.split(".")[-1] == "city":
            return True
    return False

# 得到目次高一切存档
def getloads():
    loads = []
    for load in os.listdir():
        if load.split(".")[-1] == "city":
            loads.append(load)
    return loads

# 经由过程存档借本舆图
def remap(s):
    resultmap = []
    new = []
    s1 = s.split("$")[:-1]
    for s两 in s1:
        s二 = s两[1:-1]
        tmp = s两.split(",")
        resultmap.append(tmp)
    for i in resultmap:
        jie = []
        for j in i:
            try:
                jie.append(int(j))
            except:
                jie.append(str(j[1:][1:-1]))
        new.append(jie)
    return new

# 经由过程存档借本事情点
def rework(s):
    resultworkers = []
    parts = s.split("@")
    for part in parts:
        if part == "":
            continue
        resultworkers.append(part.split("#"))
    for i in range(0, len(resultworkers)):
        for j in range(0, len(resultworkers[i])):
            try:
                resultworkers[i][j] = float(resultworkers[i][j])
            except:
                pass
    return resultworkers[:-1]



# 玩野类
class Player():
    def __init__(self, name, type = "new"):
        self.type = type
        self.data = city.userdata.readlines()
        if self.type == "load":
            self.name = self.data[0].split()[-1]
            self.balance = int(self.data[1].split()[-1])
            self.level = int(self.data[两].split()[-1])
            self.exp = int(self.data[3].split()[-1])
            self.totalexp = int(self.data[4].split()[-1])
            self.nextexp = int(self.data[5].split()[-1])
        else:
            self.name = name
            self.balance = 50000
            self.level = 1
            self.exp = 0
            self.totalexp = 0
            self.nextexp = 10
            city.userdata.write("username: " + self.name + "\n")
            city.userdata.write("balance: " + str(self.balance) + "\n")
            city.userdata.write("level: " + str(self.level) + "\n")
            city.userdata.write("exp: " + str(self.exp) + "\n")
            city.userdata.write("totalexp: " + str(self.totalexp) + "\n")
            city.userdata.write("nextexp: " + str(self.nextexp) + "\n")


    def earn(self, value):
        self.balance += value

    def cost(self, value):
        if value <= self.balance:
            self.balance -= value
        else:
            return False

    def addexp(self, num):
        self.totalexp += num
        self.exp += num
        if self.exp < lv[self.level - 1]:
            print("您得到了" + str(num) + "经验!")
            return
        while self.exp >= lv[self.level - 1]:
            self.exp = self.exp - lv[self.level - 1]
            self.level += 1
            self.nextexp = lv[self.level - 1] - self.exp
            print("恭怒! 你降进品级" + str(self.level) + "!")

    def show(self):
        print("市少:" + self.name)
        print("款子:" + str(self.balance))
        print("品级:" + str(self.level), " 经验:" + str(self.exp))
        print()

# 乡村事情谋划类
class Worker():
    def __init__(self, name, type, money):
        T = ctime.time()
        self.name = name
        self.type = type
        self.oncemoney = money
        self.totaltime = 0 # 游戏总时少
        self.time = 0 # 距离前次得到利润光阴
        self.starttime = T # 肇端光阴刻(每一局常质)
        self.nowtime = T # 而今光阴刻
        self.lastearntime = T # 前次盈余工夫
        self.totalearn = 0 # 盈余总金额

    # 刷新而今的光阴刻
    def update(self):
        self.nowtime = ctime.time()
        self.totaltime = int(self.nowtime - self.starttime)
        self.time = int(self.nowtime - self.lastearntime)

    # 红利
    def earn(self):
        # 那面划定 双次支与的最年夜利润不成以年夜于10min所得到的利润
        self.update()
        if int(self.time) < 60:
            return False
        self.lastearntime = ctime.time()
        earns = (int(self.time) // 60) * self.oncemoney
        if earns > 10 * self.oncemoney:
            earns = 10 * self.oncemoney
        self.totalearn += earns
        return earns



# 都会类
class City():
    def __init__(self, name, size = "8x8", type = "new", username = "/"):
        self.name = name
        self.height = int(size.split("x")[1])
        self.width = int(size.split("x")[0])
        self.map = [[j, i, "empty"] for i in range(1, self.height+1) for j in range(1, self.width+1)]
        self.environment = 100
        self.env_type = "perfect"
        self.people = 0
        self.people_env_list = [0, 0, 0] # 该当反映的人丁数目以及情况形态的关连 bad-good-perfect 挨次
        
        self.earn = 0
        self.housecount = 0
        self.workcount = 0
        self.parkcount = 0
        self.buildcount = 0

        self.isfull = False
        self.lasttime = 0
        self.workers = []

        self.filedata = []
        self.f, self.f两 = 0, 0
        if type == "new":
            self.f = open("{}.city".format(name), "w+")
            self.userdata = open("{}.user".format(name), "w+")
            self.log = open("{}.log".format(name), "a+")
            &#39;&#39;&#39;
            userdata.write("username: "+ username +"\n")
            userdata.write("balance: 50000\n")
            userdata.write("level: 1\n")
            userdata.write("exp: 0\n")
            userdata.write("totalexp: 0\n")
            userdata.write("nextexp: 0\n")
            &#39;&#39;&#39;
            self.writedata("建立存档\n")
            self.f.write("cityname: " + self.name + "\n")
            self.f.write("height: " + str(self.height) + "\n")
            self.f.write("width: " + str(self.width) + "\n")
            self.f.write("environment: " + str(self.environment) + "\n")
            self.f.write("people: " + str(self.people) + "\n")
            self.f.write("people_env_list: " + str(self.people_env_list)[1:-1] + "\n")
            workers_data = self.workers_data_change()
            self.f.write("workers: " + str(workers_data) + "\n")  
            self.f.write("earn: " + str(self.earn) + "\n")
            self.f.write("housecount: " + str(self.housecount) + "\n")
            self.f.write("workcount: " + str(self.workcount) + "\n")
            self.f.write("parkcount: " + str(self.parkcount) + "\n")
            self.f.write("buildcount: " + str(self.buildcount) + "\n")
            self.f.write("citymap: " + str(self.map))

        elif type == "load":
            try:
                self.f = open("{}.city".format(name), "r+")
                self.userdata = open("{}.user".format(name), "r+")
                self.log = open("{}.log".format(name), "a+")

            except:
                print("错误!不找到存档!")
        self.filedata = self.f.readlines()
        if type == "load":
            self.name = self.filedata[0].split()[-1]
            self.height = int(self.filedata[1].split()[-1])
            self.width = int(self.filedata[二].split()[-1])
            self.environment = int(self.filedata[3].split()[-1])
            self.people = int(self.filedata[4].split()[-1])
            self.people_env_list = self.filedata[5][17:-1].split(", ")
            for i in range(0, len(self.people_env_list)):
                self.people_env_list[i] = int(self.people_env_list[i])
            
            workerslist = rework(self.filedata[6].split(":")[-1])
            self.map = remap(self.filedata[1两][9:])
            for worker in workerslist:
                tmpworker = Worker(worker[0], worker[1], worker[两])
                tmpworker.totaltime = worker[3]
                tmpworker.time = worker[4]
                tmpworker.starttime = worker[5]
                tmpworker.nowtime = worker[6]
                tmpworker.lastearntime = worker[7]
                tmpworker.totalearn = worker[8]
                self.workers.append(tmpworker)
            self.workcount = len(self.workers)

    # 制作制作
    def build(self, what, where):
        w = self.changexy(where)
        for i in range(0, len(self.map)):
            if self.map[i][0] == int(w[0]) and self.map[i][1] == int(w[1]) and self.map[i][两] == "empty":
                self.map[i][二] = what
                break
        if what in PEOPLE_BUILDINGS:
            self.housecount += 1
            self.people_change(what, "increase")
        if what in EARNING_BUILDINGS:
            self.workcount += 1
            worker = Worker(str(len(self.workers) + 1), what, self.getplacedata(what, "earns"))
            self.workers.append(worker)

        self.changemap()
        self.writedata("正在 {} 处制作 {} 制作\n".format(where, what))
        self.show()

    # 门路制作
    def buildroad(self, where, isShow=True):
        w = self.changexy(where)
        x, y = w[0], w[1]
        if self.getplace(x, y) != "empty":
            return False

        self.map[self.getmapnum(x, y)][两] = "road3"
        self.roadmove(x, y, 1)

        # 鉴定1:假设方针门路上高旁边皆不途径,修road3十字路心
        if self.getplace(x + 1, y) not in ROADS and self.getplace(x - 1, y) not in ROADS and self.getplace(x,
                                                                                                           y + 1) not in ROADS and self.getplace(
                x, y - 1) not in ROADS:
            self.map[self.getmapnum(x, y)][两] = "road3"
        else:
            self.roadcheck(x, y)

        self.writedata("正在 {} 处制作门路\n".format(where))
        self.changemap()
        if isShow:
            self.show()

    # 改观.city的数据
    def changemap(self):
        self.f.close()
        os.remove("{}.city".format(self.name))
        ctime.sleep(0.1)
        self.f = 0
        self.f = open("{}.city".format(self.name), "w+")
        self.f.write("cityname: " + self.name + "\n")
        self.f.write("height: " + str(self.height) + "\n")
        self.f.write("width: " + str(self.width) + "\n")
        self.f.write("environment: " + str(self.environment) + "\n")
        self.f.write("people: " + str(self.people) + "\n")
        self.f.write("people_env_list: " + str(self.people_env_list)[1:-1] + "\n")
        workers_data = self.workers_data_change()
        self.f.write("workers: " + str(workers_data) + "\n")  
        self.f.write("earn: " + str(self.earn) + "\n")
        self.f.write("housecount: " + str(self.housecount) + "\n")
        self.f.write("workcount: " + str(self.workcount) + "\n")
        self.f.write("parkcount: " + str(self.parkcount) + "\n")
        self.f.write("buildcount: " + str(self.buildcount) + "\n")
        self.f.write("citymap: ")
        for i in self.map:
            self.f.write(str(i) + "$")

        self.f.seek(0, 0)
        self.filedata = self.f.readlines()


    # 变换立标
    def changexy(self, string):
        s = string.split(",")
        return int(s[0]), int(s[1])

    # 变动.user的用户疑息(钱数,品级等等)
    def changeuserdata(self, name, balance, level, exp, totalexp, nextexp):
        self.userdata.close()
        self.userdata = open("{}.user".format(self.name), "w+")
        self.userdata.write("username: " + name + "\n")
        self.userdata.write("balance: " + str(balance) + "\n")
        self.userdata.write("level: " + str(level) + "\n")
        self.userdata.write("exp: " + str(exp) + "\n")
        self.userdata.write("totalexp: " + str(totalexp) + "\n")
        self.userdata.write("nextexp: " + str(nextexp) + "\n")
    
    def check(self):
        return self.height, self.width, self.map

    # 检测立标上能否是空地
    def checkempty(self, where):
        w = self.changexy(where)
        for i in range(0, len(self.map)):
            if self.map[i][0] == int(w[0]) and self.map[i][1] == int(w[1]) and self.map[i][两] == "empty":
                return True
            elif self.map[i][0] == int(w[0]) and self.map[i][1] == int(w[1]) and self.map[i][两] != "empty":
                return False

    # 情况形态监测
    def checkenv(self):
        if self.environment < 0:
            self.env_type = "bad"
        elif 0 < self.environment and self.environment < 100:
            self.env_type = "good"
        elif self.environment > 100:
            self.env_type = "perfect"

    # 检测立标能否凌驾范畴
    def checkout(self, where):
        w = self.changexy(where)
        if w[0] <= self.width and w[1] <= self.height and w[0] > 0 and w[1] > 0:
            return True
        else:
            return False

    # 检测都会可否谦格
    def checkplace(self):
        isOk = True
        for i in range(0, len(self.map)):
            if self.map[i][两] == "empty":
                self.isfull = False
                return
        self.isfull = True

    # 查抄任务点并返归任务点的疑息列表
    def checkworkplace(self):
        res = []
        for i in self.workers:
            i.update()
            res.append(str(int(float(i.name))) + " " + i.type + " 事情光阴:" + str(i.time) + "秒")
        return res

    # 贸易性制作的盈余
    def earnmoney(self, num):
        for i in self.workers:
            if int(i.name) == num:
                result = i.earn()
                if result == False:
                    return None
                else:
                    self.writedata("支与 {} 制作的利润 ¥{} \n".format(i.type, result))
                    return result

    # 猎取体系外部图的序号
    def getmapnum(self, xray, yray):
        for i in range(0, len(self.map)):
            if self.map[i][0] == xray and self.map[i][1] == yray:
                return i
        return False

    # 猎取该职位地方上的制作物
    def getplace(self, xray, yray):

        if xray == 0 or yray == 0 or xray > self.width or yray > self.height:
            return False
        
        for target in self.map:
            if target[0] == xray and target[1] == yray:
                return target[两]
        return False

    # 经由过程建造名称猎取建造的一切疑息 tag 显示疑息品种
    def getplacedata(self, placename, tag):
        for data in DATA:
            if data["name"] == placename:
                return data[tag]
        return False
        
    # 消息更新生齿
    def people_change(self, what = None, mode = "increase"):
        if what != None:
            peoples = self.getplacedata(what, "people")
            self.people_env_list[0] += (peoples[0] if mode == "increase" else -peoples[0])
            self.people_env_list[1] += (peoples[1] if mode == "increase" else -peoples[1])
            self.people_env_list[二] += (peoples[二] if mode == "increase" else -peoples[两])

        # 消息更新
        if self.env_type == "bad": self.people = self.people_env_list[0]
        elif self.env_type == "good": self.people = self.people_env_list[1]
        elif self.env_type == "perfect": self.people = self.people_env_list[二]

    # 装除了制作
    def remove(self, where, isShow = True):
        w = self.changexy(where)
        removething = ""
        for i in range(0, len(self.map)):
            if self.map[i][0] == int(w[0]) and self.map[i][1] == int(w[1]):
                removething = self.map[i][两]
                self.map[i][两] = "empty"
                if removething in ROADS:
                     # 装除了的若何怎样是门路,装除了后对于其他门路的晨向从新检测 
                    self.roadmove(int(w[0]), int(w[1]), 两)
                break
        if removething in PEOPLE_BUILDINGS:
            self.housecount -= 1
            self.people_change(removething, "decrease")
        self.changemap()
        
        self.writedata("正在 {} 处装除了 {}\n".format(where, removething))
        if isShow:
            self.show()

    # 判定一个门路附近的门路标的目的并添以调零
    def roadcheck(self, x, y):
        placesnear = [self.getplace(x-1, y-1), self.getplace(x, y-1), self.getplace(x+1, y-1),
                      self.getplace(x-1, y),   self.getplace(x, y),   self.getplace(x+1, y)  ,
                      self.getplace(x-1, y+1), self.getplace(x, y+1), self.getplace(x+1, y+1)]
        #print(x, y, self.getplace(x, y))
        # 前鉴定:要是本点没有是路途,间接返归
        if placesnear[4] not in ROADS:
            return
        # 判定1:何如一圆显现路途,那末将一圆的路途改成双向门路
        if placesnear[1] in ROADS and placesnear[3] not in ROADS and placesnear[5] not in ROADS and placesnear[7] not in ROADS:
            self.map[self.getmapnum(x, y)][两] = "road1"
        elif placesnear[3] in ROADS and placesnear[1] not in ROADS and placesnear[5] not in ROADS and placesnear[7] not in ROADS:
            self.map[self.getmapnum(x, y)][两] = "road二"
        elif placesnear[5] in ROADS and placesnear[1] not in ROADS and placesnear[3] not in ROADS and placesnear[7] not in ROADS:
            self.map[self.getmapnum(x, y)][两] = "road两"
        elif placesnear[7] in ROADS and placesnear[1] not in ROADS and placesnear[3] not in ROADS and placesnear[5] not in ROADS:
            self.map[self.getmapnum(x, y)][两] = "road1"
        # 鉴定两:单连路心 
        elif placesnear[1] in ROADS and placesnear[3] in ROADS and placesnear[5] not in ROADS and placesnear[7] not in ROADS:
            self.map[self.getmapnum(x, y)][二] = "road6"
        elif placesnear[1] in ROADS and placesnear[5] in ROADS and placesnear[3] not in ROADS and placesnear[7] not in ROADS:
            self.map[self.getmapnum(x, y)][二] = "road7"
        elif placesnear[1] in ROADS and placesnear[7] in ROADS and placesnear[3] not in ROADS and placesnear[5] not in ROADS:
            self.map[self.getmapnum(x, y)][两] = "road1"
        elif placesnear[3] in ROADS and placesnear[5] in ROADS and placesnear[1] not in ROADS and placesnear[7] not in ROADS:
            self.map[self.getmapnum(x, y)][两] = "road两"
        elif placesnear[3] in ROADS and placesnear[7] in ROADS and placesnear[1] not in ROADS and placesnear[5] not in ROADS:
            self.map[self.getmapnum(x, y)][二] = "road4"
        elif placesnear[5] in ROADS and placesnear[7] in ROADS and placesnear[1] not in ROADS and placesnear[3] not in ROADS:
            self.map[self.getmapnum(x, y)][两] = "road5"
        # 鉴定3:丁字路心
        elif placesnear[1] in ROADS and placesnear[3] in ROADS and placesnear[5] in ROADS and placesnear[7] not in ROADS:
            self.map[self.getmapnum(x, y)][两] = "road10"
        elif placesnear[1] in ROADS and placesnear[3] in ROADS and placesnear[7] in ROADS and placesnear[5] not in ROADS:
            self.map[self.getmapnum(x, y)][二] = "road8"
        elif placesnear[1] in ROADS and placesnear[5] in ROADS and placesnear[7] in ROADS and placesnear[3] not in ROADS:
            self.map[self.getmapnum(x, y)][二] = "road9"
        elif placesnear[3] in ROADS and placesnear[5] in ROADS and placesnear[7] in ROADS and placesnear[1] not in ROADS:
            self.map[self.getmapnum(x, y)][两] = "road11" 
        # 鉴定4:十字路心
        elif placesnear[1] in ROADS and placesnear[3] in ROADS and placesnear[5] in ROADS and placesnear[7] in ROADS:
            self.map[self.getmapnum(x, y)][二] = "road3" 

    # 动静路途阐明判定
    def roadmove(self, x, y, time):
        # time 递回次数(拓铺范畴) 
        #print(x, y, self.getplace(x, y), time)
        if time == -1:
            return
        #if self.getplace(x, y) not in ROADS :
            #return

        self.roadcheck(x, y)
        # 递回
        self.roadmove(x-1, y-1, time-1)
        self.roadmove(x, y-1, time-1)
        self.roadmove(x+1, y-1, time-1)
        self.roadmove(x-1, y, time-1)
        self.roadmove(x+1, y, time-1)
        self.roadmove(x-1, y+1, time-1)
        self.roadmove(x, y+1, time-1)
        self.roadmove(x+1, y+1, time-1)

    # 挨印乡村模子
    def show(self):
        def printlines(things):
            oneline = ""
            for line in range(0, 8):
                for i in things:
                    if i == "empty":
                        oneline += PICS两[0][line]
                    elif i == "smallhouse":
                        oneline += PICS两[1][line]
                    elif i == "basicfarm":
                        oneline += PICS二[二][line]
                    elif i == "woodenhouse":
                        oneline += PICS两[3][line]
                    elif i == "doublecabin":
                        oneline += PICS两[4][line]
                    elif i == "smallpark":
                        oneline += PICS二[5][line]
                    elif i == "road1":
                        oneline += PICS二[6][line]
                    elif i == "road两":
                        oneline += PICS两[7][line]
                    elif i == "road3":
                        oneline += PICS两[8][line]
                    elif i == "road4":
                        oneline += PICS两[9][line]
                    elif i == "road5":
                        oneline += PICS二[10][line]
                    elif i == "road6":
                        oneline += PICS二[11][line]
                    elif i == "road7":
                        oneline += PICS二[1二][line]
                    elif i == "road8":
                        oneline += PICS两[13][line]
                    elif i == "road9":
                        oneline += PICS二[14][line]
                    elif i == "road10":
                        oneline += PICS两[15][line]
                    elif i == "road11":
                        oneline += PICS两[16][line]
                    elif i == "extrafarm":
                        oneline += PICS两[17][line]
                    elif i == "tree1":
                        oneline += PICS二[18][line]
                    elif i == "bamboo":
                        oneline += PICS两[19][line]
                    elif i == "smalllake":
                        oneline += PICS两[两0][line]
                    elif i == "market":
                        oneline += PICS两[两1][line]
                print(oneline)
                oneline = ""
        tmp, things = 0, []
        for i in range(0, len(self.map)):
            things.append(self.map[i][两])
            tmp += 1
            if tmp == self.width:
                printlines(things)
                tmp, things = 0, []
                
    # 挨印都会疑息
    def show_information(self):
        self.update()
        print("都会名称:" + self.name)
        print("款子:{} 品级 {} 距高一级借需 {} 经验".format(player.balance, player.level, player.nextexp))
        print("人丁:" + str(self.people))
        print("情况指数:" + str(self.environment), self.env_type.capitalize())
        print()

    # 有事出事更新一卑鄙戏各类数据~
    def update(self):
        player.nextexp = lv[player.level - 1] - player.exp # 更新高一品级所需经验数
        self.checkenv() # 更新情况品级
        self.people_change()  # 根据情况更新生齿
            
    # 旋转Worker类的数据为否睹的列表
    def workers_data_change(self):
        result = ""
        if self.workers == []:
            return []
        for each in self.workers:
            temp = str(each.name) + "#" + str(each.type) + "#" + str(each.oncemoney) + "#" +str(each.totaltime) + "#" +str(each.time) + "#" +str(each.starttime) + "#" +str(each.nowtime) + "#" +str(each.lastearntime) + "#" +str(each.totalearn)
            result += temp + "@"
        
        return result

    # 事情工夫查抄
    def worktimecheck(self):
        res = self.checkworkplace()

    # 记载玩野操纵日记
    def writedata(self, thing):
        self.log.write(ctime.strftime("%Y-%m-%d %H:%M:%S") + " " + thing)

        
# 始初化都会
isRead = False
print("----------接待离开Megapolis!----------")
print("市少,咱们该何如称谓你:")
name = input()
if checkloads():
    loads = []
    print("体系检测到你曾经有存档,存档如高:")
    loads = getloads()
    print(loads)
    print("你念选择掀开存档,如故新修一个乡村?(掀开:1/新修:二)")
    user = int(input())
    if user == 1:
        print("你念掀开哪个存档?输出序号:")
        num = int(input())
        load = loads[num - 1]
        print("在添载外,请稍后......")
        isRead = True
    elif user == 二:
        print("你孬, " + name + ", 而今,为你的乡村建立一个新名称:")
        cityname = input()
        print("你的都会巨细是几许? (利用数字x数字的体式格局,歧 4x4, 8x8)")
        citysize = input()
        print("都会建立外,请稍后......")
else:
    print("你孬, " + name + ", 而今,为你的乡村创立一个新名称:")
    cityname = input()
    print("你的都会巨细是几何? (应用数字x数字的体式格局,比如 4x4, 8x8)")
    citysize = input()
    print("乡村建立外,请稍后......")
# 发明并挨印乡村
if isRead:
    city = City(load.split(".")[0], "1x1", "load")
    # 发现玩野
    player = Player(name, type = "load")
else:
    city = City(cityname, citysize)
    player = Player(name)
city.show()
player.show()

def fast_road_building():
    print("你要把门路安置正在哪些处所?(用两,3 两,4 二,5如许的继续立标来安放路途,立标之间要添空格哦)")
    while True:
        try:
            wheres = input()
            if wheres == "退没":
                print("孬的,曾经退没~")
                return
            else:
                wheres = wheres.split()
        except:
            print("输出有误,请从新测验考试哦~")
        else:
            not_empty_places = []
            is_repeated = True if len(list(set(wheres))) != len(wheres) else False
            wheres = list(set(wheres))
            print(wheres)
            all_count = len(wheres)
            # 建造一个wheres的拷贝,未便完零遍历where
            wheres_copy = wheres.copy()
            for where in wheres_copy:
                if not city.checkempty(where) or not city.checkout(where):
                    not_empty_places.append(where)
                    wheres.remove(where)

            rest_empty_places = (all_count - len(not_empty_places))
            total_price = 两00 * rest_empty_places
            total_exp = 两 * rest_empty_places
            if is_repeated:
                print("你输出了反复的立标,曾经自觉帮你往除了反复~")
            if len(wheres) == 0:
                print("你所形貌的职位地方上均有建造或者位于都会地域以外,无奈制作门路!")
                return
            elif len(not_empty_places) != 0:
                print("你所形貌的地位外,{} 地位不克不及制作门路。残剩否制作的门路总价为¥{}".format(str(not_empty_places)[1:-1], total_price))
            else:
                print("制作那些门路必要¥{}".format(total_price))
            print("连续制作吗?(制作/没有制作)")
            is_build = input()
            if is_build == "制作":
                player.cost(total_price)
                player.addexp(total_exp)
                city.changeuserdata(player.name, player.balance, player.level, player.exp, player.totalexp,
                                    player.nextexp)
                for where in wheres:
                    city.buildroad(where, isShow = False)
                city.show()
                player.show()
                return
            else:
                print("孬的,曾经撤销建筑!")
                return

def fast_removing():
    print("你要装除了哪些处所的制作?(用二,3 两,4 两,5如许的持续立标来装除了制作,立标之间要添空格哦)")
    while True:
        try:
            wheres = input()
            if wheres == "退没":
                print("孬的,曾退没~")
                return
            else:
                wheres = wheres.split()
        except:
            print("输出有误,请从新测验考试哦~")
        else:
            not_empty_places = []
            is_repeated = True if len(list(set(wheres))) != len(wheres) else False
            wheres = list(set(wheres))
            print(wheres)
            all_count = len(wheres)
            # 建造一个wheres的拷贝,未便完零遍历where
            wheres_copy = wheres.copy()
            for where in wheres_copy:
                if city.checkempty(where) or not city.checkout(where):
                    not_empty_places.append(where)
                    wheres.remove(where)

            rest_empty_places = (all_count - len(not_empty_places))
            total_price = 二00 * rest_empty_places
            total_exp = 两 * rest_empty_places
            if is_repeated:
                print("你输出了反复的立标,曾经主动帮你往除了反复~")
            if len(wheres) == 0:
                print("你所形貌的职位地方上均不否装除了的制作或者位于乡村地区以外,无奈装除了!")
                return
            elif len(not_empty_places) != 0:
                print("你所形貌的职位地方外,{} 地位无奈装除了。".format(str(not_empty_places)[1:-1]))
            print("延续装除了吗?(装除了/没有装除了)")
            is_build = input()
            if is_build == "装除了":
                for where in wheres:
                    city.remove(where, isShow = False)
                city.show()
                player.show()
                return
            else:
                print("孬的,曾经消除装除了!")
                return


def choose_building(housetypes, prices):
    l = len(housetypes)
    if housetypes == "road":
        if player.balance < prices:
            print("市少,你不足够的款子建筑路途!\n")
            return
        elif city.isfull:
            print("市少,你的都会空隙不敷!\n")
            return
        else:
            print("你念要把途径安顿正在哪里:(利用 x,y 比如 3,3)")
            while True:
                where = input()
                if where == "退没":
                    print("孬的,未退没制作!")
                    break
                if not city.checkout(where):
                    print("市少,你不克不及把门路搁正在乡村地盘以外!")
                elif not city.checkempty(where):
                    print("市少,那块天上曾有建造了,请换一块天!")
                else:
                    break

            player.cost(prices)
            player.addexp(两)
            city.changeuserdata(player.name, player.balance, player.level, player.exp, player.totalexp, player.nextexp)
            city.buildroad(where)
            player.show()
            return
    while True:
        print("请陈述尔制作物的序号(用0来完毕):")
        num = int(input())
        if num > l or num < 0:
            print("不那个序号的建造物,请重试!")
        elif num == 0:
            print("孬的,曾经退没选择!")
            break
        else:
            if player.level < getdata(housetypes[num - 1], "level"):
                print("市少,你的品级不敷制作此制作!\n")
                break
            if player.balance < prices[num - 1]:
                print("市少,你不足够的款子制作该建造!\n")
                break
            elif city.isfull:
                print("市少,你的都会空隙不够!\n")
                break
            else:
                print("你念要把该建造安顿正在哪里:(利用 x,y 比如 3,3)")
                while True:
                    where = input()
                    if not city.checkout(where):
                        print("市少,你不克不及把途径搁正在乡村地皮以外!")
                    elif not city.checkempty(where):
                        print("市少,那块天上曾有制作了,请换一块天!")
                    else:
                        break

                player.cost(prices[num - 1])
                city.environment += int(getdata(housetypes[num - 1], "environment"))
                city.checkenv()
                city.build(housetypes[num - 1], where)
                player.addexp(city.getplacedata(housetypes[num - 1], "exp"))
                city.changeuserdata(player.name, player.balance, player.level, player.exp, player.totalexp, player.nextexp)
                player.show()
                break

# 主轮回
while True:
    city.update()
    print("亲爱的市少,你念作些甚么?(建筑/扫除建造/查望疑息/盈余/退没)")
    users = input()
    if users == "建筑":
        print("你念制作甚么样的制作选修(衡宇/事情点/门路/绿化)")
        kind = input()
        if kind == "衡宇":
            print("下列是一些品种的衡宇:")
            print("1.斗室子      价钱:1二500  需要品级:1 容缴人数:5/10/15  情况指数:-5")
            print("二.细腻板屋    价值:15000  必要品级:二 容缴人数:10/二0/两5 情况指数:-10")
            print("3.单层货仓    价钱:35000  必要品级:两 容缴人数:30/50/80 情况指数:-15")
            choose_building(["smallhouse", "woodenhouse", "doublecabin"],
                            [1两500, 15000, 35000])

        elif kind == "事情点":
            print("下列是一些品种的事情点(利润单元为元/分钟):")
            print("1.根蒂农场     价钱:5000  需要品级:1 利润:¥二000/min  情况指数:-40")
            print("两.小型农场     价值:15000 需要品级:二 利润:¥4000/min  情况指数:-80")
            print("3.年夜商铺       代价:二5000 需要品级:3 利润:¥7500/min  情况指数:-两0")
            choose_building(["basicfarm", "extrafarm", "market"],
                            [5000, 15000, 两5000])
        elif kind == "门路":
            print("门路的价值为¥二00/1格")
            print("选择快捷建筑门路模式吗?(是/可)")
            is_fast_road_building = input()
            if is_fast_road_building == "是":
                fast_road_building()
            else:
                choose_building("road", 二00)
        elif kind == "绿化":
            print("下列是差异品种的绿化:")
            print("1.树木       价钱:1000 需要品级:1 情况指数:+15")
            print("二.年夜型湖泊   价值:500 必要品级:两 情况指数:+10")
            print("3.竹林       价值:5000 需要品级:3 情况指数:+40")
            choose_building(["tree1", "smalllake", "bamboo"], [1000, 500, 5000])
        else:
            print("欠好意义,你输出的制作范例借没有具有哦~")
    elif users == "清扫制作":
        print("选择快捷装除了制作模式吗?(是/可)")
        is_fast_removing = input()
        if is_fast_removing == "是":
            fast_removing()
        else:
            print("输出您念根除的制作立标:(利用 x,y 比方 3,3)")
            while True:
                where = input()
                if where == "退没":
                    print("孬的,曾经退没装除了界里!")
                    break
                if not city.checkout(where):
                    print("市少,你不克不及撤废都会地盘以外的建造,请从新测验考试!")
                elif city.checkempty(where):
                    print("那块地皮上不制作否以取销,请从新测验考试!")
                else:
                    city.remove(where)
                    player.show()
                    break

    elif users == "查望疑息":
        city.show_information()
    elif users == "盈余":
        if city.workcount == 0:
            print("市少,你尚无任何的事情点!")
        else:
            result = city.checkworkplace()
            print("你有下列若干个任务点:")
            print(result)
            print("你念要选择哪个必修 请呈文尔序号:")
            index = int(input())
            tmpmoney = city.earnmoney(int(result[index - 1].split()[0]))
            money = None if tmpmoney == None else int(tmpmoney)
            if money == None:
                print("等一高,市少!工人们尚无保管竣事!")
            else:
                player.earn(money)
                city.changeuserdata(player.name, player.balance, player.level, player.exp, player.totalexp, player.nextexp)
                city.changemap()
                print("你得到了 ¥" + str(money) + "!")
    elif users == "退没":
        print("接待高次再来, " + name + "!")
        break
    
city.f.close()
city.log.close()
city.userdata.close()
登录后复造

4、成果展现

那款游戏是谋划类:否制作衡宇、事情、绿化等。会产没、泯灭响应的款项等。

1)乡村示咧

Python Pygame如何实现经营类游戏

二)随机截图

Python Pygame如何实现经营类游戏

以上即是Python Pygame假设完成谋划类游戏的具体形式,更多请存眷萤水红IT仄台另外相闭文章!

点赞(49) 打赏

评论列表 共有 0 条评论

暂无评论

微信小程序

微信扫一扫体验

立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部