def run(self): maleLock.naFila = maleLock.naFila + 1 test = GameObject((400, 100), (100, 100), testTex) #cria novo objeto (pinguim) e o adiciona ao grupo para desenhar a sprite na tela test.changeDestination((self.threadID%5)*40+200,100) #muda as coordenadas de destino do objeto if femaleLock.naFila > 0 and maleLock.consecutive > 5: maleLock.consecutive = 0 maleTurnstile.clear() maleTurnstile.wait() maleLock.consecutive = maleLock.consecutive + 1 maleLock.counter = maleLock.counter+1 while maleLock.status == 'False': maleLock.changeStatus() while maleLock.lastIn + 1 != self.threadID: #faz com que a ordem de entrada seja tal que obedeca a regra de 1 por slot time.sleep(0) maleLock.lastIn = maleLock.lastIn + 1 maleMultiplex.acquire() test.changeDestination(180,100) time.sleep(3-(self.threadID%3)/2) #tempo de sleep varia com a localizacao do pinguim. Serve para que todos entrem pela porta. maleLock.naFila = maleLock.naFila - 1 test.changeDestination((self.threadID%3)*40+150,20) print "Homem %d entrou no banheiro" %(self.threadID) maleLock.insideCounter = maleLock.insideCounter + 1 time.sleep(5) maleLock.insideCounter = maleLock.insideCounter - 1 print "Homem %d saiu do banheiro" %(self.threadID) test.changeDestination(180,400) maleLock.counter = maleLock.counter-1 if maleLock.counter == 0: femaleTurnstile.set() maleLock.changeStatus() maleMultiplex.release() time.sleep(9) #aguarda o objeto sair da tela para exlcui-lo test.kill()
def run(self): femaleLock.naFila = femaleLock.naFila + 1 test = GameObject((0, 100), (100, 100), testTex2) test.changeDestination((self.threadID%5)*40,100) if maleLock.naFila > 0 and femaleLock.consecutive > 5: femaleLock.consecutive = 0 femaleTurnstile.clear() femaleTurnstile.wait() femaleLock.consecutive = femaleLock.consecutive + 1 femaleLock.counter = femaleLock.counter+1 while femaleLock.status == 'False': femaleLock.changeStatus() while femaleLock.lastIn + 1 != self.threadID: time.sleep(0) femaleLock.lastIn = femaleLock.lastIn + 1 femaleMultiplex.acquire() print "Mulher %d entrou no banheiro" %(self.threadID) femaleLock.insideCounter = femaleLock.insideCounter + 1 femaleLock.naFila = femaleLock.naFila - 1 test.changeDestination(180,100) time.sleep(3-(self.threadID%3)/2) test.changeDestination((self.threadID%3)*40+150,20) time.sleep(5) femaleLock.insideCounter = femaleLock.insideCounter - 1 print "Mulher %d saiu do banheiro" %(self.threadID) femaleLock.counter = femaleLock.counter-1 if femaleLock.counter == 0: maleTurnstile.set() femaleLock.changeStatus() femaleMultiplex.release() test.changeDestination(200,400) time.sleep(12) test.kill()