From 397e4c323a0366dddb7d772f8c9d1058fffed9b9 Mon Sep 17 00:00:00 2001 From: informaniac Date: Tue, 2 Jan 2018 21:06:24 +0100 Subject: [PATCH] renamed BalanceUtil._get_raw_data to _get_raw_player_data moved player ready function into BalanceUtil object --- blup/balance_util.py | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/blup/balance_util.py b/blup/balance_util.py index 8fa8626..915a375 100644 --- a/blup/balance_util.py +++ b/blup/balance_util.py @@ -33,22 +33,6 @@ class BalanceSocket(object): p0x, p0y, p1x, p1y = struct.unpack('bbbb', data) return p0x, p0y, p1x, p1y - def get_player1_ready(self): - """ - check if someone is on board 1 - :return: true if someone is on the board - """ - p0x, p0y, p1x, p1y = self._get_raw_data() - return p0x > -128 or p0y > -128 - - def get_player2_ready(self): - """ - check if someone is on board 2 - :return: true if someone is on the board - """ - p0x, p0y, p1x, p1y = self._get_raw_data() - return p1x > -128 or p1y > -128 - class BalanceUtil(BalanceSocket): def __init__(self, balance_server_socket, player_id): @@ -60,7 +44,7 @@ class BalanceUtil(BalanceSocket): super(BalanceUtil, self).__init__(balance_server_socket) self.player_id = player_id - def _get_raw_data(self): + def _get_raw_player_data(self): self.socket.send(b'a') data = self.socket.recv(4) p0x, p0y, p1x, p1y = struct.unpack('bbbb', data) @@ -69,6 +53,14 @@ class BalanceUtil(BalanceSocket): else: return p1x, p1y + def get_player_ready(self): + """ + check if someone is on the board + :return: true if someone is on the board + """ + p_x, p_y = self._get_raw_player_data() + return p_x > -128 or p_y > -128 + def get_raw_2dir_y(self): """ Get raw 2-directional data from the y axis of the board. @@ -76,12 +68,12 @@ class BalanceUtil(BalanceSocket): in balance pong :return: raw y axis balance value """ - x_bal, y_bal = self._get_raw_data() + x_bal, y_bal = self._get_raw_player_data() return y_bal def get_2dir_y(self, threshold): threshold = sanitize_threshold(threshold) - x_bal, y_bal = self._get_raw_data() + x_bal, y_bal = self._get_raw_player_data() if x_bal == -128 or y_bal == -128: return Direction.QUIT elif abs(y_bal) < threshold: @@ -92,12 +84,12 @@ class BalanceUtil(BalanceSocket): return Direction.DOWN def get_raw_2dir_x(self): - x_bal, y_bal = self._get_raw_data() + x_bal, y_bal = self._get_raw_player_data() return x_bal def get_2dir_x(self, threshold): threshold = sanitize_threshold(threshold) - x_bal, y_bal = self._get_raw_data() + x_bal, y_bal = self._get_raw_player_data() if x_bal == -128 or y_bal == -128: return Direction.QUIT elif abs(x_bal) < threshold: @@ -108,7 +100,7 @@ class BalanceUtil(BalanceSocket): return Direction.LEFT def get_raw_4dir(self): - return self._get_raw_data() + return self._get_raw_player_data() def get_4dir(self, threshold): """ @@ -121,7 +113,7 @@ class BalanceUtil(BalanceSocket): :return: Enum Direction value of direction or event """ threshold = sanitize_threshold(threshold) - x_bal, y_bal = self._get_raw_data() + x_bal, y_bal = self._get_raw_player_data() if x_bal == -128 or y_bal == -128: return Direction.QUIT elif abs(x_bal) < threshold and abs(y_bal) < threshold: