option.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. SKIP_TURN = "skip_turn"
  15. class Option(object):
  16. def __init__(self, code, text, game_code=None, color=None, card=None, user_name=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. self.user_name = user_name
  23. def isOption(self, other):
  24. # ignore text and game_code
  25. return \
  26. self.code == other.code and \
  27. self.color == other.color and \
  28. self.card == other.card
  29. if __name__ == "__main__":
  30. option = Option(OptionCode.NEW_GAME, "Nieuw spel", game_code=3)
  31. print(option)
  32. print(option.__dict__)
  33. print(json.dumps(option.__dict__))
  34. other = Option(OptionCode.NEW_GAME, "Start nog een spel", game_code=4)
  35. print(option.isOption(other))
  36. other = Option(OptionCode.NEW_GAME, "Doe maar gek", color='red')
  37. print(option.isOption(other))
  38. other = Option(OptionCode.SWAP_CARD, "Wissel kaart", card=Card("spades", "10"))