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

Function game2_2

projects/multiplayer_socket/server.py:163–194  ·  view source on GitHub ↗
(clientAddress)

Source from the content-addressed store, hash-verified

161
162
163def game2_2(clientAddress):
164 while not attributes["break2"]:
165 if attributes["mes"] != "":
166 attributes["player2"].send(
167 "Play".encode()
168 ) # send prompt to player2 to play
169 attributes["mes"] = (
170 attributes["player2"].recv(2048).decode().upper()
171 ) # receive player 2's choice
172 attributes["rps"][1] = attributes["mes"]
173 ans = decision() # check decision
174 if ans != -1:
175 score[ans - 1] += 1 # update score
176 if attributes["rps_count"] == 3: # set result when 3 tries done
177 if score[0] > score[1]:
178 attributes["mes"] = "Player 1 won"
179 elif score[0] < score[1]:
180 attributes["mes"] = "Player 2 won"
181 else:
182 attributes["mes"] = "Draw"
183 attributes["break2"] = 1
184 else:
185 attributes["mes"] = ",".join(attributes["rps"]) + ",".join(
186 map(str, score)
187 )
188 attributes["player1"].send(
189 attributes["mes"].encode()
190 ) # send result to player1
191 attributes["player2"].send(
192 attributes["mes"].encode()
193 ) # send result to player2
194 attributes["mes"] = ""
195
196
197def pre_game2(clientSocket, clientAddress):

Callers 1

pre_game2Function · 0.85

Calls 1

decisionFunction · 0.85

Tested by

no test coverage detected