option.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. from enum import Enum
  2. from color import Color
  3. from cards import Card
  4. import json
  5. class OptionCode(str, Enum):
  6. NEW_GAME = "new_game"
  7. JOIN_GAME = "join_game"
  8. PICK_COLOR = "pick_color"
  9. DEAL = "deal"
  10. SWAP_CARD = "swap_card"
  11. PLAY_CARD = "play_card"
  12. READY = "ready"
  13. UNDO_CARD = "undo_card"
  14. PASS = "pass"
  15. class Option(object):
  16. def __init__(self, code, text, game_code=None, color=None, card=None):
  17. self.code = OptionCode(code)
  18. self.text = text
  19. self.game_code = int(game_code) if game_code != None else None
  20. self.color = Color(color) if color != None else None
  21. self.card = card if isinstance(card, Card) else Card(card['suit'], card['denom']) if isinstance(card, dict) else None
  22. def isOption(self, other):
  23. # ignore text and game_code
  24. return \
  25. self.code == other.code and \
  26. self.color == other.color and \
  27. self.card == other.card
  28. if __name__ == "__main__":
  29. option = Option(OptionCode.NEW_GAME, "Nieuw spel", game_code=3)
  30. print(option)
  31. print(option.__dict__)
  32. print(json.dumps(option.__dict__))
  33. other = Option(OptionCode.NEW_GAME, "Start nog een spel", game_code=4)
  34. print(option.isOption(other))
  35. other = Option(OptionCode.NEW_GAME, "Doe maar gek", color='red')
  36. print(option.isOption(other))
  37. other = Option(OptionCode.SWAP_CARD, "Wissel kaart", card=Card("spades", "10"))