-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplay_game.py
32 lines (31 loc) · 895 Bytes
/
play_game.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from ping_thing import PingThing
#Runs a game with two players, represented by Pingthings
#Players score points when they do not receive a response for their ping
#num_plays determines the number of games played
#if there is a tie, a game with the same settings repeats
def PlayGame (num_plays = 1, player1 = PingThing, player2 = PingThing):
sum1 = 0
sum2 = 0
for i in range(num_plays):
while True:
if player1.play() == True:
sum1 += 1
break
if player2.play() == True:
sum2 += 1
break
print("---GAME---")
print("Score: "+str(sum1)+"-"+str(sum2))
if sum1 == sum2:
print ("---TIE---")
return PlayGame(num_plays, player1, player2)
if sum1 > sum2:
print("---PLAYER 1 WINS---")
player1.purge()
player2.purge()
return player1
if sum1 < sum2:
print("---PLAYER 2 WINS---")
player1.purge()
player2.purge()
return player2