removed server added client code
This commit is contained in:
17
Classes/Game/Events/GameStart.py
Normal file
17
Classes/Game/Events/GameStart.py
Normal file
@ -0,0 +1,17 @@
|
||||
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
|
||||
from Classes.System.Utils.Path import PathUtil
|
||||
|
||||
|
||||
# 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):
|
||||
index:int = 0
|
||||
|
||||
for card in handCards:
|
||||
#world.AddToPlayerHand(Card(pygame.Vector2(500 + (index * 100), 1050), PathUtil.getAbsolutePathTo(f"Assets/Cards/{card}/"), inputHandler, Player(1000, 0, "test"), dragable=True))
|
||||
world.spawnCard(PathUtil.getAbsolutePathTo(f"Assets/Cards/{card}"), pygame.Vector2(500 + (index * 100), 1050), inputHandler, world.getPlayer())
|
||||
index=index+1
|
25
Classes/Game/Events/Login.py
Normal file
25
Classes/Game/Events/Login.py
Normal file
@ -0,0 +1,25 @@
|
||||
import json
|
||||
import pygame
|
||||
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(tcpClient):
|
||||
payload = {
|
||||
"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]
|
||||
}
|
||||
|
||||
tcpClient.send(payload)
|
||||
|
||||
# server response for login event
|
||||
def LoginResponse(message:dict, world:World):
|
||||
print("LoginResponse called")
|
||||
# checks if the response on the login request is successfull
|
||||
if message["status"] != "success":
|
||||
print("login failed")
|
||||
else:
|
||||
print("receiving login confirmation from server")
|
||||
world.setPlayer(Player(0,0,message["name"], message["id"]))
|
32
Classes/Game/Events/PlaceCard.py
Normal file
32
Classes/Game/Events/PlaceCard.py
Normal file
@ -0,0 +1,32 @@
|
||||
import pygame
|
||||
from Classes.Game.World import World
|
||||
from Classes.System.Components.InputHandler import InputHandler
|
||||
from Classes.Game.Cards.Card import Card
|
||||
from Classes.System.Utils.Path import PathUtil
|
||||
|
||||
# the event the client sends to the server when it places a card
|
||||
def PlaceCard(tcpClient, card:Card, player):
|
||||
# todo: send card information to the server
|
||||
# todo: required info is:
|
||||
# - position
|
||||
# - field type (used for validating what field the card is played in will be compared on server side)
|
||||
# - card id (server will do the rest to fetch card info)
|
||||
payload = {
|
||||
"event":"placecard",
|
||||
"card": card.getID(),
|
||||
"type": card.getType(),
|
||||
"user": player.getID(),
|
||||
"x": card.getX(),
|
||||
"y": card.getY(),
|
||||
}
|
||||
|
||||
tcpClient.send(payload)
|
||||
|
||||
# the event send from the server to display a card on the field
|
||||
def CardPlaced(world:World, card:int, owner:str, pos:pygame.Vector2, inputHandler:InputHandler):
|
||||
# todo: make this work with all cardtypes
|
||||
print("placing enemy card")
|
||||
world.spawnEnemyCard(PathUtil.getAbsolutePathTo(f"Assets/Cards/{card}"), pos, inputHandler, owner)
|
||||
|
||||
def MovedCard(world:World, card:int, type:str, owner:str, oldPos:pygame.Vector2, newPos:pygame.Vector2, inputHandler:InputHandler):
|
||||
pass
|
Reference in New Issue
Block a user