From 518804051d68b76be61af9d4f2fd69dc6ad07527 Mon Sep 17 00:00:00 2001 From: steev Date: Fri, 5 Jan 2024 01:51:06 +0100 Subject: [PATCH] added first event functions documented server behaviour for some events --- .../Classes/{Objects => Game}/Player.py | 0 Game Server/server logic notes.md | 37 ++++++++++++++++++ .../Classes/{Objects => Game}/BoardField.py | 0 .../Classes/{Objects => Game}/Cards/Card.py | 0 .../{Objects => Game}/Cards/MonsterCard.py | 0 .../{Objects => Game}/Cards/SpellCard.py | 0 .../{Objects => Game}/Cards/TrapCard.py | 0 .../__pycache__/MonsterCard.cpython-311.pyc | Bin .../__pycache__/MonsterCard.cpython-312.pyc | Bin Game_Client/Classes/Game/Events/Login.py | 20 ++++++++++ Game_Client/Classes/Game/Events/PlaceCard.py | 17 ++++++++ .../Classes/{Objects => Game}/Player.py | 0 .../Classes/{Objects => Game}/World.py | 4 +- .../__pycache__/BoardField.cpython-311.pyc | Bin .../__pycache__/BoardField.cpython-312.pyc | Bin .../__pycache__/World.cpython-311.pyc | Bin .../__pycache__/World.cpython-312.pyc | Bin Game_Client/Classes/System/App.py | 9 +++-- Game_Client/Classes/System/chatgpt server.py | 1 + 19 files changed, 83 insertions(+), 5 deletions(-) rename Game Server/Classes/{Objects => Game}/Player.py (100%) create mode 100644 Game Server/server logic notes.md rename Game_Client/Classes/{Objects => Game}/BoardField.py (100%) rename Game_Client/Classes/{Objects => Game}/Cards/Card.py (100%) rename Game_Client/Classes/{Objects => Game}/Cards/MonsterCard.py (100%) rename Game_Client/Classes/{Objects => Game}/Cards/SpellCard.py (100%) rename Game_Client/Classes/{Objects => Game}/Cards/TrapCard.py (100%) rename Game_Client/Classes/{Objects => Game}/Cards/__pycache__/MonsterCard.cpython-311.pyc (100%) rename Game_Client/Classes/{Objects => Game}/Cards/__pycache__/MonsterCard.cpython-312.pyc (100%) create mode 100644 Game_Client/Classes/Game/Events/Login.py create mode 100644 Game_Client/Classes/Game/Events/PlaceCard.py rename Game_Client/Classes/{Objects => Game}/Player.py (100%) rename Game_Client/Classes/{Objects => Game}/World.py (97%) rename Game_Client/Classes/{Objects => Game}/__pycache__/BoardField.cpython-311.pyc (100%) rename Game_Client/Classes/{Objects => Game}/__pycache__/BoardField.cpython-312.pyc (100%) rename Game_Client/Classes/{Objects => Game}/__pycache__/World.cpython-311.pyc (100%) rename Game_Client/Classes/{Objects => Game}/__pycache__/World.cpython-312.pyc (100%) diff --git a/Game Server/Classes/Objects/Player.py b/Game Server/Classes/Game/Player.py similarity index 100% rename from Game Server/Classes/Objects/Player.py rename to Game Server/Classes/Game/Player.py diff --git a/Game Server/server logic notes.md b/Game Server/server logic notes.md new file mode 100644 index 0000000..c815e72 --- /dev/null +++ b/Game Server/server logic notes.md @@ -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 \ No newline at end of file diff --git a/Game_Client/Classes/Objects/BoardField.py b/Game_Client/Classes/Game/BoardField.py similarity index 100% rename from Game_Client/Classes/Objects/BoardField.py rename to Game_Client/Classes/Game/BoardField.py diff --git a/Game_Client/Classes/Objects/Cards/Card.py b/Game_Client/Classes/Game/Cards/Card.py similarity index 100% rename from Game_Client/Classes/Objects/Cards/Card.py rename to Game_Client/Classes/Game/Cards/Card.py diff --git a/Game_Client/Classes/Objects/Cards/MonsterCard.py b/Game_Client/Classes/Game/Cards/MonsterCard.py similarity index 100% rename from Game_Client/Classes/Objects/Cards/MonsterCard.py rename to Game_Client/Classes/Game/Cards/MonsterCard.py diff --git a/Game_Client/Classes/Objects/Cards/SpellCard.py b/Game_Client/Classes/Game/Cards/SpellCard.py similarity index 100% rename from Game_Client/Classes/Objects/Cards/SpellCard.py rename to Game_Client/Classes/Game/Cards/SpellCard.py diff --git a/Game_Client/Classes/Objects/Cards/TrapCard.py b/Game_Client/Classes/Game/Cards/TrapCard.py similarity index 100% rename from Game_Client/Classes/Objects/Cards/TrapCard.py rename to Game_Client/Classes/Game/Cards/TrapCard.py diff --git a/Game_Client/Classes/Objects/Cards/__pycache__/MonsterCard.cpython-311.pyc b/Game_Client/Classes/Game/Cards/__pycache__/MonsterCard.cpython-311.pyc similarity index 100% rename from Game_Client/Classes/Objects/Cards/__pycache__/MonsterCard.cpython-311.pyc rename to Game_Client/Classes/Game/Cards/__pycache__/MonsterCard.cpython-311.pyc diff --git a/Game_Client/Classes/Objects/Cards/__pycache__/MonsterCard.cpython-312.pyc b/Game_Client/Classes/Game/Cards/__pycache__/MonsterCard.cpython-312.pyc similarity index 100% rename from Game_Client/Classes/Objects/Cards/__pycache__/MonsterCard.cpython-312.pyc rename to Game_Client/Classes/Game/Cards/__pycache__/MonsterCard.cpython-312.pyc diff --git a/Game_Client/Classes/Game/Events/Login.py b/Game_Client/Classes/Game/Events/Login.py new file mode 100644 index 0000000..244ca7c --- /dev/null +++ b/Game_Client/Classes/Game/Events/Login.py @@ -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 \ No newline at end of file diff --git a/Game_Client/Classes/Game/Events/PlaceCard.py b/Game_Client/Classes/Game/Events/PlaceCard.py new file mode 100644 index 0000000..d04aaf6 --- /dev/null +++ b/Game_Client/Classes/Game/Events/PlaceCard.py @@ -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 \ No newline at end of file diff --git a/Game_Client/Classes/Objects/Player.py b/Game_Client/Classes/Game/Player.py similarity index 100% rename from Game_Client/Classes/Objects/Player.py rename to Game_Client/Classes/Game/Player.py diff --git a/Game_Client/Classes/Objects/World.py b/Game_Client/Classes/Game/World.py similarity index 97% rename from Game_Client/Classes/Objects/World.py rename to Game_Client/Classes/Game/World.py index 2cfe233..7acd9bf 100644 --- a/Game_Client/Classes/Objects/World.py +++ b/Game_Client/Classes/Game/World.py @@ -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(): diff --git a/Game_Client/Classes/Objects/__pycache__/BoardField.cpython-311.pyc b/Game_Client/Classes/Game/__pycache__/BoardField.cpython-311.pyc similarity index 100% rename from Game_Client/Classes/Objects/__pycache__/BoardField.cpython-311.pyc rename to Game_Client/Classes/Game/__pycache__/BoardField.cpython-311.pyc diff --git a/Game_Client/Classes/Objects/__pycache__/BoardField.cpython-312.pyc b/Game_Client/Classes/Game/__pycache__/BoardField.cpython-312.pyc similarity index 100% rename from Game_Client/Classes/Objects/__pycache__/BoardField.cpython-312.pyc rename to Game_Client/Classes/Game/__pycache__/BoardField.cpython-312.pyc diff --git a/Game_Client/Classes/Objects/__pycache__/World.cpython-311.pyc b/Game_Client/Classes/Game/__pycache__/World.cpython-311.pyc similarity index 100% rename from Game_Client/Classes/Objects/__pycache__/World.cpython-311.pyc rename to Game_Client/Classes/Game/__pycache__/World.cpython-311.pyc diff --git a/Game_Client/Classes/Objects/__pycache__/World.cpython-312.pyc b/Game_Client/Classes/Game/__pycache__/World.cpython-312.pyc similarity index 100% rename from Game_Client/Classes/Objects/__pycache__/World.cpython-312.pyc rename to Game_Client/Classes/Game/__pycache__/World.cpython-312.pyc diff --git a/Game_Client/Classes/System/App.py b/Game_Client/Classes/System/App.py index 3a8ea9b..497b647 100644 --- a/Game_Client/Classes/System/App.py +++ b/Game_Client/Classes/System/App.py @@ -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 diff --git a/Game_Client/Classes/System/chatgpt server.py b/Game_Client/Classes/System/chatgpt server.py index 0176f92..7588e58 100644 --- a/Game_Client/Classes/System/chatgpt server.py +++ b/Game_Client/Classes/System/chatgpt server.py @@ -1,6 +1,7 @@ import selectors import socket import json +import types sel = selectors.DefaultSelector()