attempt to fix sending placecard event on client side
This commit is contained in:
parent
160fce0484
commit
afa2d779a1
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -47,12 +47,12 @@ class App:
|
||||
# create sprite groups
|
||||
# todo: remove these and let server handle card creation instead
|
||||
# blocker: server - client communication [WIP]
|
||||
self.__world.spawnCard("Assets/Cards/1", pygame.Vector2(500, 1050), self.__inputHandler, Player(1000, 0, "test"))
|
||||
self.__world.spawnCard("Assets/Cards/1", pygame.Vector2(600, 1050), self.__inputHandler, Player(1000, 0, "test"))
|
||||
self.__world.spawnCard("Assets/Cards/1", pygame.Vector2(700, 1050), self.__inputHandler, Player(1000, 0, "test"))
|
||||
self.__world.spawnCard("Assets/Cards/1", pygame.Vector2(800, 1050), self.__inputHandler, Player(1000, 0, "test"))
|
||||
self.__world.spawnCard("Assets/Cards/1", pygame.Vector2(900, 1050), self.__inputHandler, Player(1000, 0, "test"))
|
||||
self.__world.spawnCard("Assets/Cards/1", pygame.Vector2(1000, 1050), self.__inputHandler, Player(1000, 0, "test"))
|
||||
self.__world.spawnCard("Assets/Cards/1/", pygame.Vector2(500, 1050), self.__inputHandler, Player(1000, 0, "test"))
|
||||
self.__world.spawnCard("Assets/Cards/1/", pygame.Vector2(600, 1050), self.__inputHandler, Player(1000, 0, "test"))
|
||||
self.__world.spawnCard("Assets/Cards/1/", pygame.Vector2(700, 1050), self.__inputHandler, Player(1000, 0, "test"))
|
||||
self.__world.spawnCard("Assets/Cards/1/", pygame.Vector2(800, 1050), self.__inputHandler, Player(1000, 0, "test"))
|
||||
self.__world.spawnCard("Assets/Cards/1/", pygame.Vector2(900, 1050), self.__inputHandler, Player(1000, 0, "test"))
|
||||
self.__world.spawnCard("Assets/Cards/1/", pygame.Vector2(1000, 1050), self.__inputHandler, Player(1000, 0, "test"))
|
||||
|
||||
while self.__running:
|
||||
self.__clock.tick(self.__FPS)
|
||||
@ -79,7 +79,7 @@ class App:
|
||||
# handles incoming event queue
|
||||
def handleEvent(self, events):
|
||||
# TODO: fix bug that stacks cards when dragging them around
|
||||
selectedCard = None
|
||||
self.selectedCard = None
|
||||
|
||||
for event in events:
|
||||
if event.type == pygame.QUIT:
|
||||
@ -89,10 +89,9 @@ class App:
|
||||
mouse_pos = pygame.Vector2(mouse_x, mouse_y)
|
||||
|
||||
for card in self.__world.getCards():
|
||||
if card.rect.collidepoint(mouse_pos) and selectedCard == None:
|
||||
if card.getState() == "onHand":
|
||||
if card.rect.collidepoint(mouse_pos) and self.selectedCard == None:
|
||||
card.setDragging(True)
|
||||
selectedCard = card
|
||||
self.selectedCard = card
|
||||
for field in self.__world.getBoardFields():
|
||||
if field.getRect().collidepoint(mouse_pos):
|
||||
if field.getSide() == "Player":
|
||||
@ -116,20 +115,19 @@ class App:
|
||||
mouse_pos = pygame.Vector2(mouse_x, mouse_y)
|
||||
if event.button == 1: # Wenn linke Maustaste losgelassen wird
|
||||
for card in self.__world.getCards():
|
||||
card.setDragging(False)
|
||||
# card.setState("placed")
|
||||
# TODO: send place card event to server
|
||||
# resets the currently selected card in order to prevent it getting moved
|
||||
try:
|
||||
if card == selectedCard:
|
||||
card.setDragging(False)
|
||||
# TODO: send place card event to server
|
||||
# resets the currently selected card in order to prevent it getting moved
|
||||
print(self.selectedCard)
|
||||
if self.selectedCard == card:
|
||||
PlaceCard(self.__tcpClient, card) # tells the server that the player placed this card
|
||||
except Exception as e:
|
||||
print(f"failed to place card on server due to error: {e}")
|
||||
|
||||
if not selectedCard == None:
|
||||
selectedCard = None
|
||||
if not card == None:
|
||||
card = None
|
||||
|
||||
# sets the running state for the gameloop
|
||||
def setRunning(self, running:bool):
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user