Declare double click event
parent
d149b3ab24
commit
d1a4c396e2
|
@ -1,5 +1,5 @@
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
import pygame
|
||||||
|
|
||||||
class GameState(Enum):
|
class GameState(Enum):
|
||||||
DEALING = 0
|
DEALING = 0
|
||||||
|
@ -19,3 +19,5 @@ NUM_OF_PLAYERS = 4
|
||||||
STARTING_HAND = 13
|
STARTING_HAND = 13
|
||||||
HIGHEST_CARD = 414
|
HIGHEST_CARD = 414
|
||||||
LOWEST_CARD = 102
|
LOWEST_CARD = 102
|
||||||
|
DOUBLE_CLICK_EVENT = pygame.USEREVENT + 1
|
||||||
|
DOUBLE_CLICK_TIMING = 300
|
||||||
|
|
13
players.py
13
players.py
|
@ -1,7 +1,7 @@
|
||||||
import cards
|
import cards
|
||||||
import pprint
|
import pprint
|
||||||
import pygame
|
import pygame
|
||||||
from game_consts import GameState, PlayerRole, STARTING_HAND
|
from game_consts import GameState, PlayerRole, STARTING_HAND, DOUBLE_CLICK_EVENT, DOUBLE_CLICK_TIMING
|
||||||
|
|
||||||
|
|
||||||
class Player(cards.Deck):
|
class Player(cards.Deck):
|
||||||
|
@ -190,14 +190,11 @@ class MainPlayer(Player):
|
||||||
self.selectable = True
|
self.selectable = True
|
||||||
self.left_mouse_down = False
|
self.left_mouse_down = False
|
||||||
self.double_clicking = False
|
self.double_clicking = False
|
||||||
self.double_click_event = pygame.USEREVENT + 1
|
|
||||||
self.double_click_timing = 300
|
|
||||||
|
|
||||||
def make_a_play(self, substate, game_events=None):
|
def make_a_play(self, substate, game_events=None):
|
||||||
card = None
|
card = None
|
||||||
if game_events:
|
if game_events:
|
||||||
for event in game_events:
|
for event in game_events:
|
||||||
mouse_clicks = event.type == pygame.MOUSEBUTTONDOWN
|
|
||||||
if event.type == pygame.MOUSEBUTTONUP and event.button == 1:
|
if event.type == pygame.MOUSEBUTTONUP and event.button == 1:
|
||||||
print('mouse click')
|
print('mouse click')
|
||||||
mouse_pos = pygame.mouse.get_pos()
|
mouse_pos = pygame.mouse.get_pos()
|
||||||
|
@ -207,7 +204,7 @@ class MainPlayer(Player):
|
||||||
card = 1
|
card = 1
|
||||||
|
|
||||||
if self.double_clicking:
|
if self.double_clicking:
|
||||||
pygame.time.set_timer(self.double_click_event, 0)
|
pygame.time.set_timer(DOUBLE_CLICK_EVENT, 0)
|
||||||
print('Double clicked')
|
print('Double clicked')
|
||||||
if reselect:
|
if reselect:
|
||||||
card_value = self.cards[self.selected_card].value
|
card_value = self.cards[self.selected_card].value
|
||||||
|
@ -219,13 +216,13 @@ class MainPlayer(Player):
|
||||||
self.double_clicking = False
|
self.double_clicking = False
|
||||||
else:
|
else:
|
||||||
self.double_clicking = True
|
self.double_clicking = True
|
||||||
pygame.time.set_timer(self.double_click_event, self.double_click_timing)
|
pygame.time.set_timer(DOUBLE_CLICK_EVENT, DOUBLE_CLICK_TIMING)
|
||||||
if reselect:
|
if reselect:
|
||||||
self.deselect_card()
|
self.deselect_card()
|
||||||
card = 1
|
card = 1
|
||||||
|
|
||||||
if event.type == self.double_click_event:
|
if event.type == DOUBLE_CLICK_EVENT:
|
||||||
pygame.time.set_timer(self.double_click_event, 0)
|
pygame.time.set_timer(DOUBLE_CLICK_EVENT, 0)
|
||||||
self.double_clicking = False
|
self.double_clicking = False
|
||||||
print('double click disabled')
|
print('double click disabled')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue