added first event functions documented server behaviour for some events

This commit is contained in:
steev 2024-01-05 01:51:06 +01:00
parent 0cd9857795
commit 518804051d
19 changed files with 83 additions and 5 deletions

View File

@ -0,0 +1,37 @@
# validation for placing cards:
- is the game still running
- is it the players turn
- does the card exist
- does the player have that card in his deck
- does the player have this card in his hand
- is the type of card allowed in that type of field
- is the field already blocked by another card
# validation for attacking another player
- is the game still running
- is it the players turn
- does the card exist
- does the player have that card in his deck
- is that card played
- does the enemy have remaining monster cards on his side
- if yes a direct attack would only be possible if a effect allows it
- can this card attack
- is the card of correct type
- is it blocked by effects (will be implemented after card effects are implemented)
# player death management (win condition)
- does a players hp go to 0?
- make the other player the winner
- if an effect affects the playing player card priority comes first
# handle a player leaving
- check if game still runs
- make remaining player win if yes
# turn management
- server keeps track of each turn
- whos turn is it
- what turn state is currently active
- draw state
- place state
- is the player trying to do actions not allowed in the given state

View File

@ -0,0 +1,20 @@
import pygame
from Classes.System.Network.NetworkManager import NetworkManager
from Classes.Game.World import World
# event the client sends to let the server know it logged in
def Login(networkManager:NetworkManager):
payload = {
"event":"login",
"username": "player"
}
networkManager.tcp.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

View File

@ -0,0 +1,17 @@
from Classes.Game.Cards.Card import Card
from Classes.Game.World import World
from Classes.System.Network.NetworkManager import NetworkManager
# the event the client sends to the server when it places a card
def PlaceCard(networkManager: NetworkManager, card:Card):
# 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)
pass
# the event send from the server to display a card on the field
def CardPlaced(world:World):
pass

View File

@ -1,7 +1,7 @@
import pygame
from Classes.Objects.BoardField import BoardField
from Classes.Game.BoardField import BoardField
from Classes.System.Components.Label import Label
from Classes.Objects.Cards.MonsterCard import MonsterCard
from Classes.Game.Cards.MonsterCard import MonsterCard
from Classes.System.Components.InputHandler import InputHandler
class World():

View File

@ -1,11 +1,12 @@
import pygame
from pygame.locals import *
from Classes.Objects.Cards.MonsterCard import MonsterCard
from Classes.Game.Cards.MonsterCard import MonsterCard
from Classes.System.Components.Window import Window
from Classes.System.Components.InputHandler import InputHandler
from Classes.Objects.World import World
from Classes.Game.World import World
from Classes.System.Network.NetworkManager import NetworkManager
from Classes.Game.Events.Login import Login
class App:
@ -24,6 +25,7 @@ class App:
self.__window = Window(width=width, height=height, title=title)
self.__inputHandler = InputHandler()
self.__networkManager("127.0.0.1", "54322", "54323")
Login(self.__networkManager) # will login to the server
# game word
self.__world = World(self.__window.getScreen())
@ -100,7 +102,8 @@ class App:
if event.button == 1: # Wenn linke Maustaste losgelassen wird
for card in self.__world.getCards():
card.setDragging(False)
# TODO: send server command
# TODO: send place card event to server
# resets the currently selected card in order to prevent it getting moved
if not card == None:
card = None

View File

@ -1,6 +1,7 @@
import selectors
import socket
import json
import types
sel = selectors.DefaultSelector()