Lanka Developers Community

    Lanka Developers

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Shop

    Race game using python

    Programming
    @python
    1
    1
    468
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • thilina dilshan
      thilina dilshan last edited by

      import turtle
      from turtle import Turtle
      import random

      turtle.title('Turtle rance')
      turtle.bgcolor('grey')

      turtle.color('white')
      turtle.penup()
      turtle.goto(-100, 200)
      turtle.write('Turtle race', font=('Arial', 30, 'bold'))

      turtle.goto(-400, -200)
      turtle.color('brown')
      size = [800, 120, 800, 120]
      turtle.speed(100)
      turtle.begin_fill()

      for i in range(4):
      turtle.forward(size[i])
      turtle.right(90)
      turtle.end_fill()

      turtle.shape('square')
      turtle.color('dark green')
      for i in range(10):
      turtle.goto(300, 150 - (i*30))
      turtle.stamp()

      for i in range(10):
      turtle.goto(310, 140 - (i*30))
      turtle.stamp()

      t1 = Turtle()
      t1.penup()
      t1.goto(-200, 0)
      t1.shape('turtle')
      t1.color('yellow')

      t2 = Turtle()
      t2.penup()
      t2.goto(-200, 50)
      t2.shape('turtle')
      t2.color('blue')

      t3 = Turtle()
      t3.penup()
      t3.goto(-200, 100)
      t3.shape('turtle')
      t3.color('black')

      t4 = Turtle()
      t4.penup()
      t4.goto(-200, -50)
      t4.shape('turtle')
      t4.color('red')

      d1 = 0
      d2 = 0
      d3 = 0
      d4 = 0

      for i in range(200):
      ran1 = random.randint(1, 25)
      ran2 = random.randint(1, 25)
      ran3 = random.randint(1, 25)
      ran4 = random.randint(1, 25)

      t1.forward(ran1)
      d1 += ran1
      t2.forward(ran2)
      d2 += ran2
      t3.forward(ran3)
      d3 += ran3
      t4.forward(ran4)
      d4 += ran4
      
      if d1 >= 499 or d2 >= 499 or d3 >= 499 or d4 >= 499:
          distance = {d1:'yellow', d2:'blue', d3:'black', d4:'red'}
      
          turtle.goto(-350, 290)
          turtle.write('Final result', font=('Arial', 20, 'bold'))
      
          one = max(distance.keys())
          turtle.goto(-350, 260)
          turtle.write('1:{}'.format(distance[one]), font=('Arial', 13))
          del distance[one]
      
          two = max(distance.keys())
          turtle.goto(-350, 240)
          turtle.write('2:{}'.format(distance[two]), font=('Arial', 13))
          del distance[two]
      
          three = max(distance.keys())
          turtle.goto(-350, 220)
          turtle.write('3:{}'.format(distance[three]), font=('Arial', 13))
          del distance[three]
      
          four = max(distance.keys())
          turtle.goto(-350, 200)
          turtle.write('4:{}'.format(distance[four]), font=('Arial', 13))
      
          break
      

      turtle.hideturtle()
      turtle.done()

      1 Reply Last reply Reply Quote 1
      • 1 / 1
      • First post
        Last post

      0
      Online

      3.6k
      Users

      1.3k
      Topics

      5.3k
      Posts

      • Privacy
      • Terms & Conditions
      • Donate

      © Copyrights and All right reserved Lanka Developers Community

      Powered by Axis Technologies (PVT) Ltd

      Made with in Sri Lanka

      | |