Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- started = False
- queued = False
- TCP_IP = '127.0.0.1'
- TCP_PORT = 5005
- BUFFER_SIZE = 1024
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- s.connect((TCP_IP, TCP_PORT))
- m = raw_input('Mode: (P)layer or (S)pectator?')
- while m != 'P' and m != 'S':
- m = raw_input('Invalid. Choose mode: (P)layer or (S)pectator')
- while 1:
- data = s.recv(BUFFER_SIZE)
- if data == 'MODE':
- s.send(m)
- continue
- elif data == 'FILLED':
- data = s.recv(BUFFER_SIZE)
- print 'A game is in progress, you are #', data, ' in the queue. Please wait.'
- queued = True
- continue
- elif data == 'UNQUEUED':
- queued = False
- elif data == 'STARTING!':
- started = True
- elif data == 'OK':
- continue
- elif data == 'HEART':
- if not started and not queued and m == 'P':
- started = raw_input('Enter \'START\' when you want to begin.') == 'START'
- while not started:
- started = raw_input('Enter \'START\' when you want to begin.') == 'START'
- continue
- print 'OK wait.'
- s.send('START')
- else:
- s.send('OK')
- continue
- elif data == 'TAKE or PASS':
- s.send(raw_input('TAKE or PASS? '))
- continue
- elif data == 'PLAY':
- s.send(raw_input('Choose a card to play: '))
- continue
- elif data == 'GAME OVER':
- s.send('OK')
- if m == 'P':
- data = s.recv(BUFFER_SIZE)
- print 'Game over! Results:', data
- else:
- print 'Game over.'
- break
- print data
- s.send('OK')
- s.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement