MCPcopy Create free account
hub / github.com/geekcomputers/Python / play_snakes_and_ladders

Function play_snakes_and_ladders

BoardGame-CLI/python.py:60–86  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

58
59# Main game loop
60def play_snakes_and_ladders():
61 player1_position = 1
62 player2_position = 1
63
64 player1_name = input("Enter the name of Player 1: ")
65 player2_name = input("Enter the name of Player 2: ")
66
67 current_player = player1_name
68
69 while player1_position < 100 and player2_position < 100:
70 print(f"\n{current_player}'s turn:")
71 input("Press Enter to roll the die.")
72
73 if current_player == player1_name:
74 player1_position = take_turn(player1_position, player1_name)
75 current_player = player2_name
76 else:
77 player2_position = take_turn(player2_position, player2_name)
78 current_player = player1_name
79
80 print("\nGame Over!")
81 print(f"{player1_name} ended at square {player1_position}.")
82 print(f"{player2_name} ended at square {player2_position}.")
83 if player1_position == 100:
84 print(f"{player1_name} won!")
85 elif player2_position == 100:
86 print(f"{player2_name} won!")
87
88
89# Start the game

Callers 1

python.pyFile · 0.85

Calls 1

take_turnFunction · 0.85

Tested by

no test coverage detected