Advertisement
clesiomatias

Corrida de Tartarugas

Nov 15th, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.18 KB | None | 0 0
  1. from turtle import *
  2. import time
  3. import random
  4.  
  5. class Tartaruga(Turtle):
  6.    
  7.     def __init__(self,numero,cor,x,y ):
  8.         super().__init__()
  9.         self.ht()
  10.         self.speed(0)
  11.         self.pu()
  12.         self.color(cor)
  13.         self.setpos(x,y)
  14.         self.shape('turtle')
  15.         self.shapesize(2)
  16.         self.pd()
  17.         self.st()
  18.         self.numero = numero
  19.        
  20.     def correr(self,x,y):
  21.         self.goto(x,y)
  22.    
  23. janela = Screen()
  24. janela.bgcolor('white')
  25. janela.title('Corrida de Tartaruga')
  26. janela.setup(500,400)
  27.  
  28. linha= Turtle()
  29. linha.ht()
  30. linha.pu()
  31. linha.speed(0)
  32. linha.setpos(235,195)
  33. linha.color('red')
  34. linha.width(2)
  35. linha.pd()
  36. linha.goto(235,-195)
  37.  
  38. y = 160
  39. x = -220
  40. cores=['red', 'yellow','blue','gray','purple']
  41. tartarugas =[]
  42. for i in range(5):
  43.     tartarugas.append( Tartaruga(i,cores[i],x,y))
  44.     y-= 75
  45. time.sleep(1)  
  46. while True:
  47.     if tartarugas[0].xcor()>=200 or tartarugas[1].xcor()>=200 or tartarugas[2].xcor()>=200 or tartarugas[3].xcor()>=200 or tartarugas[4].xcor()>=200 :
  48.             break
  49.     else:
  50.            
  51.             for i in range(len(tartarugas)):
  52.                    
  53.                     tartarugas[i].correr(tartarugas [i].xcor ()+random.randint (0,5),tartarugas[i].ycor ())
  54.                     print(tartarugas[i].numero,' =' ,tartarugas[i].xcor())
  55.    
  56. janela.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement