【发布时间】:2019-06-04 02:47:51
【问题描述】:
我正在创建一个垄断游戏,在这个游戏中,我有一个名为 properties 的列表,其中包含所有属性名称:
property = ["Go", "Mediterranean Ave", "Community Chest", "Baltic Ave", "Income Tax", "Reading Railroad",
"Oriental Ave", "Chance", "Vermont Ave", "Connecticut Ave", "jail/Just Visiting", "St. Charles Place",
"Electric Company", "States Ave", "Virginia Ave", "Pennsylvania Railroad", "St. James Place",
"Community Chest", "Tennessee Ave", "New York Ave", "Free Parking", "Kentucky Ave", "Chance",
"Indiana Ave", "Illinois Ave", "B. & O. Railroad", "Atlantic Ave", "Ventnor Ave", "Water Works",
"Marvin Gardens", "Go to Jail", "Pacific Ave", "North Carolina Ave", "Community Chest",
"Pennsylvania Ave", "Short Line Railroad", "Chance", "Park Place", "Luxury Tax", "Boardwalk"]
我还有一个标记属性颜色的颜色列表:
propertyColor = [
"None", "Brown", "None", "Brown", "None", "None", "Navy", "None", "Navy", "Navy", "None", "Pink", "None", "Pink", "Pink", "None", "Orange",
"None", "Orange", "Orange", "None", "Red", "None", "Red", "Red", "None", "Yellow", "Yellow", "None", "Yellow", "None", "Green", "Green", "None",
"Green", "None", "None", "Blue", "None", "Blue"
]
每个玩家都有一本与他们的名字相关的字典
{
"playerName": name,
"money": settings[4],
"properties": ["Mediterranean Ave", "Baltic Ave"],
"railroads": [],
"inJail": False,
"PlayerLocation": 0
}
我想这样做,如果用户想在一个属性上建造一个公寓,程序会检查用户是否在同一颜色组中拥有所有三个属性,它将执行下一个命令,如何会这样做吗?
【问题讨论】:
-
你已经尝试了什么?有一个起点总是更好。
-
property和propertyColor是如何关联的?你怎么知道所有属性都在同一个颜色组中? -
您需要将属性链接到它们的颜色组。例如,将
property扩展为一个字典,其中的值是键的颜色。您可能还需要一个反向字典,它在每组中提供 2-4 个属性(您可能需要 4 个 RR)。 -
小心,在传统的垄断中,有些物业组在组内只有2个物业,而不是3个。