Advertisement
Guest User

Untitled

a guest
May 27th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. import socket
  2. started = False
  3. queued = False
  4. TCP_IP = '127.0.0.1'
  5. TCP_PORT = 5005
  6. BUFFER_SIZE = 1024
  7. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  8. s.connect((TCP_IP, TCP_PORT))
  9.  
  10. m = raw_input('Mode: (P)layer or (S)pectator?')
  11. while m != 'P' and m != 'S':
  12. m = raw_input('Invalid. Choose mode: (P)layer or (S)pectator')
  13. while 1:
  14. data = s.recv(BUFFER_SIZE)
  15. if data == 'MODE':
  16. s.send(m)
  17. continue
  18. elif data == 'FILLED':
  19. data = s.recv(BUFFER_SIZE)
  20. print 'A game is in progress, you are #', data, ' in the queue. Please wait.'
  21. queued = True
  22. continue
  23. elif data == 'UNQUEUED':
  24. queued = False
  25. elif data == 'STARTING!':
  26. started = True
  27. elif data == 'OK':
  28. continue
  29. elif data == 'HEART':
  30. if not started and not queued and m == 'P':
  31. started = raw_input('Enter \'START\' when you want to begin.') == 'START'
  32. while not started:
  33. started = raw_input('Enter \'START\' when you want to begin.') == 'START'
  34. continue
  35. print 'OK wait.'
  36. s.send('START')
  37. else:
  38. s.send('OK')
  39. continue
  40. elif data == 'TAKE or PASS':
  41. s.send(raw_input('TAKE or PASS? '))
  42. continue
  43. elif data == 'PLAY':
  44. s.send(raw_input('Choose a card to play: '))
  45. continue
  46. elif data == 'GAME OVER':
  47. s.send('OK')
  48. if m == 'P':
  49. data = s.recv(BUFFER_SIZE)
  50. print 'Game over! Results:', data
  51. else:
  52. print 'Game over.'
  53. break
  54. print data
  55. s.send('OK')
  56. s.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement