From 810180a173f8acf19a6661e543a15f98b3d87875 Mon Sep 17 00:00:00 2001 From: huangjielun <2872405629@qq.com> Date: Sat, 17 Sep 2022 10:28:55 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=98=E9=9C=80=E8=A6=81=E5=8A=A0=E5=85=A5?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E5=AF=B9=E6=96=B9=E7=9A=84=E7=A7=BB=E5=8A=A8?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E5=90=88=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/config.txt | 2 +- server/server.py | 431 +++++++++--------- .../Client_connection.cpython-38.pyc | Bin 4049 -> 4032 bytes src/__pycache__/init.cpython-38.pyc | Bin 6183 -> 6183 bytes src/__pycache__/socket_client.cpython-38.pyc | Bin 1473 -> 1565 bytes src/__pycache__/start_game.cpython-38.pyc | Bin 3702 -> 3702 bytes src/main.py | 10 +- src/main_an.py | 24 +- src/time_diplay.py | 32 ++ 9 files changed, 283 insertions(+), 216 deletions(-) create mode 100644 src/time_diplay.py diff --git a/server/config.txt b/server/config.txt index 1ead9da..594c877 100644 --- a/server/config.txt +++ b/server/config.txt @@ -1,5 +1,5 @@ SOCKET_HOST=127.0.0.1 SOCKET_PORT=50005 MAX_WAITING_TIME=600 -MAX_THNIKING_TIME=15 +MAX_THNIKING_TIME=30 MAX_TOTAL_TIME=1000 diff --git a/server/server.py b/server/server.py index 0ef5af8..4bf8c30 100644 --- a/server/server.py +++ b/server/server.py @@ -2,250 +2,267 @@ import socket import sys import json -import uuid -import time +import uuid +import time from threading import Thread, Lock -if(sys.version[:1] == "3"): - import queue as Queue - from _thread import * +if (sys.version[:1] == "3"): + import queue as Queue + from _thread import * else: - import Queue - from thread import * + import Queue + from thread import * + class Config: - SOCKET_HOST = '127.0.0.1' # Symbolic name meaning all available interfaces - SOCKET_PORT = 50005 # Arbitrary non-privileged port - MAX_WAITING_TIME = 180 - MAX_THNIKING_TIME = 60 - MAX_TOTAL_TIME = 600 + SOCKET_HOST = '127.0.0.1' # Symbolic name meaning all available interfaces + SOCKET_PORT = 50005 # Arbitrary non-privileged port + MAX_WAITING_TIME = 180 + MAX_THNIKING_TIME = 60 + MAX_TOTAL_TIME = 600 + class Client: - def __init__(self, conn, addr, name, side, time, total): - self.conn = conn - self.addr = addr - self.name = name - self.side = side - self.time = time - self.total = total + def __init__(self, conn, addr, name, side, time, total): + self.conn = conn + self.addr = addr + self.name = name + self.side = side + self.time = time + self.total = total + mutex = Lock() mutex_playing = Lock() playing_ones = {} waiting_players = Queue.Queue() -#init queues -#for games in range(1, 10): + + +# init queues +# for games in range(1, 10): # waiting_players[games] = Queue.Queue() def load_config(): - with open('config.txt', 'r') as f: - for line in f.readlines(): - line = line.strip() - if line.find('SOCKET_HOST=') >= 0: - Config.SOCKET_HOST = line[line.index('=') + 1 : ] - elif line.find('SOCKET_PORT=') >= 0: - Config.SOCKET_PORT = int(line[line.index('=') + 1 : ]) - elif line.find('MAX_WAITING_TIME=') >= 0: - Config.MAX_WAITING_TIME = int(line[line.index('=') + 1 : ]) - elif line.find('MAX_THNIKING_TIME=') >= 0: - Config.MAX_THNIKING_TIME = int(line[line.index('=') + 1 : ]) - elif line.find('MAX_TOTAL_TIME=') >= 0: - Config.MAX_TOTAL_TIME = int(line[line.index('=') + 1 : ]) - else: - pass + with open('config.txt', 'r') as f: + for line in f.readlines(): + line = line.strip() + if line.find('SOCKET_HOST=') >= 0: + Config.SOCKET_HOST = line[line.index('=') + 1:] + elif line.find('SOCKET_PORT=') >= 0: + Config.SOCKET_PORT = int(line[line.index('=') + 1:]) + elif line.find('MAX_WAITING_TIME=') >= 0: + Config.MAX_WAITING_TIME = int(line[line.index('=') + 1:]) + elif line.find('MAX_THNIKING_TIME=') >= 0: + Config.MAX_THNIKING_TIME = int(line[line.index('=') + 1:]) + elif line.find('MAX_TOTAL_TIME=') >= 0: + Config.MAX_TOTAL_TIME = int(line[line.index('=') + 1:]) + else: + pass + def get_counterpart_from(waiting_ones): - counterpart = None - mutex.acquire() - if not waiting_ones.empty(): - counterpart = waiting_ones.get() - mutex.release() - return counterpart + counterpart = None + mutex.acquire() + if not waiting_ones.empty(): + counterpart = waiting_ones.get() + mutex.release() + return counterpart + def to_wait_in_queue(client, the_queue): - mutex.acquire() - the_queue.put(client) - mutex.release() - + mutex.acquire() + the_queue.put(client) + mutex.release() + + def remove_one_from_queue(the_queue): - mutex.acquire() - if (the_queue.qsize() == 1): - the_queue.get() - mutex.release() + mutex.acquire() + if (the_queue.qsize() == 1): + the_queue.get() + mutex.release() + def send_msg_to(client, msg): - packet = json.dumps(msg) - if (sys.version[:1] == "3"): - packet = packet.encode('utf-8') - #print(client.addr[0] + ":" + str(client.addr[1]) + "\t" + str(msg)) - client.conn.send(packet) + packet = json.dumps(msg) + if (sys.version[:1] == "3"): + packet = packet.encode('utf-8') + # print(client.addr[0] + ":" + str(client.addr[1]) + "\t" + str(msg)) + client.conn.send(packet) + def __start_match_between(client0, client1): - match_uuid = str(uuid.uuid4()) - mutex_playing.acquire() - playing_ones[match_uuid] = (client0, client1) - mutex_playing.release() - - client0.side = 0 - client0.time = Config.MAX_THNIKING_TIME - client0.total = Config.MAX_TOTAL_TIME - client1.side = 1 - client1.time = -1 - client1.total = Config.MAX_TOTAL_TIME - - msg0 = { - "status": 1, - "counterpart_name": client1.name, - "game_id": match_uuid, - "side": client0.side, - "think_time": Config.MAX_THNIKING_TIME, - "total_time": Config.MAX_TOTAL_TIME, - } - send_msg_to(client0, msg0) - msg1 = { - "status": 1, - "counterpart_name": client0.name, - "game_id": match_uuid, - "side": client1.side, - "think_time": Config.MAX_THNIKING_TIME, - "total_time": Config.MAX_TOTAL_TIME, - } - send_msg_to(client1, msg1) + match_uuid = str(uuid.uuid4()) + mutex_playing.acquire() + playing_ones[match_uuid] = (client0, client1) + mutex_playing.release() + + client0.side = 0 + client0.time = Config.MAX_THNIKING_TIME + client0.total = Config.MAX_TOTAL_TIME + client1.side = 1 + client1.time = -1 + client1.total = Config.MAX_TOTAL_TIME + + msg0 = { + "status": 1, + "counterpart_name": client1.name, + "game_id": match_uuid, + "side": client0.side, + "think_time": Config.MAX_THNIKING_TIME, + "total_time": Config.MAX_TOTAL_TIME, + } + send_msg_to(client0, msg0) + msg1 = { + "status": 1, + "counterpart_name": client0.name, + "game_id": match_uuid, + "side": client1.side, + "think_time": Config.MAX_THNIKING_TIME, + "total_time": Config.MAX_TOTAL_TIME, + } + send_msg_to(client1, msg1) + def join_game_handler(msg, addr, conn): - new_client = Client(conn, addr, msg['name'], -1, -1, -1) - #game_type = msg["id"] - #the_queue = waiting_players[game_type] - counterpart = get_counterpart_from(waiting_players) - if not counterpart: #wait - to_wait_in_queue(new_client, waiting_players) - return - else: - #counterpart=get_counterpart_from(waiting_players[game_type]) - __start_match_between(new_client, counterpart) + new_client = Client(conn, addr, msg['name'], -1, -1, -1) + # game_type = msg["id"] + # the_queue = waiting_players[game_type] + counterpart = get_counterpart_from(waiting_players) + if not counterpart: # wait + to_wait_in_queue(new_client, waiting_players) + return + else: + # counterpart=get_counterpart_from(waiting_players[game_type]) + __start_match_between(new_client, counterpart) + def quit_game_handler(msg): - match_uuid = msg['game_id'] - if match_uuid is None: - remove_one_from_queue(waiting_players) - return - pairs = None - mutex_playing.acquire() - if (match_uuid in playing_ones): - pairs = playing_ones[match_uuid] - del playing_ones[match_uuid] - mutex_playing.release() - - if pairs is not None: - if(pairs[0].side == msg['side']): - to_notify = pairs[1] - else: - to_notify = pairs[0] - msg = { - "status": 2, #exit - "game_id": match_uuid, - "side": msg['side'], - "request": msg['request'], - } - send_msg_to(to_notify, msg) + match_uuid = msg['game_id'] + if match_uuid is None: + remove_one_from_queue(waiting_players) + return + pairs = None + mutex_playing.acquire() + if (match_uuid in playing_ones): + pairs = playing_ones[match_uuid] + del playing_ones[match_uuid] + mutex_playing.release() + + if pairs is not None: + if (pairs[0].side == msg['side']): + to_notify = pairs[1] + else: + to_notify = pairs[0] + msg = { + "status": 2, # exit + "game_id": match_uuid, + "side": msg['side'], + "request": msg['request'], + } + send_msg_to(to_notify, msg) + def timer_thread(): - while True: - time.sleep(1) - mutex_playing.acquire() - for game_id in list(playing_ones.keys()): - (client0, client1) = playing_ones[game_id] - #print("%d - %d" % (client0.time, client1.time)) - if (client0.time < 0): - client = client1 - else: - client = client0 - - if (client.time == 0 or client.total == 0): - msg = { - "status": 3, #timeout exit - "game_id": game_id, - "side": client.side, - } - send_msg_to(client0, msg) - send_msg_to(client1, msg) - del playing_ones[game_id] - else: + while True: + time.sleep(1) + mutex_playing.acquire() + for game_id in list(playing_ones.keys()): + (client0, client1) = playing_ones[game_id] + # print("%d - %d" % (client0.time, client1.time)) + if (client0.time < 0): + client = client1 + else: + client = client0 + + if (client.time == 0 or client.total == 0): + msg = { + "status": 3, # timeout exit + "game_id": game_id, + "side": client.side, + } + send_msg_to(client0, msg) + send_msg_to(client1, msg) + del playing_ones[game_id] + else: client.time -= 1 - client.total -= 1 - mutex_playing.release() + client.total -= 1 + mutex_playing.release() + def transfer_message(msg): - match_uuid = msg['game_id'] - pairs = playing_ones[match_uuid] - if(pairs[0].side == msg['side']): - to_notify = pairs[1] - pairs[0].time = -1 - else: - to_notify = pairs[0] - pairs[1].time = -1 - to_notify.time = Config.MAX_THNIKING_TIME - send_msg_to(to_notify, msg) + match_uuid = msg['game_id'] + pairs = playing_ones[match_uuid] + if (pairs[0].side == msg['side']): + to_notify = pairs[1] + pairs[0].time = -1 + else: + to_notify = pairs[0] + pairs[1].time = -1 + to_notify.time = Config.MAX_THNIKING_TIME + send_msg_to(to_notify, msg) + def client_thread(conn, addr): - while True: - try: - data = conn.recv(1024) - if not data: - break - print(data) - data = json.loads(data) - - if not 'type' in data: - transfer_message(data['msg']) - continue - if data['type'] == 0: - join_game_handler(data['msg'], addr, conn) - continue - elif data['type'] == 1: - transfer_message(data['msg']) - continue - elif data['type'] == 2: - quit_game_handler(data['msg']) - break - elif data['type'] == 3: - break - else: - #delivering message between the two clients - transfer_message(data['msg']) - continue - except: - break - #came out of loop - conn.close() - #print("conneection exit!") + while True: + try: + data = conn.recv(1024) + if not data: + break + print(data) + data = json.loads(data) + + if not 'type' in data: + transfer_message(data['msg']) + continue + if data['type'] == 0: + join_game_handler(data['msg'], addr, conn) + continue + elif data['type'] == 1: + transfer_message(data['msg']) + continue + elif data['type'] == 2: + quit_game_handler(data['msg']) + break + elif data['type'] == 3: + break + else: + # delivering message between the two clients + transfer_message(data['msg']) + continue + except: + break + # came out of loop + conn.close() + + +# print("conneection exit!") def main(): - load_config() - server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - print('Socket server created') - #try: - server.bind((Config.SOCKET_HOST, Config.SOCKET_PORT)) - #except (socket.error, msg): - # print ('Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1]) - # sys.exit() - - print('Socket bind complete') - server.listen(10) - print('Socket now listening') - - #now keep talking with the client - start_new_thread(timer_thread, ()) - while True: - #wait to accept a connection - blocking call - conn, addr = server.accept() - print ('Connected with ' + addr[0] + ':' + str(addr[1])) - - #start new thread takes 1st argument as a function name to be run, second is the tuple of arguments to the function. - start_new_thread(client_thread, (conn, addr)) - server.close() + load_config() + server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + print('Socket server created') + # try: + server.bind((Config.SOCKET_HOST, Config.SOCKET_PORT)) + # except (socket.error, msg): + # print ('Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1]) + # sys.exit() + + print('Socket bind complete') + server.listen(10) + print('Socket now listening') + + # now keep talking with the client + start_new_thread(timer_thread, ()) + while True: + # wait to accept a connection - blocking call + conn, addr = server.accept() + print('Connected with ' + addr[0] + ':' + str(addr[1])) + + # start new thread takes 1st argument as a function name to be run, second is the tuple of arguments to the function. + start_new_thread(client_thread, (conn, addr)) + server.close() + if __name__ == '__main__': - main() - \ No newline at end of file + main() diff --git a/src/__pycache__/Client_connection.cpython-38.pyc b/src/__pycache__/Client_connection.cpython-38.pyc index 5d78e1249fd4836d5c3fbab35005a4e54b085747..eb153dee957faf46db9190afe7a0a36407fe7457 100644 GIT binary patch delta 322 zcmca8e?Xo$l$V!_0SLAwY9>F}$ZO2OC^6ZQLws@qhXiMlHcxkz>LLw4E8%Q=Jv zz)G2z7@7XDv2ZaK*=|0=!OzH;Hu(;xG^69>ADnBY9DrJioI!*Eh%f{ZE+E2n@_sH= z$wDBrm=8!WFmfQlBDcwZxdIuTCi`>CGdfJp=Qb9t1gQku2Ul0*K6yL0J5besZYiKD zDIPuH29PQaAOSP4$Yb&WR@uoFJd1(qWO$9G9D#C0ZXm)PM0fy+Tdc`B`NgS|(|HXT z+a}N8{l@4!xt~voapB}me0`#}AZ6&fCWrE83vzI9b8v95bFgtp@-T65axek_gw;Ra delta 364 zcmX>ge^H({l$V!_0R*l}Cx6<=Ys|r@Fxinq+^B|O0pmgjMurrIUbMlK*HJOW4CqHDDoji?0ScnHG&cMXP$n=kmg^Q7cvB+-oP7Z!X z#`MW2Ii(q$CO_p|E9D4OQse?63_t|P#3EM^;Wk;2M|kpnE+M`mAh(zgNH74+;Fvs< zTYB;@E=NY^$u`{bjE<9IxQ#`tKuW;Q2Ppx=B9F;SxZQ!O9Jz%j|L0~0s!Zfoovg#d zDclHB%>gqIsJh5=@&Q)a$*DYxf$BMVjU}9bl11(y!UIHjf(Tn6F*%IafU$jYJMT9} s+sSo&N{ovpFXZbJwFAkc>zVArpDoDA!Og+J!Op?PA<4tU!O6i00KCga>;M1& diff --git a/src/__pycache__/init.cpython-38.pyc b/src/__pycache__/init.cpython-38.pyc index b24bdee7f4b8a8444cfa35e2fcfc8d6071ee2961..bcdd137dba49e789c2e4dc7b945062dc86402510 100644 GIT binary patch delta 26 gcmZ2(u-t$0iZez{_7uMd07{hw_y7O^ diff --git a/src/__pycache__/socket_client.cpython-38.pyc b/src/__pycache__/socket_client.cpython-38.pyc index 20f927f89cc0021b36516c0d70b7752f16157d8c..c94f9cbf3a6c7db4a0f24587d0a88377d5c4b818 100644 GIT binary patch delta 615 zcmY+BT}vB56o%(a*0^Rrsx`4zr60i$79_RzVl6FrQ$kRL5-3ZWo#;Yh^h|0ukUM+P zTbb*6?{!7+vVUX#f&ZfCq-9BFnTK;`-t(TFnLpkyKRgbClAv+lirN>>b$Ik8plqL} zULq*bghVuD;wHsp_6IZz2^@)N&K4Wp)=**n@dc?KKT85|L{qdw=KsMl?TQaH_2Koy zyVa355^-td6TMMD^b%uw5WlhRC)F9m-_tWYcbJ}>{tLtYrNVfS_EfCXL`9)> zwCZ*+Fny@L_Q@T&6+U6iGZq+63AX~v<_1o^6-opY`7@r}fWW+!OCHX!kWn`Wa;w7U z#_}{OzprEgYWZp;t*q@>NGF69DzT;AZmI|Ee(!v*Z0-tQYm2<|OBg7wpAz|H7Gop&i)A%tZWlDCWLrB{e=Q zc?G4*aB>GlB!H2;^M-9x>L7eDaFZ3kH+HdL$&EO!T0RDlBWMUz=ydlcPAc2fbvL2> z`71Qu%(|XXqIs@(v_>qWL|Ls#BZ9LqON`!M-pn}xleFFkeLA~fyTPY ztNz^0D2m65FFX#k87~Lq1+>&PmpYY41e<=!l;M0hilexi#KzfThbXiFs1T$-+1Qk& q2I;rZd(kjSOEI~b2kQ8q0D76USR0q=l-Zijg2zeNCYq%6I?f-6Pg!;V diff --git a/src/__pycache__/start_game.cpython-38.pyc b/src/__pycache__/start_game.cpython-38.pyc index d4f996e001534c76bd86ddc52e5fe042d0ed96b9..10ce797402a689e8c287866d72d728fda397abc6 100644 GIT binary patch delta 101 zcmew+^G$|3l$V!_0SLAwYHsBI&utyW;+vXR8d4+(6f4pO5>c!HiKWGU624< tP-;PbQAv>=h{F*NEh;*(AJ904J48NdJl delta 101 zcmew+^G$|3l$V!_0SGSIC~V~Z&ux8+#WyvtG^9unC|0BmByO<=B$gJZ7U_TlbU^}a uL8%4#MI}XgAP!4lX=X|07e*j+vMbLSMz766yxfe8UXu^7icdD>a|8gDoE$d* diff --git a/src/main.py b/src/main.py index 74614c8..0848147 100644 --- a/src/main.py +++ b/src/main.py @@ -1689,7 +1689,7 @@ def time_thread(): return True class Config: - SOCKET_HOST = '127.0.0.1'#Symbolic name meaning all available interfaces + SOCKET_HOST = '192.168.43.201'#Symbolic name meaning all available interfaces SOCKET_PORT = 50005#Arbitrary non-privileged port MAX_WAITING_TIME = 180 MAX_THNIKING_TIME = 60 @@ -2133,10 +2133,12 @@ def main(): draw_window(l_elephant, l_eagle, l_wolf, l_lion, l_leopard, l_mouse, l_fox, r_elephant, r_eagle, r_wolf, r_lion, r_leopard, r_mouse, r_fox, id, x, y, status, MAP, MAP1, turn) - if left_win(x, y, MAP, MAP1) or (demo == 1 and Left_win == 1): + if left_win(x, y, MAP, MAP1) or (demo == 1 and Left_win == 1) or (demo == 1 and player.status_2 == -1 and player.invalid == 0 and left_win(counterpart_x,counterpart_y,MAP,MAP1)): run = False - if right_win(x, y, MAP, MAP1) or (demo == 1 and Right_win == 1): + Left_win = 1 + if right_win(x, y, MAP, MAP1) or (demo == 1 and Right_win == 1) or (demo == 1 and player.status_2 == -1 and player.invalid == 0 and right_win(counterpart_x,counterpart_y,MAP,MAP1)): run = False + Right_win = 1 if left_win(x, y, MAP, MAP1) or (demo == 1 and Left_win == 1): if demo == 1 and player.side == 0: if pause == 1: @@ -2159,7 +2161,7 @@ def main(): C.ack_exit_game(client,player.side) - time.sleep(2) + time.sleep(10) #os.system("pause") return start_game.starting_screen() diff --git a/src/main_an.py b/src/main_an.py index 74614c8..758aae3 100644 --- a/src/main_an.py +++ b/src/main_an.py @@ -1670,6 +1670,18 @@ def server_thread(conn,addr) : except: return +def time_ShowAndCheck(player: player): + time.sleep(1) + clock = str(player.think_time) + '秒' + largeText = pygame.font.SysFont('comicsansms', 25) + TextSurf, TextRect = text_objects(clock, largeText) + if player.side == 1: + TextRect = init.tran(0,3) + else: + TextRect = init.tran(8,3) + gameDisplay.blit(TextSurf, TextRect) + pygame.display.update() + mutex_playing = Lock() def time_thread(): @@ -1682,6 +1694,7 @@ def time_thread(): break else: player.think_time -= 1 + time_ShowAndCheck(player) player.total_time -= 1 if is_over_time: return False @@ -1689,7 +1702,7 @@ def time_thread(): return True class Config: - SOCKET_HOST = '127.0.0.1'#Symbolic name meaning all available interfaces + SOCKET_HOST = '192.168.43.201'#Symbolic name meaning all available interfaces SOCKET_PORT = 50005#Arbitrary non-privileged port MAX_WAITING_TIME = 180 MAX_THNIKING_TIME = 60 @@ -1744,6 +1757,7 @@ def main(): run = False if demo == 1: C.start_new_thread(server_thread, (client,Address)) + C.server_thread(time_thread,()) Right_win = player.Right_win Left_win = player.Left_win for event in pygame.event.get(): @@ -2133,10 +2147,12 @@ def main(): draw_window(l_elephant, l_eagle, l_wolf, l_lion, l_leopard, l_mouse, l_fox, r_elephant, r_eagle, r_wolf, r_lion, r_leopard, r_mouse, r_fox, id, x, y, status, MAP, MAP1, turn) - if left_win(x, y, MAP, MAP1) or (demo == 1 and Left_win == 1): + if left_win(x, y, MAP, MAP1) or (demo == 1 and Left_win == 1) or (demo == 1 and player.status_2 == -1 and player.invalid == 0 and left_win(counterpart_x,counterpart_y,MAP,MAP1)): run = False - if right_win(x, y, MAP, MAP1) or (demo == 1 and Right_win == 1): + Left_win = 1 + if right_win(x, y, MAP, MAP1) or (demo == 1 and Right_win == 1) or (demo == 1 and player.status_2 == -1 and player.invalid == 0 and right_win(counterpart_x,counterpart_y,MAP,MAP1)): run = False + Right_win = 1 if left_win(x, y, MAP, MAP1) or (demo == 1 and Left_win == 1): if demo == 1 and player.side == 0: if pause == 1: @@ -2159,7 +2175,7 @@ def main(): C.ack_exit_game(client,player.side) - time.sleep(2) + time.sleep(10) #os.system("pause") return start_game.starting_screen() diff --git a/src/time_diplay.py b/src/time_diplay.py new file mode 100644 index 0000000..c986265 --- /dev/null +++ b/src/time_diplay.py @@ -0,0 +1,32 @@ +import pygame +import time + + +pygame.init() +black = (0, 0, 0) +white = (255, 255, 255) +display_width = 800 +display_height = 600 +gameDisplay = pygame.display.set_mode((display_width, display_height)) + +def text_objects(text, font): + textSurface = font.render(text, True, black) + return textSurface, textSurface.get_rect() + + + +def time_ShowAndCheck(client_time): + time.sleep(1) + gameDisplay.fill(white) + count = client_time + clock = str(count) + largeText = pygame.font.SysFont('comicsansms', 25) + TextSurf, TextRect = text_objects(clock, largeText) + TextRect.center = (750, (display_height / 10)) + gameDisplay.blit(TextSurf, TextRect) + pygame.display.update() + +flag = 300 +while flag: + time_ShowAndCheck(flag) + flag -= 1 \ No newline at end of file