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
|
# create sprite groups
|
||||||
# todo: remove these and let server handle card creation instead
|
# todo: remove these and let server handle card creation instead
|
||||||
# blocker: server - client communication [WIP]
|
# 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(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(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(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(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(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(1000, 1050), self.__inputHandler, Player(1000, 0, "test"))
|
||||||
|
|
||||||
while self.__running:
|
while self.__running:
|
||||||
self.__clock.tick(self.__FPS)
|
self.__clock.tick(self.__FPS)
|
||||||
@ -79,7 +79,7 @@ class App:
|
|||||||
# handles incoming event queue
|
# handles incoming event queue
|
||||||
def handleEvent(self, events):
|
def handleEvent(self, events):
|
||||||
# TODO: fix bug that stacks cards when dragging them around
|
# TODO: fix bug that stacks cards when dragging them around
|
||||||
selectedCard = None
|
self.selectedCard = None
|
||||||
|
|
||||||
for event in events:
|
for event in events:
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
@ -89,10 +89,9 @@ class App:
|
|||||||
mouse_pos = pygame.Vector2(mouse_x, mouse_y)
|
mouse_pos = pygame.Vector2(mouse_x, mouse_y)
|
||||||
|
|
||||||
for card in self.__world.getCards():
|
for card in self.__world.getCards():
|
||||||
if card.rect.collidepoint(mouse_pos) and selectedCard == None:
|
if card.rect.collidepoint(mouse_pos) and self.selectedCard == None:
|
||||||
if card.getState() == "onHand":
|
|
||||||
card.setDragging(True)
|
card.setDragging(True)
|
||||||
selectedCard = card
|
self.selectedCard = card
|
||||||
for field in self.__world.getBoardFields():
|
for field in self.__world.getBoardFields():
|
||||||
if field.getRect().collidepoint(mouse_pos):
|
if field.getRect().collidepoint(mouse_pos):
|
||||||
if field.getSide() == "Player":
|
if field.getSide() == "Player":
|
||||||
@ -116,20 +115,19 @@ class App:
|
|||||||
mouse_pos = pygame.Vector2(mouse_x, mouse_y)
|
mouse_pos = pygame.Vector2(mouse_x, mouse_y)
|
||||||
if event.button == 1: # Wenn linke Maustaste losgelassen wird
|
if event.button == 1: # Wenn linke Maustaste losgelassen wird
|
||||||
for card in self.__world.getCards():
|
for card in self.__world.getCards():
|
||||||
|
card.setDragging(False)
|
||||||
# card.setState("placed")
|
# card.setState("placed")
|
||||||
# TODO: send place card event to server
|
# TODO: send place card event to server
|
||||||
# resets the currently selected card in order to prevent it getting moved
|
# resets the currently selected card in order to prevent it getting moved
|
||||||
try:
|
try:
|
||||||
if card == selectedCard:
|
print(self.selectedCard)
|
||||||
card.setDragging(False)
|
if self.selectedCard == card:
|
||||||
# TODO: send place card event to server
|
|
||||||
# resets the currently selected card in order to prevent it getting moved
|
|
||||||
PlaceCard(self.__tcpClient, card) # tells the server that the player placed this card
|
PlaceCard(self.__tcpClient, card) # tells the server that the player placed this card
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"failed to place card on server due to error: {e}")
|
print(f"failed to place card on server due to error: {e}")
|
||||||
|
|
||||||
if not selectedCard == None:
|
if not card == None:
|
||||||
selectedCard = None
|
card = None
|
||||||
|
|
||||||
# sets the running state for the gameloop
|
# sets the running state for the gameloop
|
||||||
def setRunning(self, running:bool):
|
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