|
|
@ -130,6 +130,15 @@ class B4lancePong(object): |
|
|
|
else: |
|
|
|
else: |
|
|
|
self.__dimension = blup.frame.FrameDimension(18, 8, 2, 1) |
|
|
|
self.__dimension = blup.frame.FrameDimension(18, 8, 2, 1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def gametickcb(self): |
|
|
|
|
|
|
|
for i, p in enumerate(self.__players): |
|
|
|
|
|
|
|
if isinstance(p, pong.PongBot): |
|
|
|
|
|
|
|
print('bot in game') |
|
|
|
|
|
|
|
if (isinstance(p, pong.PongBot) and \ |
|
|
|
|
|
|
|
self.__bplayers[i].get_player_ready()): |
|
|
|
|
|
|
|
print('second player joined, cancelling current game') |
|
|
|
|
|
|
|
self.__playground.cancel() |
|
|
|
|
|
|
|
|
|
|
|
def runGame(self): |
|
|
|
def runGame(self): |
|
|
|
print('starting a game...') |
|
|
|
print('starting a game...') |
|
|
|
scoreLeft = 0 |
|
|
|
scoreLeft = 0 |
|
|
@ -141,13 +150,13 @@ class B4lancePong(object): |
|
|
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
|
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
|
|
sock.connect(self.__balanceserver) |
|
|
|
sock.connect(self.__balanceserver) |
|
|
|
print('connected!') |
|
|
|
print('connected!') |
|
|
|
bplayers = [ |
|
|
|
self.__bplayers = [ |
|
|
|
blup.balance_util.BalanceUtil(sock, 0), |
|
|
|
blup.balance_util.BalanceUtil(sock, 0), |
|
|
|
blup.balance_util.BalanceUtil(sock, 1) |
|
|
|
blup.balance_util.BalanceUtil(sock, 1) |
|
|
|
] |
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
while not (bplayers[0].get_player_ready() or |
|
|
|
while not (self.__bplayers[0].get_player_ready() or |
|
|
|
bplayers[1].get_player_ready()): |
|
|
|
self.__bplayers[1].get_player_ready()): |
|
|
|
time.sleep(0.1) |
|
|
|
time.sleep(0.1) |
|
|
|
|
|
|
|
|
|
|
|
for i in range(5): |
|
|
|
for i in range(5): |
|
|
@ -155,8 +164,8 @@ class B4lancePong(object): |
|
|
|
self.__out.sendFrame(frame) |
|
|
|
self.__out.sendFrame(frame) |
|
|
|
|
|
|
|
|
|
|
|
print('waiting for second player...') |
|
|
|
print('waiting for second player...') |
|
|
|
if (bplayers[0].get_player_ready() and |
|
|
|
if (self.__bplayers[0].get_player_ready() and |
|
|
|
bplayers[1].get_player_ready()): |
|
|
|
self.__bplayers[1].get_player_ready()): |
|
|
|
break |
|
|
|
break |
|
|
|
time.sleep(1) |
|
|
|
time.sleep(1) |
|
|
|
|
|
|
|
|
|
|
@ -164,9 +173,9 @@ class B4lancePong(object): |
|
|
|
for i in [0, 1]: |
|
|
|
for i in [0, 1]: |
|
|
|
paddle = self.__playground.leftPaddle if i == 0 else \ |
|
|
|
paddle = self.__playground.leftPaddle if i == 0 else \ |
|
|
|
self.__playground.rightPaddle |
|
|
|
self.__playground.rightPaddle |
|
|
|
if bplayers[i].get_player_ready(): |
|
|
|
if self.__bplayers[i].get_player_ready(): |
|
|
|
player = BalanceBoardPlayer(self.__playground, paddle, |
|
|
|
player = BalanceBoardPlayer(self.__playground, paddle, |
|
|
|
bplayers[i]) |
|
|
|
self.__bplayers[i]) |
|
|
|
else: |
|
|
|
else: |
|
|
|
player = pong.PongBot(self.__playground, paddle, 3) |
|
|
|
player = pong.PongBot(self.__playground, paddle, 3) |
|
|
|
self.__players.append(player) |
|
|
|
self.__players.append(player) |
|
|
@ -184,7 +193,10 @@ class B4lancePong(object): |
|
|
|
self.__out.sendFrame(frame) |
|
|
|
self.__out.sendFrame(frame) |
|
|
|
time.sleep(1) |
|
|
|
time.sleep(1) |
|
|
|
|
|
|
|
|
|
|
|
while max(scoreLeft, scoreRight) < __MAX_SCORE__: |
|
|
|
self.__playground.addGameTickCallback(self.gametickcb) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (max(scoreLeft, scoreRight) < __MAX_SCORE__ and |
|
|
|
|
|
|
|
not self.__playground.cancelled): |
|
|
|
winner = self.__playground.play() |
|
|
|
winner = self.__playground.play() |
|
|
|
if winner is self.__playground.leftPaddle: |
|
|
|
if winner is self.__playground.leftPaddle: |
|
|
|
scoreLeft += 1 |
|
|
|
scoreLeft += 1 |
|
|
@ -192,6 +204,7 @@ class B4lancePong(object): |
|
|
|
scoreRight += 1 |
|
|
|
scoreRight += 1 |
|
|
|
pong.displayScore(self.__out, self.__dimension, scoreLeft, scoreRight, 3000) |
|
|
|
pong.displayScore(self.__out, self.__dimension, scoreLeft, scoreRight, 3000) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not self.__playground.cancelled: |
|
|
|
for i in range(3): |
|
|
|
for i in range(3): |
|
|
|
frame = blup.frame.Frame(self.__dimension) |
|
|
|
frame = blup.frame.Frame(self.__dimension) |
|
|
|
self.__out.sendFrame(frame) |
|
|
|
self.__out.sendFrame(frame) |
|
|
|