diff --git a/Game Server/Classes/Game/Player.py b/Game Server/Classes/Game/Player.py index 0b39b40..81a6bb2 100644 --- a/Game Server/Classes/Game/Player.py +++ b/Game Server/Classes/Game/Player.py @@ -1,6 +1,5 @@ import random - class Player: __id:int __hp:int diff --git a/Game Server/Classes/System/GameManager.py b/Game Server/Classes/System/GameManager.py index a4927b2..c64961f 100644 --- a/Game Server/Classes/System/GameManager.py +++ b/Game Server/Classes/System/GameManager.py @@ -46,7 +46,10 @@ class GameManager: def startGame(self, tcpSocket:socket): self.__state = "running" + players = list(self.__serverWorld.getPlayers) + print("game starts") + self.logger.info("game manager is starting the game") for userAddr in self.__users.keys(): try: user = self.__serverWorld.getPlayers[userAddr]["player"] @@ -56,12 +59,23 @@ class GameManager: cards = user.getDeck() user.setHand(cards[:5]) + enemy = players[0]["player"] + + if enemy == user: + enemy = players[1]["player"] + payload = { "event":"startgame", - "playermana": user.getMana(), - "playerhp": user.getHP(), - "playername": user.getName(), - "hand": user.getHand() + "player": { + "mana":user.getMana(), + "hp": user.getHP(), + "hand": user.getHand() + }, + "enemy": { + "id": enemy.getID(), + "name": enemy.getName(), + "hp": enemy.getHP(), + }, } tcpSocket.send(json.dumps(payload).encode()) @@ -100,4 +114,8 @@ class GameManager: self.logger.info("2 players have join game starts") self.startGame(socket) - return self.__players \ No newline at end of file + return self.__players + + def removePlayers(self, clientAddr): + self.logger.info(f"removing player with address '{clientAddr}' from players database") + del self.__players[clientAddr] \ No newline at end of file diff --git a/Game Server/Classes/System/Network/NetworkManger.py b/Game Server/Classes/System/Network/NetworkManger.py index ab950bf..f3c480c 100644 --- a/Game Server/Classes/System/Network/NetworkManger.py +++ b/Game Server/Classes/System/Network/NetworkManger.py @@ -102,6 +102,9 @@ class NetworkManager: if e.errno == 10054: self.__gameManager.getLogger().error(f"Connection with {client_address} forcibly closed by remote host.") + players = self.__gameManager.getPlayers() + self.__gameManager.removePlayers(client_address) + self.__gameManager.getLogger().info(f"new player length {len(players)}") break self.__gameManager.getLogger().error(f"Socket error receiving data from {client_address}: {e}") diff --git a/Game Server/Classes/System/Network/__pycache__/NetworkManger.cpython-312.pyc b/Game Server/Classes/System/Network/__pycache__/NetworkManger.cpython-312.pyc index 4845ff9..bdfd0fc 100644 Binary files a/Game Server/Classes/System/Network/__pycache__/NetworkManger.cpython-312.pyc and b/Game Server/Classes/System/Network/__pycache__/NetworkManger.cpython-312.pyc differ diff --git a/Game Server/Classes/System/__pycache__/GameManager.cpython-312.pyc b/Game Server/Classes/System/__pycache__/GameManager.cpython-312.pyc index 963cabf..cbcb0b9 100644 Binary files a/Game Server/Classes/System/__pycache__/GameManager.cpython-312.pyc and b/Game Server/Classes/System/__pycache__/GameManager.cpython-312.pyc differ diff --git a/Game Server/log/nlwaonqh.log b/Game Server/log/nlwaonqh.log new file mode 100644 index 0000000..262c4f9 --- /dev/null +++ b/Game Server/log/nlwaonqh.log @@ -0,0 +1,83 @@ +07:54:39,940 root INFO starting up server +07:54:39,941 root INFO starting up game manager +07:54:39,941 root INFO preparing to start server +07:54:39,941 root INFO starting up network manager +07:54:39,941 root INFO starting up network manager +07:54:39,941 root INFO starting up tcp server +07:54:39,943 root INFO starting up thread for client socket accepting +07:54:53,468 root INFO Connected with ('127.0.0.1', 50377) +07:54:53,469 root INFO starting client handler thread for client at address ('127.0.0.1', 50377) +07:54:53,470 root INFO decoded message {'event': 'login', 'username': 'player', 'deck': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]} +07:54:53,471 root INFO user in message None +07:54:53,471 root INFO user logging in +07:54:53,471 root INFO task passed off to gameManager +07:54:53,471 root INFO creating user with id: > +07:54:53,471 root INFO new length of user dictionary: 1 +07:54:53,471 root INFO connected users 1 +07:54:53,472 root INFO confirming login for user +07:54:53,472 root INFO incommingevent {'event': 'login', 'username': 'player', 'deck': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]} +07:54:53,472 root INFO Received message from ('127.0.0.1', 50377): {"event": "login", "username": "player", "deck": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]} +07:55:54,122 root ERROR Connection with ('127.0.0.1', 50377) forcibly closed by remote host. +07:55:54,122 root INFO removing player with address '('127.0.0.1', 50377)' from players database +07:55:54,122 root INFO new player length 0 +07:55:57,266 root INFO Connected with ('127.0.0.1', 50382) +07:55:57,266 root INFO starting client handler thread for client at address ('127.0.0.1', 50382) +07:55:57,267 root INFO decoded message {'event': 'login', 'username': 'player', 'deck': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]} +07:55:57,267 root INFO user in message None +07:55:57,267 root INFO user logging in +07:55:57,268 root INFO task passed off to gameManager +07:55:57,269 root INFO creating user with id: > +07:55:57,270 root INFO new length of user dictionary: 1 +07:55:57,270 root INFO connected users 1 +07:55:57,271 root INFO confirming login for user +07:55:57,271 root INFO incommingevent {'event': 'login', 'username': 'player', 'deck': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]} +07:55:57,272 root INFO Received message from ('127.0.0.1', 50382): {"event": "login", "username": "player", "deck": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]} +07:56:20,208 root ERROR Connection with ('127.0.0.1', 50382) forcibly closed by remote host. +07:56:20,208 root INFO removing player with address '('127.0.0.1', 50382)' from players database +07:56:20,208 root INFO new player length 0 +07:59:44,914 root INFO Connected with ('127.0.0.1', 50416) +07:59:44,915 root INFO starting client handler thread for client at address ('127.0.0.1', 50416) +07:59:44,921 root INFO decoded message {'event': 'login', 'username': 'player', 'deck': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]} +07:59:44,922 root INFO user in message None +07:59:44,922 root INFO user logging in +07:59:44,922 root INFO task passed off to gameManager +07:59:44,923 root INFO creating user with id: > +07:59:44,923 root INFO new length of user dictionary: 1 +07:59:44,923 root INFO connected users 1 +07:59:44,923 root INFO confirming login for user +07:59:44,924 root INFO incommingevent {'event': 'login', 'username': 'player', 'deck': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]} +07:59:44,925 root INFO Received message from ('127.0.0.1', 50416): {"event": "login", "username": "player", "deck": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]} +07:59:47,51 root INFO decoded message {'event': 'placecard', 'card': 1, 'type': 'MonsterCard', 'x': 422.0, 'y': 540.0} +07:59:47,52 root INFO user in message None +07:59:47,52 root INFO incommingevent {'event': 'placecard', 'card': 1, 'type': 'MonsterCard', 'x': 422.0, 'y': 540.0} +07:59:47,52 root INFO Received message from ('127.0.0.1', 50416): {"event": "placecard", "card": 1, "type": "MonsterCard", "x": 422.0, "y": 540.0} +07:59:48,65 root INFO decoded message {'event': 'placecard', 'card': 1, 'type': 'MonsterCard', 'x': 422.0, 'y': 540.0} +07:59:48,65 root INFO user in message None +07:59:48,66 root INFO incommingevent {'event': 'placecard', 'card': 1, 'type': 'MonsterCard', 'x': 422.0, 'y': 540.0} +07:59:48,66 root INFO Received message from ('127.0.0.1', 50416): {"event": "placecard", "card": 1, "type": "MonsterCard", "x": 422.0, "y": 540.0} +08:08:21,501 root ERROR Connection with ('127.0.0.1', 50416) forcibly closed by remote host. +08:08:21,501 root INFO removing player with address '('127.0.0.1', 50416)' from players database +08:08:21,502 root INFO new player length 0 +08:08:29,119 root INFO Connected with ('127.0.0.1', 50487) +08:08:29,120 root INFO starting client handler thread for client at address ('127.0.0.1', 50487) +08:08:29,129 root INFO decoded message {'event': 'login', 'username': 'player', 'deck': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]} +08:08:29,129 root INFO user in message None +08:08:29,129 root INFO user logging in +08:08:29,129 root INFO task passed off to gameManager +08:08:29,130 root INFO creating user with id: > +08:08:29,130 root INFO new length of user dictionary: 1 +08:08:29,130 root INFO connected users 1 +08:08:29,130 root INFO confirming login for user +08:08:29,130 root INFO incommingevent {'event': 'login', 'username': 'player', 'deck': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]} +08:08:29,131 root INFO Received message from ('127.0.0.1', 50487): {"event": "login", "username": "player", "deck": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]} +08:08:39,319 root INFO decoded message {'event': 'placecard', 'card': 1, 'type': 'MonsterCard', 'x': 411.0, 'y': 595.0} +08:08:39,320 root INFO user in message None +08:08:39,320 root INFO incommingevent {'event': 'placecard', 'card': 1, 'type': 'MonsterCard', 'x': 411.0, 'y': 595.0} +08:08:39,320 root INFO Received message from ('127.0.0.1', 50487): {"event": "placecard", "card": 1, "type": "MonsterCard", "x": 411.0, "y": 595.0} +08:08:39,697 root INFO decoded message {'event': 'placecard', 'card': 1, 'type': 'MonsterCard', 'x': 411.0, 'y': 595.0} +08:08:39,698 root INFO user in message None +08:08:39,698 root INFO incommingevent {'event': 'placecard', 'card': 1, 'type': 'MonsterCard', 'x': 411.0, 'y': 595.0} +08:08:39,698 root INFO Received message from ('127.0.0.1', 50487): {"event": "placecard", "card": 1, "type": "MonsterCard", "x": 411.0, "y": 595.0} +08:10:00,576 root ERROR Connection with ('127.0.0.1', 50487) forcibly closed by remote host. +08:10:00,576 root INFO removing player with address '('127.0.0.1', 50487)' from players database +08:10:00,576 root INFO new player length 0 diff --git a/Game Server/log/ylpfvlxp.log b/Game Server/log/ylpfvlxp.log new file mode 100644 index 0000000..4b9dfa8 --- /dev/null +++ b/Game Server/log/ylpfvlxp.log @@ -0,0 +1,30 @@ +07:50:55,550 root INFO starting up server +07:50:55,550 root INFO starting up game manager +07:50:55,551 root INFO preparing to start server +07:50:55,551 root INFO starting up network manager +07:50:55,551 root INFO starting up network manager +07:50:55,551 root INFO starting up tcp server +07:50:55,553 root INFO starting up thread for client socket accepting +07:51:04,118 root INFO Connected with ('127.0.0.1', 50258) +07:51:04,119 root INFO starting client handler thread for client at address ('127.0.0.1', 50258) +07:51:04,120 root INFO decoded message {'event': 'login', 'username': 'player', 'deck': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]} +07:51:04,121 root INFO user in message None +07:51:04,121 root INFO user logging in +07:51:04,121 root INFO task passed off to gameManager +07:51:04,121 root INFO creating user with id: > +07:51:04,121 root INFO new length of user dictionary: 1 +07:51:04,121 root INFO connected users 1 +07:51:04,122 root INFO confirming login for user +07:51:04,122 root INFO incommingevent {'event': 'login', 'username': 'player', 'deck': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]} +07:51:04,122 root INFO Received message from ('127.0.0.1', 50258): {"event": "login", "username": "player", "deck": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]} +07:51:05,932 root ERROR Connection with ('127.0.0.1', 50258) forcibly closed by remote host. +07:51:05,933 root INFO new player length 1 +07:51:25,370 root INFO Connected with ('127.0.0.1', 50263) +07:51:25,371 root INFO starting client handler thread for client at address ('127.0.0.1', 50263) +07:51:25,372 root INFO decoded message {'event': 'login', 'username': 'player', 'deck': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]} +07:51:25,372 root INFO user in message None +07:51:25,372 root INFO user logging in +07:51:25,372 root INFO task passed off to gameManager +07:51:25,372 root INFO creating user with id: > +07:51:25,372 root INFO new length of user dictionary: 2 +07:51:25,372 root INFO 2 players have join game starts diff --git a/Game Server/log/zscmixee.log b/Game Server/log/zscmixee.log new file mode 100644 index 0000000..bda7c19 --- /dev/null +++ b/Game Server/log/zscmixee.log @@ -0,0 +1,30 @@ +07:48:23,537 root INFO starting up server +07:48:23,538 root INFO starting up game manager +07:48:23,538 root INFO preparing to start server +07:48:23,538 root INFO starting up network manager +07:48:23,538 root INFO starting up network manager +07:48:23,539 root INFO starting up tcp server +07:48:23,541 root INFO starting up thread for client socket accepting +07:48:36,336 root INFO Connected with ('127.0.0.1', 50229) +07:48:36,337 root INFO starting client handler thread for client at address ('127.0.0.1', 50229) +07:48:36,369 root INFO decoded message {'event': 'login', 'username': 'player', 'deck': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]} +07:48:36,370 root INFO user in message None +07:48:36,371 root INFO user logging in +07:48:36,372 root INFO task passed off to gameManager +07:48:36,372 root INFO creating user with id: > +07:48:36,372 root INFO new length of user dictionary: 1 +07:48:36,372 root INFO connected users 1 +07:48:36,372 root INFO confirming login for user +07:48:36,374 root INFO incommingevent {'event': 'login', 'username': 'player', 'deck': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]} +07:48:36,374 root INFO Received message from ('127.0.0.1', 50229): {"event": "login", "username": "player", "deck": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]} +07:48:47,859 root ERROR Connection with ('127.0.0.1', 50229) forcibly closed by remote host. +07:48:47,859 root INFO new player length 1 +07:49:03,206 root INFO Connected with ('127.0.0.1', 50235) +07:49:03,207 root INFO starting client handler thread for client at address ('127.0.0.1', 50235) +07:49:03,207 root INFO decoded message {'event': 'login', 'username': 'player', 'deck': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]} +07:49:03,208 root INFO user in message None +07:49:03,208 root INFO user logging in +07:49:03,208 root INFO task passed off to gameManager +07:49:03,208 root INFO creating user with id: > +07:49:03,208 root INFO new length of user dictionary: 2 +07:49:03,208 root INFO 2 players have join game starts diff --git a/Game_Client/Classes/Game/Cards/__pycache__/Card.cpython-311.pyc b/Game_Client/Classes/Game/Cards/__pycache__/Card.cpython-311.pyc index 512380d..db2cd58 100644 Binary files a/Game_Client/Classes/Game/Cards/__pycache__/Card.cpython-311.pyc and b/Game_Client/Classes/Game/Cards/__pycache__/Card.cpython-311.pyc differ diff --git a/Game_Client/Classes/Game/Cards/__pycache__/MonsterCard.cpython-311.pyc b/Game_Client/Classes/Game/Cards/__pycache__/MonsterCard.cpython-311.pyc index 1911997..438e237 100644 Binary files a/Game_Client/Classes/Game/Cards/__pycache__/MonsterCard.cpython-311.pyc and b/Game_Client/Classes/Game/Cards/__pycache__/MonsterCard.cpython-311.pyc differ diff --git a/Game_Client/Classes/Game/Cards/__pycache__/SpellCard.cpython-311.pyc b/Game_Client/Classes/Game/Cards/__pycache__/SpellCard.cpython-311.pyc index cbbd764..1832c8a 100644 Binary files a/Game_Client/Classes/Game/Cards/__pycache__/SpellCard.cpython-311.pyc and b/Game_Client/Classes/Game/Cards/__pycache__/SpellCard.cpython-311.pyc differ diff --git a/Game_Client/Classes/Game/Cards/__pycache__/TrapCard.cpython-311.pyc b/Game_Client/Classes/Game/Cards/__pycache__/TrapCard.cpython-311.pyc index 9c588ed..b7fcf13 100644 Binary files a/Game_Client/Classes/Game/Cards/__pycache__/TrapCard.cpython-311.pyc and b/Game_Client/Classes/Game/Cards/__pycache__/TrapCard.cpython-311.pyc differ diff --git a/Game_Client/Classes/Game/Events/GameStart.py b/Game_Client/Classes/Game/Events/GameStart.py index 29b3bff..76de95f 100644 --- a/Game_Client/Classes/Game/Events/GameStart.py +++ b/Game_Client/Classes/Game/Events/GameStart.py @@ -7,10 +7,10 @@ from Classes.System.Components.InputHandler import InputHandler # send from the server to tell the player the game starts # gives the client its and the opponents stats (not cards!!) -def GameStart(world: World, handCards:list, inputHandler:InputHandler, owner:Player, opponent:Player): +def GameStart(world: World, handCards:list, inputHandler:InputHandler, opponent:Player): index:int = 0 world.setEnemy(opponent) for card in handCards: - world.AddToPlayerHand(Card(pygame.Vector2(500 + (index + 100), 1050), f"Assets/Cards/{card}/", inputHandler, owner)) + world.AddToPlayerHand(Card(pygame.Vector2(500 + (index + 100), 1050), f"Assets/Cards/{card}/", inputHandler, world.getPlayer())) \ No newline at end of file diff --git a/Game_Client/Classes/Game/Events/Login.py b/Game_Client/Classes/Game/Events/Login.py index 1b809b2..365406f 100644 --- a/Game_Client/Classes/Game/Events/Login.py +++ b/Game_Client/Classes/Game/Events/Login.py @@ -16,7 +16,9 @@ def Login(tcpClient:TCPClient): tcpClient.send(payload) # server response for login event -def LoginResponse(message:json): +def LoginResponse(message:dict, world:World): # checks if the response on the login request is successfull if message["status"] != "success": - print("login failed") \ No newline at end of file + print("login failed") + else: + world.setPlayer(Player(0,0, message["username"], message["id"])) diff --git a/Game_Client/Classes/Game/Events/PlaceCard.py b/Game_Client/Classes/Game/Events/PlaceCard.py index c5729ca..862f752 100644 --- a/Game_Client/Classes/Game/Events/PlaceCard.py +++ b/Game_Client/Classes/Game/Events/PlaceCard.py @@ -3,7 +3,7 @@ from Classes.Game.World import World from Classes.System.Components.InputHandler import InputHandler # the event the client sends to the server when it places a card -def PlaceCard(tcpClient, card): +def PlaceCard(tcpClient, card, id): # todo: send card information to the server # todo: required info is: # - position @@ -13,6 +13,7 @@ def PlaceCard(tcpClient, card): "event":"placecard", "card": card.getID(), "type": card.getType(), + "user": id, "x": card.getPos().x, "y": card.getPos().y, } diff --git a/Game_Client/Classes/Game/Events/__pycache__/GameStart.cpython-311.pyc b/Game_Client/Classes/Game/Events/__pycache__/GameStart.cpython-311.pyc index 40ebc60..16e7390 100644 Binary files a/Game_Client/Classes/Game/Events/__pycache__/GameStart.cpython-311.pyc and b/Game_Client/Classes/Game/Events/__pycache__/GameStart.cpython-311.pyc differ diff --git a/Game_Client/Classes/Game/Events/__pycache__/Login.cpython-311.pyc b/Game_Client/Classes/Game/Events/__pycache__/Login.cpython-311.pyc index 726c1a4..a50672e 100644 Binary files a/Game_Client/Classes/Game/Events/__pycache__/Login.cpython-311.pyc and b/Game_Client/Classes/Game/Events/__pycache__/Login.cpython-311.pyc differ diff --git a/Game_Client/Classes/Game/Events/__pycache__/PlaceCard.cpython-311.pyc b/Game_Client/Classes/Game/Events/__pycache__/PlaceCard.cpython-311.pyc index e9e0c43..f7eca6e 100644 Binary files a/Game_Client/Classes/Game/Events/__pycache__/PlaceCard.cpython-311.pyc and b/Game_Client/Classes/Game/Events/__pycache__/PlaceCard.cpython-311.pyc differ diff --git a/Game_Client/Classes/Game/Player.py b/Game_Client/Classes/Game/Player.py index 42478e5..bcc15d8 100644 --- a/Game_Client/Classes/Game/Player.py +++ b/Game_Client/Classes/Game/Player.py @@ -7,10 +7,11 @@ class Player: __name:str __handCards:pygame.sprite.Group - def __init__(self, hp:int, mana:int, name:str): + def __init__(self, hp:int, mana:int, name:str, id:int): self.__hp = hp self.__mana = mana self.__name = name + self.__id = id def setID(self, id:int): self.__id = id diff --git a/Game_Client/Classes/Game/__pycache__/BoardField.cpython-311.pyc b/Game_Client/Classes/Game/__pycache__/BoardField.cpython-311.pyc index 72f14ce..17a0ef4 100644 Binary files a/Game_Client/Classes/Game/__pycache__/BoardField.cpython-311.pyc and b/Game_Client/Classes/Game/__pycache__/BoardField.cpython-311.pyc differ diff --git a/Game_Client/Classes/Game/__pycache__/Player.cpython-311.pyc b/Game_Client/Classes/Game/__pycache__/Player.cpython-311.pyc index 5245928..81c3a64 100644 Binary files a/Game_Client/Classes/Game/__pycache__/Player.cpython-311.pyc and b/Game_Client/Classes/Game/__pycache__/Player.cpython-311.pyc differ diff --git a/Game_Client/Classes/Game/__pycache__/World.cpython-311.pyc b/Game_Client/Classes/Game/__pycache__/World.cpython-311.pyc index eb436c3..17d6e55 100644 Binary files a/Game_Client/Classes/Game/__pycache__/World.cpython-311.pyc and b/Game_Client/Classes/Game/__pycache__/World.cpython-311.pyc differ diff --git a/Game_Client/Classes/System/App.py b/Game_Client/Classes/System/App.py index 92d62a0..3779dd2 100644 --- a/Game_Client/Classes/System/App.py +++ b/Game_Client/Classes/System/App.py @@ -27,6 +27,9 @@ class App: self.__myFont = pygame.font.SysFont('Comic Sans MS', 30) self.__window = Window(width=width, height=height, title=title) self.__inputHandler = InputHandler() + + # store selected card globaly in order to prevent packet flooding + self.selectedCard = None # game word self.__world = World(self.__window.getScreen()) @@ -47,12 +50,12 @@ class App: # create sprite groups # todo: remove these and let server handle card creation instead # blocker: server - client communication [WIP] - self.__world.spawnCard("Assets/Cards/1/", pygame.Vector2(500, 1050), self.__inputHandler, Player(1000, 0, "test")) - self.__world.spawnCard("Assets/Cards/1/", pygame.Vector2(600, 1050), self.__inputHandler, Player(1000, 0, "test")) - self.__world.spawnCard("Assets/Cards/1/", pygame.Vector2(700, 1050), self.__inputHandler, Player(1000, 0, "test")) - self.__world.spawnCard("Assets/Cards/1/", pygame.Vector2(800, 1050), self.__inputHandler, Player(1000, 0, "test")) - self.__world.spawnCard("Assets/Cards/1/", pygame.Vector2(900, 1050), self.__inputHandler, Player(1000, 0, "test")) - self.__world.spawnCard("Assets/Cards/1/", pygame.Vector2(1000, 1050), self.__inputHandler, Player(1000, 0, "test")) + # self.__world.spawnCard("Assets/Cards/1/", pygame.Vector2(500, 1050), self.__inputHandler, Player(1000, 0, "test")) + # self.__world.spawnCard("Assets/Cards/1/", pygame.Vector2(600, 1050), self.__inputHandler, Player(1000, 0, "test")) + # self.__world.spawnCard("Assets/Cards/1/", pygame.Vector2(700, 1050), self.__inputHandler, Player(1000, 0, "test")) + # self.__world.spawnCard("Assets/Cards/1/", pygame.Vector2(800, 1050), self.__inputHandler, Player(1000, 0, "test")) + # self.__world.spawnCard("Assets/Cards/1/", pygame.Vector2(900, 1050), self.__inputHandler, Player(1000, 0, "test")) + # self.__world.spawnCard("Assets/Cards/1/", pygame.Vector2(1000, 1050), self.__inputHandler, Player(1000, 0, "test")) while self.__running: self.__clock.tick(self.__FPS) @@ -79,7 +82,7 @@ class App: # handles incoming event queue def handleEvent(self, events): # TODO: fix bug that stacks cards when dragging them around - self.selectedCard = None + # TODO: something prevents selected card from becoming function global for event in events: if event.type == pygame.QUIT: @@ -112,7 +115,6 @@ class App: self.__world.spawnMonsterCard("Assets/Cards/MonsterCards/testmonstercard/", self.__inputHandler.getMousePos(), self.__inputHandler) elif event.type == pygame.MOUSEBUTTONUP: mouse_x, mouse_y = pygame.mouse.get_pos() - mouse_pos = pygame.Vector2(mouse_x, mouse_y) if event.button == 1: # Wenn linke Maustaste losgelassen wird for card in self.__world.getCards(): card.setDragging(False) @@ -120,14 +122,14 @@ class App: # TODO: send place card event to server # resets the currently selected card in order to prevent it getting moved try: - print(self.selectedCard) if self.selectedCard == card: - PlaceCard(self.__tcpClient, card) # tells the server that the player placed this card + print(self.selectedCard) + PlaceCard(self.__tcpClient, self.selectedCard, 1) # tells the server that the player placed this card except Exception as e: print(f"failed to place card on server due to error: {e}") - if not card == None: - card = None + if not self.selectedCard == None: + self.selectedCard = None # sets the running state for the gameloop def setRunning(self, running:bool): diff --git a/Game_Client/Classes/System/Components/__pycache__/InputHandler.cpython-311.pyc b/Game_Client/Classes/System/Components/__pycache__/InputHandler.cpython-311.pyc index 10e97a1..9b98f1c 100644 Binary files a/Game_Client/Classes/System/Components/__pycache__/InputHandler.cpython-311.pyc and b/Game_Client/Classes/System/Components/__pycache__/InputHandler.cpython-311.pyc differ diff --git a/Game_Client/Classes/System/Components/__pycache__/Label.cpython-311.pyc b/Game_Client/Classes/System/Components/__pycache__/Label.cpython-311.pyc index 507c282..f0331e9 100644 Binary files a/Game_Client/Classes/System/Components/__pycache__/Label.cpython-311.pyc and b/Game_Client/Classes/System/Components/__pycache__/Label.cpython-311.pyc differ diff --git a/Game_Client/Classes/System/Components/__pycache__/Window.cpython-311.pyc b/Game_Client/Classes/System/Components/__pycache__/Window.cpython-311.pyc index 1867184..ef52463 100644 Binary files a/Game_Client/Classes/System/Components/__pycache__/Window.cpython-311.pyc and b/Game_Client/Classes/System/Components/__pycache__/Window.cpython-311.pyc differ diff --git a/Game_Client/Classes/System/Network/EventHandler.py b/Game_Client/Classes/System/Network/EventHandler.py index 6fc941e..cef919b 100644 --- a/Game_Client/Classes/System/Network/EventHandler.py +++ b/Game_Client/Classes/System/Network/EventHandler.py @@ -7,14 +7,16 @@ from Classes.System.Components.InputHandler import InputHandler from Classes.Game.World import World from Classes.Game.Events.GameStart import GameStart from Classes.Game.Player import Player +from Classes.Game.Events.Login import LoginResponse class TCPEventHandler: def __init__(self, socket:socket): self.tcp_socket = socket - def handleEvents(self, message, inputHandler:InputHandler, world:World): - if message["event"] == "login": + def handleEvents(self, message:dict, inputHandler:InputHandler, world:World): + if message["event"] == "loginresponse": # todo: handle login response here + LoginResponse(message, world) pass elif message["event"] == "startgame": print("gamestart") @@ -24,14 +26,14 @@ class TCPEventHandler: CardPlaced(world, message["card"], message["type"], message["owner"], pygame.Vector2(int(message["x"]), int(message["y"]), inputHandler)) pass elif message["event"] == "MoveCard": - CardMoved( - world, - message["card"], - message["type"], - message["owner"], - pygame.Vector2(int(message["old_x"]), int(message["old_y"])), - pygame.Vector2(int(message["new_x"]), int(message["new_y"])), - inputHandler) + # CardMoved( + # world, + # message["card"], + # message["type"], + # message["owner"], + # pygame.Vector2(int(message["old_x"]), int(message["old_y"])), + # pygame.Vector2(int(message["new_x"]), int(message["new_y"])), + # inputHandler, world) pass elif message["event"] == "RemoveCard": pass diff --git a/Game_Client/Classes/System/Network/__pycache__/EventHandler.cpython-311.pyc b/Game_Client/Classes/System/Network/__pycache__/EventHandler.cpython-311.pyc index 3b0d395..e60a3e6 100644 Binary files a/Game_Client/Classes/System/Network/__pycache__/EventHandler.cpython-311.pyc and b/Game_Client/Classes/System/Network/__pycache__/EventHandler.cpython-311.pyc differ diff --git a/Game_Client/Classes/System/Network/__pycache__/TCPClient.cpython-311.pyc b/Game_Client/Classes/System/Network/__pycache__/TCPClient.cpython-311.pyc index 62eed0f..04c59e8 100644 Binary files a/Game_Client/Classes/System/Network/__pycache__/TCPClient.cpython-311.pyc and b/Game_Client/Classes/System/Network/__pycache__/TCPClient.cpython-311.pyc differ diff --git a/Game_Client/Classes/System/__pycache__/App.cpython-311.pyc b/Game_Client/Classes/System/__pycache__/App.cpython-311.pyc index c0c8d20..be962d3 100644 Binary files a/Game_Client/Classes/System/__pycache__/App.cpython-311.pyc and b/Game_Client/Classes/System/__pycache__/App.cpython-311.pyc differ