Skip to content

Commit

Permalink
Attempt 2 to fix infinite loop.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiahuita committed Mar 27, 2024
1 parent d2d5196 commit 2d584fe
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 18 deletions.
2 changes: 1 addition & 1 deletion example.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from new_york_minute import solo_game, multiplayer_game, custom_game, load_game
from new_york_minute.game import solo_game, multiplayer_game, custom_game, load_game

# Example 1: Solo game
print("Example 1: Solo game")
Expand Down
40 changes: 34 additions & 6 deletions src/new_york_minute/__main__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,39 @@
from new_york_minute.game import solo_game
from new_york_minute.game import solo_game, multiplayer_game, custom_game, load_game

def main():
print("Welcome to New York Minute! Starting New Game!")
player_name = input("What's your name? ")
player_dream = input("What's your dream in New York City? ")
player_background = input("Choose your background (e.g. Artist/Entrepreneur/Student): ")
solo_game(player_name, player_dream, player_background)
print("Welcome to New York Minute!")
game_type = input("Choose the type of game ('solo', 'multiplayer', 'custom', 'load'): ")
if game_type == 'solo':
print("Starting New Game!")
player_name = input("What's your name? ")
player_dream = input("What's your dream in New York City? ")
player_background = input("Choose your background (e.g. Artist/Entrepreneur/Student): ")
solo_game(player_name, player_dream, player_background)
elif game_type == 'multiplayer':
num_players = int(input("Enter the number of players: "))
player_names = []
player_dreams = []
player_backgrounds = []
for i in range(num_players):
player_names.append(input(f"Enter the name for Player {i+1}: "))
player_dreams.append(input(f"Enter the dream for Player {i+1}: "))
player_backgrounds.append(input(f"Enter the background for Player {i+1}: "))
multiplayer_game(player_names, player_dreams, player_backgrounds)
elif game_type == 'custom':
num_players = int(input("Enter the number of players: "))
player_names = []
player_dreams = []
player_backgrounds = []
for i in range(num_players):
player_names.append(input(f"Enter the name for Player {i+1}: "))
player_dreams.append(input(f"Enter the dream for Player {i+1}: "))
player_backgrounds.append(input(f"Enter the background for Player {i+1}: "))
custom_game(num_players, player_names, player_dreams, player_backgrounds)
elif game_type == 'load':
save_file = input("Enter the path to the save file: ")
load_game(save_file)
else:
print("Invalid game type. Please try again.")

if __name__ == "__main__":
main()
24 changes: 13 additions & 11 deletions src/new_york_minute/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,21 @@ def start_game(players, actions=None):
if isinstance(players, list):
for player in players:
print(f"Welcome, {player.name}!")
completed_players = []
while len(completed_players) < len(players):
for player in players:
if player not in completed_players:
if play_turn(player, actions):
completed_players.append(player)
print(f"{player.name} has achieved their dream!")
else:
print(f"{player.name}'s turn is over.")
print("All players have completed their turns.")
else:
print(f"Welcome, {players.name}!")

completed_players = []
while len(completed_players) < len(players):
for player in players:
if player not in completed_players:
if play_turn(player, actions):
completed_players.append(player)
print(f"{player.name} has achieved their dream!")
else:
print(f"{player.name}'s turn is over.")
print("All players have completed their turns.")
while True:
if play_turn(players, actions):
break

print("The game has ended. Thank you for playing!")

Expand Down

0 comments on commit 2d584fe

Please sign in to comment.