MCPcopy Create free account
hub / github.com/Mrinank-Bhowmick/python-beginner-projects / play_game

Function play_game

projects/HandCricket/main.py:49–89  ·  view source on GitHub ↗
(overs, player1_choice, player2_choice, difficulty=1)

Source from the content-addressed store, hash-verified

47
48# Function to handle the main gameplay for two players
49def play_game(overs, player1_choice, player2_choice, difficulty=1):
50 player1_score = 0
51 player2_score = 0
52 player1_wickets = 10
53 player2_wickets = 10
54
55 print("\nMatch Summary")
56 print("=============")
57 print(f"Overs: {overs}")
58
59 for over in range(overs):
60 print(
61 f"\nOver {over + 1}, Player 1: {player1_wickets} wickets left, Player 2: {player2_wickets} wickets left"
62 )
63
64 if player1_choice == "1":
65 # Player 1 bats first
66 player1_score, player1_wickets = user_turn(
67 player1_score, player1_wickets, "1", over
68 )
69
70 # Player 2 bowls
71 player2_score, player2_wickets = user_turn(
72 player2_score, player2_wickets, "2", over
73 )
74 else:
75 # Player 2 bowls first
76 player2_score, player2_wickets = user_turn(
77 player2_score, player2_wickets, "2", over
78 )
79
80 # Player 1 bats
81 player1_score, player1_wickets = user_turn(
82 player1_score, player1_wickets, "1", over
83 )
84
85 # Display the scoreboard after each over
86 display_scoreboard(player1_score, player2_score, over)
87
88 # Return the final scores
89 return player1_score, player2_score
90
91
92# Function for a player's turn

Callers 1

mainFunction · 0.70

Calls 2

user_turnFunction · 0.70
display_scoreboardFunction · 0.70

Tested by

no test coverage detected