Пример #1
0
def start():
    for i in range(4):
        turtles[i].penup()
        turtles[i].goto(0, 20 * i)
    racing = True
    while racing:
        random_values = [randint(10, 30) for i in range(4)]
        for i in range(4):
            turtles[i].forward(random_values[i])
            position = turtles[i].pos()[0]
            if position > 230:
                racing = False
                has_won = colors_list[i]
    s.speak(has_won + " has won the race.")
    if bet.lower() == has_won:
        s.speak("You bet correctly! The turtle you picked won the race!")
Пример #2
0
 def speak_score(self):
     s.speak(str(self.score))
Пример #3
0
# Keyboard functionality
screen.onkey(score.speak_score, 's')
screen.onkey(snake.up, 'Up')
screen.onkey(snake.down, 'Down')
screen.onkey(snake.left, 'Left')
screen.onkey(snake.right, 'Right')
screen.onkey(food.speak_pos, 'f')

game = True
while game:
  screen.update()
  sleep(0.1)
  snake.move()
  if snake.head.distance(food) < 15:
    s.speak("You ate the food!")
    food.refresh()
    score.increase()
    snake.extend()
  if snake.head.xcor() > 280 or snake.head.xcor() < -280 or snake.head.ycor() > 280 or snake.head.ycor() < -280:
    s.speak("Game over! You crashed into a wall!")
    score.game_over()
    game = False
  for segment in snake.segments[1:]:
    if segment.distance(snake.head) < 10:
      s.speak("Your snake is tangled! Game over!")
      score.game_over()
      game = False

screen.exitonclick()
Пример #4
0
def clear():
  tim.clear()
  tim.penup()
  tim.home()
  tim.pendown()
  s.speak("Cleared drawing.")
Пример #5
0
def move_forward():
  tim.forward(10)
  s.speak("Moved 10 forward.")
Пример #6
0
def speak_pos():
  heading = tim.heading()
  s.speak("Position: " + str(tim.pos()) + " position: " + str(heading))
Пример #7
0
def move_back():
  tim.back(10)
  s.speak("Moving back 10.")
Пример #8
0
def turn_left():
  tim.left(10)
  s.speak("Turning left.")
Пример #9
0
def turn_right():
  tim.right(10)
  s.speak("Turning right.")
Пример #10
0
 def speak_score(self):
   s.speak(f"Score: {self.score} high score: {self.high_score}")
Пример #11
0
 def speak_pos(self):
     s.speak(str(self.x) + " " + str(self.y))
Пример #12
0
def chose():
    s.speak("You chose " + color)
Пример #13
0
def yellow_position():
    s.speak("Yellow turtle position: " + str(turtles[3].pos()))
Пример #14
0
def green_position():
    s.speak("Green turtle position: " + str(turtles[2].pos()))
Пример #15
0
def red_position():
    s.speak("Red turtle position: " + str(turtles[1].pos()))
Пример #16
0
def blue_position():
    s.speak("Blue turtle position: " + str(turtles[0].pos()))