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,8 +1,16 @@
import pygame
from Classes.Game.World import World
from Classes.Game.Cards.Card import Card
from Classes.Game.Player import Player
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):
print("game starts")
pass
def GameStart(world: World, handCards:list, inputHandler:InputHandler, owner:Player, 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))

View File

@ -1,20 +1,22 @@
import json
import pygame
from Classes.System.Network.NetworkManager import NetworkManager
from Classes.System.Network.TCPClient import TCPClient
from Classes.Game.World import World
from Classes.Game.Player import Player
# event the client sends to let the server know it logged in
def Login(networkManager:NetworkManager):
def Login(tcpClient:TCPClient):
payload = {
"event":"login",
"username": "player"
"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]
}
networkManager.tcp.send(payload)
tcpClient.send(payload)
# server response for login event
def LoginResponse(networkManager:NetworkManager, gameWorld: World):
# todo: get labels from world
# todo: get name for enemy
# todo: adjust enemy name label
pass
def LoginResponse(message:json):
# checks if the response on the login request is successfull
if message["status"] != "success":
print("login failed")

View File

@ -1,9 +1,9 @@
import pygame
from Classes.Game.World import World
from Classes.System.Network.NetworkManager import NetworkManager
from Classes.System.Components.InputHandler import InputHandler
# the event the client sends to the server when it places a card
def PlaceCard(networkManager: NetworkManager, card):
def PlaceCard(tcpClient, card):
# todo: send card information to the server
# todo: required info is:
# - position
@ -12,12 +12,24 @@ def PlaceCard(networkManager: NetworkManager, card):
payload = {
"event":"placecard",
"card": card.getID(),
"type": card.getType(),
"pos": card.getPos(),
}
networkManager.udp.send(payload)
tcpClient.send(payload)
# the event send from the server to display a card on the field
def CardPlaced(world:World, card:int, pos:pygame.Vector2):
def CardPlaced(world:World, card:int, type:str, owner:str, pos:pygame.Vector2, inputHandler:InputHandler):
if type == "MonsterCard":
world.spawnMonsterCard(f"Assets/Cards/{card}/", pos, inputHandler, owner)
pass
elif type == "SpellCard":
world.spawnSpellCard(f"Assets/Cards/{card}/", pos, inputHandler, owner)
pass
elif type == "TrapCard":
world.spawmTrapCard(f"Assets/Cards/{card}/", pos, inputHandler, owner)
pass
pass
def MovedCard(world:World, card:int, type:str, owner:str, oldPos:pygame.Vector2, newPos:pygame.Vector2, inputHandler:InputHandler):
pass