Няма описание

actions.py 8.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. import random
  2. class Actions:
  3. def __init__(self, game):
  4. self.game = game
  5. def _perform_action(self, action_name, description, cost, success_effect, failure_effect, success_chance, influence_required=0, success_policy=None):
  6. print(f"Scenario: {description}")
  7. if self.game.money < cost:
  8. print(f"Not enough money to {action_name.lower()}.")
  9. return
  10. if self.game.influence < influence_required:
  11. print(f"Not enough influence to {action_name.lower()}.")
  12. return
  13. self.game.money -= cost
  14. if random.randint(1, 100) <= success_chance:
  15. for key, value in success_effect.items():
  16. setattr(self.game, key, getattr(self.game, key) + value)
  17. if success_policy:
  18. self.game.policies.append(success_policy)
  19. print(f"Success! {description} was successful.")
  20. else:
  21. for key, value in failure_effect.items():
  22. setattr(self.game, key, getattr(self.game, key) + value)
  23. print(f"Failure! {description} was unsuccessful.")
  24. def campaign(self):
  25. self._perform_action(
  26. action_name="Campaign",
  27. description="Door-to-Door Campaigning",
  28. cost=10,
  29. success_effect={"public_support": 10},
  30. failure_effect={"public_support": -5},
  31. success_chance=60
  32. )
  33. def pass_legislation(self):
  34. self._perform_action(
  35. action_name="Pass Legislation",
  36. description="Healthcare Reform Bill",
  37. cost=20,
  38. influence_required=30,
  39. success_effect={"public_support": 20},
  40. success_policy="Healthcare Reform Bill",
  41. failure_effect={},
  42. success_chance=100
  43. )
  44. def hold_rally(self):
  45. self._perform_action(
  46. action_name="Hold Rally",
  47. description="Community Unity Rally",
  48. cost=15,
  49. success_effect={"public_support": 15},
  50. failure_effect={"public_support": -5},
  51. success_chance=70
  52. )
  53. def media_campaign(self):
  54. print("Scenario: Media Campaign")
  55. print("Choose the type of media campaign:")
  56. print("1. Online (Facebook)")
  57. print("2. Online (TikTok)")
  58. print("3. Online (Twitter)")
  59. print("4. Online (Instagram)")
  60. print("5. Offline (TV, Radio, Newspapers)")
  61. choice = input("Enter the number of your choice: ")
  62. demographics_effect = {
  63. "1": {"age": "young", "gender": "female", "education": "medium"},
  64. "2": {"age": "young", "gender": "female", "education": "low"},
  65. "3": {"age": "middle-aged", "gender": "male", "education": "high"},
  66. "4": {"age": "young", "gender": "female", "education": "high"},
  67. "5": {"age": "senior", "gender": "male", "education": "low"}
  68. }
  69. if choice in demographics_effect:
  70. cost = 25
  71. success_chance = random.randint(1, 100)
  72. if self.game.money < cost:
  73. print("Not enough money to launch a media campaign.")
  74. return
  75. self.game.money -= cost
  76. if success_chance <= 80:
  77. self.game.public_support += 25
  78. dem = demographics_effect[choice]
  79. self.game.supporters.increase_support(dem)
  80. print(f"The {choice} campaign resonates with the public, increasing support by 25% and boosting support among {dem}.")
  81. else:
  82. self.game.public_support -= 10
  83. print(f"The {choice} campaign backfires, leading to a decrease in support by 10%.")
  84. else:
  85. print("Invalid choice. Please try again.")
  86. def fundraise(self):
  87. print("Scenario: High-Profile Fundraiser Dinner")
  88. print("You host an exclusive fundraiser dinner with influential donors and supporters.")
  89. success_chance = random.randint(1, 100)
  90. if success_chance <= 50:
  91. funds_raised = random.randint(20, 50)
  92. self.game.money += funds_raised
  93. print(f"The event is a success, raising ${funds_raised}.")
  94. else:
  95. print("Poor attendance results in no funds being raised.")
  96. def debate(self):
  97. print("Scenario: Televised Debate with Opponent")
  98. print("You participate in a live televised debate against a key opponent, addressing critical issues and defending your policies.")
  99. opponent = random.choice(self.game.opponents)
  100. success_chance = random.randint(1, 100)
  101. if success_chance <= 50:
  102. self.game.influence += 20
  103. self.game.public_support += 10
  104. print(f"You outshine your opponent, increasing influence by 20 and public support by 10%.")
  105. else:
  106. self.game.influence -= 10
  107. self.game.public_support -= 5
  108. print(f"The debate goes poorly, decreasing influence by 10 and public support by 5% as voters favor {opponent}'s arguments.")
  109. def set_tax_policy(self):
  110. print("Scenario: Set Tax Policy")
  111. new_tax_rate = int(input("Enter the new tax rate (0-100): "))
  112. if 0 <= new_tax_rate <= 100:
  113. self.game.tax_rate = new_tax_rate
  114. print(f"Tax rate set to {self.game.tax_rate}%.")
  115. if new_tax_rate > 30:
  116. self.game.public_support -= 10
  117. print("High tax rate decreases public support by 10%.")
  118. elif new_tax_rate < 10:
  119. self.game.public_support += 10
  120. print("Low tax rate increases public support by 10%.")
  121. else:
  122. print("Invalid tax rate. Please enter a value between 0 and 100.")
  123. def invest_in_sector(self):
  124. print("Scenario: Invest in a Sector")
  125. sectors = ["Infrastructure", "Education", "Healthcare"]
  126. print(f"Sectors available for investment: {', '.join(sectors)}")
  127. sector_choice = input("Enter the sector you want to invest in: ")
  128. if sector_choice in sectors:
  129. investment_amount = int(input("Enter the amount you want to invest: "))
  130. if self.game.money >= investment_amount:
  131. self.game.money -= investment_amount
  132. self.game.gdp += investment_amount * 1.5 # Example multiplier
  133. self.game.unemployment_rate -= 1 # Reduce unemployment
  134. print(f"Invested ${investment_amount} in {sector_choice}. GDP increased by ${investment_amount * 1.5} and unemployment rate decreased.")
  135. else:
  136. print("Not enough money to invest.")
  137. else:
  138. print("Invalid sector choice.")
  139. def allocate_military_budget(self):
  140. print("Scenario: Allocate Military Budget")
  141. additional_budget = int(input("Enter the additional military budget (0-100): "))
  142. if 0 <= additional_budget <= self.game.money:
  143. self.game.money -= additional_budget
  144. self.game.military_budget += additional_budget
  145. self.game.military_strength += additional_budget // 2 # Example conversion rate
  146. print(f"Allocated an additional ${additional_budget} to the military budget. Military strength increased by {additional_budget // 2}.")
  147. else:
  148. print("Invalid budget allocation. Please enter a value within your available money.")
  149. def opponent_friction(self):
  150. actions = [
  151. ("Negative Campaign", "Your opponent launches a negative campaign against you. Public support decreases by 10%.", -10, 0, 0),
  152. ("Political Sabotage", "Your opponent sabotages your fundraising event. You raise no money.", 0, 0, -1),
  153. ("Influence Loss", "Your opponent spreads rumors, reducing your influence. Influence decreases by 15%.", 0, -15, 0)
  154. ]
  155. action = random.choice(actions)
  156. print(f"Opponent Action: {action[0]}")
  157. print(f"{action[1]}")
  158. self.game.public_support += action[2]
  159. self.game.influence += action[3]
  160. if action[0] == "Political Sabotage":
  161. return False # Indicate that fundraising failed due to sabotage
  162. return True
  163. def foreign_interference(self):
  164. actions = [
  165. ("Russia", "Russia interferes with your campaign, spreading disinformation and causing distrust among voters. Public support decreases by 15%.", -15, 0, 0),
  166. ("China", "China launches a cyber-attack on your campaign infrastructure, reducing your influence. Influence decreases by 20%.", 0, -20, 0),
  167. ("Foreign Sabotage", "Opposition countries collaborate to sabotage your fundraising event. You raise no money.", 0, 0, -1)
  168. ]
  169. action = random.choice(actions)
  170. print(f"Foreign Interference: {action[0]}")
  171. print(f"{action[1]}")
  172. self.game.public_support += action[2]
  173. self.game.influence += action[3]
  174. if action[0] == "Foreign Sabotage":
  175. return False # Indicate that fundraising failed due to sabotage
  176. return True