Code: Alles auswählen
import random
from clrprint import *
class Player:
def __init__(self, name):
global industries, landmarks
self.name = name
self.money = 30
self.industries = {}
for industry in industries:
self.industries[industry] = 0
self.industries[wheat_field] += 1
self.industries[bakery] += 1
self.landmarks = {}
for landmark in landmarks:
self.landmarks[landmark] = 0
class Industry:
def __init__(self, name, cost, profit_basic, profit_bonus, profit_bonus_dependencies, profit_modifier_type, shop_rarity, dice_rolls, text_colour, description):
global industries
self.name = name
self.cost = cost
self.profit_basic = profit_basic
self.profit_bonus = profit_bonus
self.profit_bonus_dependencies = profit_bonus_dependencies
self.profit_modifier_type = profit_modifier_type
self.dice_rolls = dice_rolls
self.profit = 0
self.true_dependencies = 0
self.text_colour = text_colour
self.shop_rarity = shop_rarity
self.description = description
self.profit_shopping_mall_bonus = 0
industries.append(self)
def get_profit(self, player):
global roll, player_at_turn, num_player, names
self.profit = 0
if roll in self.dice_rolls and player.industries[self] > 0:
self.profit_shopping_mall_bonus = 0
self.true_dependencies = 0
if player.landmarks[shopping_mall] > 0:
self.profit_shopping_mall_bonus += 10
for industry in player.industries:
for dependency in self.profit_bonus_dependencies:
if dependency == industry:
self.true_dependencies += player.industries[industry]
if self.profit_modifier_type == "all":
self.profit = (self.profit_basic + self.profit_bonus * self.true_dependencies) * player.industries[self]
elif self.profit_modifier_type == "own" and player == players[player_at_turn]:
self.profit = (self.profit_basic + self.profit_bonus * self.true_dependencies) * player.industries[self]
if self == convenience_store or self == bakery:
self.profit += self.profit_shopping_mall_bonus
elif self.profit_modifier_type == "steal" and player != players[player_at_turn]:
self.profit = (self.profit_basic + self.profit_bonus * self.true_dependencies) * player.industries[self] + self.profit_shopping_mall_bonus
players[player_at_turn].money -= self.profit
elif self.profit_modifier_type == "stadium":
self.profit = (self.profit_basic + self.profit_bonus * (num_player - 1)) * player.industries[self]
elif self.profit_modifier_type == "tv_station" and player == players[player_at_turn]:
true = 1
while true == 1:
answer = input(player.name + ", gebe den Namen des Spielers dem du " + str(self.profit_bonus) + " Münzen stehlen willst ein: ")
if answer in names:
true = 0
for i in [i for i, x in enumerate(names) if x == answer]:
choosen_player = i
self.profit = self.profit_bonus * player.industries[self]
players[choosen_player].money -= self.profit
elif self.profit_modifier_type == "buisness_center" and player == players[player_at_turn]:
true = 1
while true == 1:
answer = input(player.name + ", gebe den Namen des Spielers mit dem du eine Karte tauschen willst ein: ")
if answer in names:
true = 0
for i in [i for i, x in enumerate(names) if x == answer]:
choosen_player = i
true = 1
while true == 1:
answer = input(player.name + ", gebe den Namen der Industrie die du von " + players[choosen_player].name + " haben willst ein: ")
print(answer)
for industry in players[choosen_player].industries:
print(industry.name)
print(players[choosen_player].industries[industry])
if answer == industry.name and players[choosen_player].industries[industry] > 0:
get_industry = industry
true = 0
true = 1
while true == 1:
answer = input(player.name + ", gebe den Namen der Industrie die du " + players[choosen_player].name + " geben willst ein: ")
for industry in player.industries:
if answer == industry.name and player.industries[industry] > 0:
give_industry = industry
true = 0
player.industries[give_industry] -= 1
player.industries[get_industry] += 1
players[choosen_player].industries[give_industry] += 1
players[choosen_player].industries[get_industry] -= 1
class Landmark:
def __init__(self, name, cost, modifier_type, description):
global landmarks
self.name = name
self.cost = cost
self.modifier_type = modifier_type
self.description = description
landmarks.append(self)
def get_players():
global players, num_player, names
players = []
names = input("Gebe die Namen der Mitspieler an: ")
names = names.split()
players = [Player(name) for name in names]
num_player = len(names)
def next_turn():
global turn, player_at_turn, num_player, players, roll, purchases_this_turn
purchases_this_turn = 0
answer = ""
rerolls = 1
turn += 1
player_at_turn += 1
if player_at_turn == num_player:
player_at_turn = 0
clrprint("[" + str(turn) + "]", "Am Zug ist:", players[player_at_turn].name, clr = "b,d,r")
while True:
if players[player_at_turn].landmarks[station] == 1:
while True:
if answer == "nein":
break
answer = input(players[player_at_turn].name + ", willst du 2 Würfel werfen? (ja/nein) ")
if answer == "ja":
roll1 = random.randint(1, 6)
roll2 = random.randint(1, 6)
roll = roll1 + roll2
print("Gewürfelt wurde eine: " + str(roll1) + " und eine: " + str(roll2) + " das macht eine: " + str(roll))
break
elif answer == "nein":
roll = random.randint(1, 6)
print("Gewürfelt wurde eine: " + str(roll))
break
else:
roll = random.randint(1, 6)
print("Gewürfelt wurde eine: " + str(roll))
if players[player_at_turn].landmarks[radio_tower] == 1 and rerolls > 0:
while True:
answer = input("\n" + players[player_at_turn].name + ", willst du neu werfen? (ja/nein)")
if answer == "nein" or answer == "ja":
rerolls -= 1
break
else:
break
stats_profite = ""
for player in players:
stats_profite += "\n" + player.name + "'s Profite:"
for industry in industries:
if industry in player.industries:
industry.get_profit(player)
player.money += industry.profit
if industry.profit > 0:
stats_profite += "\n" + industry.name + ": " + str(industry.profit)
clrprint(stats_profite, clr = "d")
get_stats()
def end_turn():
global player_at_turn
if players[player_at_turn].landmarks[amusement_park] == 1:
player_at_turn -= 1
def get_stats():
global players
for player in players:
clrprint("\n-" + player.name + "-", "\nGeld: ", str(player.money) + "\nIndustrien: ", clr = "d,y,d")
for industry in player.industries:
if player.industries[industry] == 0:
continue
clrprint(industry.name, ": " + str(player.industries[industry]), clr = industry.text_colour + ",d")
def setup_shop_deck():
global num_player, industries, shop_deck
regular_card_num = round(num_player * 0.5) + 4
special_card_num = num_player
shop_deck = []
for industry in industries:
if industry.shop_rarity == "regular":
for x in range(0, regular_card_num):
shop_deck.append(industry)
elif industry.shop_rarity == "special":
for x in range(0, special_card_num):
shop_deck.append(industry)
random.shuffle(shop_deck)
def update_shop():
global shop_deck, shop
while len(shop) != 10:
if len(shop_deck) == 0:
break
elif shop_deck[0] in shop:
shop[shop_deck[0]] += 1
del shop_deck[0]
elif shop_deck[0] not in shop:
shop[shop_deck[0]] = 1
del shop_deck[0]
def view_shop():
global shop, industries, player_at_turn, purchases_this_turn
update_shop()
for industry in shop:
dice_numbers = ""
for dice_number in industry.dice_rolls:
dice_numbers += " " + str(dice_number)
if industry.profit_modifier_type == "own" or industry.profit_modifier_type == "tv_station" or industry.profit_modifier_type == "buisness_center" or industry.profit_modifier_type == "stadium":
dice_numbers += " (Nur deine Würfe)"
elif industry.profit_modifier_type == "all":
dice_numbers += " (Alle Würfe)"
elif industry.profit_modifier_type == "steal":
dice_numbers += " (Die Würfe der Anderen)"
clrprint("[" + str(shop[industry]) + "]", industry.name, "\nKosten:", str(industry.cost) + "\n" + industry.description + "\nWurfzahlen: " + dice_numbers + "\n", clr = "d," + industry.text_colour + ",y,d")
clrprint("\n" + "Du hast: ", str(players[player_at_turn].money) + " Münzen", clr = "d,y")
if purchases_this_turn < 1:
true = 1
while true == 1:
answer = input("\nWas willst du machen?(zurück/kaufen NAME)")
if answer == "zurück":
break
elif "kaufen" in answer.split():
answer = answer.split()
answer.remove("kaufen")
for industry in industries:
if industry.name == answer[0] and industry.cost <= players[player_at_turn].money:
if shop[industry] == 1:
del shop[industry]
purchases_this_turn += 1
players[player_at_turn].industries[industry] += 1
players[player_at_turn].money -= industry.cost
true = 0
break
elif shop[industry] > 1:
purchases_this_turn += 1
shop[industry] -= 1
players[player_at_turn].industries[industry] += 1
players[player_at_turn].money -= industry.cost
true = 0
break
ask_what_to_do()
def view_landmarks():
global landmarks, player_at_turn, purchases_this_turn
clrprint(players[player_at_turn].name + "'s", "Projekte", clr = "d,y")
for landmark in landmarks:
if players[player_at_turn].landmarks[landmark] == 1:
building_status = "[abgeschlossen]"
else:
building_status = "[ noch im bau ]"
clrprint("\n" + building_status, landmark.name + "\nKosten:", str(landmark.cost) + "\n" + landmark.description, clr = "d,y,d")
clrprint("\n" + "Du hast: ", str(players[player_at_turn].money) + " Münzen", clr = "d,y")
if purchases_this_turn < 1:
true = 1
while true == 1:
answer = input("\nWas willst du machen?(zurück/bauen NAME)")
if answer == "zurück":
break
elif "bauen" in answer.split():
answer = answer.split()
answer.remove("bauen")
for landmark in landmarks:
if landmark.name == answer[0] and landmark.cost <= players[player_at_turn].money and players[player_at_turn].landmarks[landmark] < 1:
purchases_this_turn += 1
players[player_at_turn].landmarks[landmark] += 1
players[player_at_turn].money -= landmark.cost
true = 0
break
ask_what_to_do()
def ask_what_to_do():
global player_at_turn
while True:
answer = input("\n" + players[player_at_turn].name + ", Was willst du machen?(projekt/shop/zug beenden)")
if answer == "projekt":
view_landmarks()
break
elif answer == "shop":
view_shop()
break
elif answer == "zug beenden":
end_turn()
break
def main_game_loop():
global shop, turn, player_at_turn, landmarks
turn = 0
shop = {}
player_at_turn = -1
get_players()
setup_shop_deck()
update_shop()
player_that_won = None
while player_that_won == None:
next_turn()
ask_what_to_do()
for player in players:
build_landmarks = 0
for landmark in player.landmarks:
if player.landmarks[landmark] == 1:
build_landmarks += 1
if build_landmarks == len(landmarks):
player_that_won = players[player_at_turn]
clrprint("\n\n==", "Gratulation", player_that_won.name, "du hast gewonnen!", "==\n\n", clr = "d,b,r,b,d")
input("Drücke enter/return um nochmal zu spielen")
main_game_loop()
#def industries:
industries = []
wheat_field = Industry("Feld", 10, 10, 0, [], "all", "regular", [1], "b", "Erhalte 10 Münzen aus der Bank")
ranch = Industry("Bauernhof", 10, 10, 0, [], "all", "regular", [2], "b", "Erhalte 10 Münzen aus der Bank")
forest = Industry("Wald", 30, 10, 50, [], "all", "regular", [5], "b", "Erhalte 10 Münzen aus der Bank")
mine = Industry("Bergwerk", 60, 50, 0, [], "all", "regular", [9], "b", "Erhalte 50 Münzen aus der Bank")
apple_orchard = Industry("Apfelplantage", 30, 30, 0, [], "all", "regular", [10], "b", "Erhalte 30 Münzen aus der Bank")
bakery = Industry("Bäckerei", 10, 10, 0, [], "own", "regular", [2, 3], "g", "Erhalte 10 Münzen aus der Bank")
convenience_store = Industry("Mini-Markt", 20, 30, 0, [], "own", "regular", [4], "g", "Erhalte 30 Münzen aus der Bank")
cheese_factory = Industry("Molkerei", 50, 0, 30, [ranch], "own", "regular", [7], "g", "Erhalte 30 Münzen aus der Bank für jeden Bauernhof")
furniture_factory = Industry("Möbelfabrik", 30, 0, 30, [forest, mine], "own", "regular", [8], "g", "Erhalte 30 Münzen aus der Bank für jeden Wald und jedes Bergwerk")
fruit_and_vegetable_market = Industry("Markthalle", 20, 0, 20, [wheat_field, apple_orchard], "own", "regular", [11, 12], "g", "Erhalte 20 Münzen aus der Bank für jedes Feld und jede Apfelplantage")
cafe = Industry("Cafe", 20, 0, 10, [], "steal", "regular", [3], "r", "Erhalte 10 Münzen von dem Mitspieler der eine 3 gewürfelt hat")
family_restaurant = Industry("Familienrestaurant", 30, 20, 0, [], "steal", "regular", [9, 10], "r", "Erhalte 20 Münzen von dem Mitspieler der eine 9 oder 10 gewürfelt hat")
stadium = Industry("Stadion", 60, 0, 20, [], "stadium", "special", [6], "p", "Erhalte von jedem Mitspieler 20 Münzen")
tv_station = Industry("Fernsehsender", 70, 0, 50, [], "tv_station", "special", [6], "p", "Erhalte von einem Mitspieler deiner Wahl 50 Münzen")
buisness_center = Industry("Bürohaus", 80, 0, 0, [], "buisness_center", "special", [6], "p", "Tausche 1 Karte mit einem Mitspieler deiner Wahl")
#def landmarks:
landmarks = []
station = Landmark("Bahnhof", 40, "station", "Würfle mit 2 Würfeln")
shopping_mall = Landmark("Einkaufszentrum", 100, "shopping_mall", "Erhalte +10 Münzen für jedes Cafe, Familienrestaurant, jede Bäckerei und jeden Mini-Markt")
amusement_park = Landmark("Freizeitpark", 160, "amusement_park", "Mache einen weiteren Zug wenn du einen Pasch wirfst")
radio_tower = Landmark("Funkturm", 220, "radio_tower", "Einmal im Zug kannst du deine Würfel neu werfen")
main_game_loop()