command.py 1023 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. from enum import Enum
  2. import json
  3. class Command(str, Enum):
  4. NEWGAME = "newgame"
  5. JOINGAME = "joingame"
  6. PICKCOLOR = "pickcolor"
  7. DEAL = "deal"
  8. CHANGECARD = "changecard"
  9. PLAYCARD = "playcard"
  10. READY = "ready"
  11. UNDOCARD = "undocard"
  12. PASS = "pass"
  13. class Option(object):
  14. def __init__(self, command, args=None, text=None):
  15. self.command = command # Command(command)
  16. self.args = args
  17. self.text = text
  18. def check_arg(self, expected_arg, given_arg):
  19. return expected_arg == "#" or expected_arg == given_arg
  20. def check_args(self, other):
  21. if self.args == other.args:
  22. return True
  23. if self.args == None or len(self.args) == 0 or len(self.args) != len(other.args):
  24. return False
  25. return all(self.check_arg(expected, given) for (expected, given) in zip(self.args, other.args))
  26. if __name__ == "__main__":
  27. option = Option("newgame")
  28. print(option)
  29. print(option.__dict__)
  30. print(json.dumps(option))