| 161 | |
| 162 | |
| 163 | def 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 | |
| 197 | def pre_game2(clientSocket, clientAddress): |