merged broken branches client with master branch and added first statehandling for card placement

This commit is contained in:
2024-01-08 20:07:29 +01:00
parent 8f90633b16
commit 677552a617
53 changed files with 344 additions and 224 deletions

View File

@@ -1,3 +1,4 @@
import json
import socket
from Classes.Game.Player import Player
@@ -38,23 +39,28 @@ class GameManager:
# this section mostly only used by the networking and event handling classes
# other parts should never need to interface with this unless really required
# =============================================================================
def startGame(self):
def startGame(self, tcpSocket:socket):
self.__state = "running"
print("game starts")
for userAddr in self.__users.keys():
try:
user = self.__serverWorld.getPlayers[userAddr]
user = self.__serverWorld.getPlayers[userAddr]["player"]
user.addMana(1000)
user.adjustHP(1000)
user.shuffleDeck()
cards = user.getDeck()
user.setHand(cards[:5])
payload = {
"event":"startgame",
"mana": user.getMana(),
"hp": user.getHP()
"playermana": user.getMana(),
"playerhp": user.getHP(),
"playername": user.getName(),
"hand": user.getHand()
}
self.send(payload, userAddr)
tcpSocket.send(json.dumps(payload).encode())
except Exception as e:
print(f"failed to start game due to error: {e}")
break
@@ -84,6 +90,6 @@ class GameManager:
# counts participating players and starts the game if enough have joined
if len(self.__players) == 2:
self.startGame()
self.startGame(socket)
return self.__players