Example #1
1
def banner(s):
    """
    Display a message then quit.
    :param s: String of your message
    """
    turtle.home()
    turtle.color('black')
    turtle.write(s, True, align='center', font=('Arial', 48, 'italic'))
    time.sleep(2)
    turtle.undo()
    lander.delete()
Example #2
0
 def __undo(self):
     global line_turtle, line
     line -= 1
     line_turtle.clear()
     line_turtle.write('Now is line ' + str(line))
     turtle.onkeypress(None, 'Down')
     turtle.onkeypress(None, 'Up')
     turtle.undo()
     if self.command_line == 0:
         return 0
     self.command_line -= 1
     temp = self.point
     self.point = self.end_list[self.command_line] + 1
     while temp != self.point:
         temp -= 1
         self.command_iter.back()
         self.parameters_iter.back()
     self.steps_check_point -= 1
     temp = 0
     while self.steps > self.steps_check[self.steps_check_point]:
         temp += 1
         self.steps -= 1
         turtle.undo()
     self.now_point_iter.back()
     self.steps_check.pop()
     time.sleep(0.5)
     turtle.onkeypress(self.__undo, 'Down')
     turtle.onkeypress(self.__run_step, 'Up')
def score(positionscore):
    turtle.undo()
    global scorev
    turtle.goto(positionscore)
    scorev += 1
    turtle.hideturtle()
    turtle.write(scorev, font=("Arial", 16, "normal"))
Example #4
0
def set_screen():
    engine.init_screen(WIDTH, HEIGHT)
    turtle.color('blue')
    turtle.write("Turtle Patrol", True, align='center', font=('Courier', 50, 'italic'))
    time.sleep(2)
    turtle.undo()
    turtle.bgcolor('black')
Example #5
0
def freeroam(turtle):
    global num_uncleaned
    # sets how long the Roomba runs
    length = float(integerbox("How long would you like the Roomba to run (in seconds)?"))
    start = time.time()
    while True:
        if time.time() > start + length:
            break
        current = turtle.heading()
        x, y = turtle.pos()
        coord = (int(x)+249,int(y)+249)
        print("current coords: ",int(coord[0]),int(coord[1]))
        for i in range(50):
            for j in range(50):
                xclean = coord[0]+i
                yclean = coord[1]+j
                if 0<=xclean<500 and 0<=yclean<500 and (i**2+j**2 <= 30**2):
                    if not clean_grid[xclean,yclean]:
                        clean_grid[xclean,yclean] = True
                        num_uncleaned-=1
        print("num of coords: ",num_uncleaned)
        if (-width/2 < x < width/2) and  (-height/2 < y < height/2):
                turtle.forward(2)
        else:
            turtle.undo()
            angle = random.randint(-180,180)
            turtle.setheading(current+angle) 
    
    # Return Roomba to its home; final goodbyes
    home(Roomba, homex, homey)
    msgbox("Roomba has cleaned "+str(int((((250000-num_uncleaned)/250000)*100)))+"% of your home in "+str(int(length))+" seconds. Good-bye!")
Example #6
0
def hands( freq=166 ):
    """Draw three hands.

    :param freq: Frequency of refresh in milliseconds.
    """
    global running
    now= datetime.datetime.now()
    time= now.time()
    h, m, s, ms = time.hour, time.minute, time.second, int(time.microsecond/1000)

    # Erase old hands.
    while turtle.undobufferentries():
        turtle.undo()

    # Draw new hands.
    hand( h*5+m/60+s/3600, .6*R, 3 )
    hand( m+s/60, .8*R, 2 )
    hand( s+ms/1000, .9*R, 1 )

    # Draw date and time
    turtle.penup(); turtle.home()
    turtle.goto( 0, -120 ); turtle.write( now.strftime("%b %d %H:%M:%S"), align="center", font=("Helvetica", 24, "normal") )

    # Reschedule hands function
    if running:
        # Reset timer for next second (including microsecond tweak)
        turtle.ontimer( hands, freq-(ms%freq) )
Example #7
0
def complete(turtle):
    global num_uncleaned
    clean = False
    cleanage = integerbox("What percent of the floor would you like Roomba to clean (0-95)", lowerbound = 0, upperbound = 95)
    start = time.time()
    while True:
        if(int((((250000-num_uncleaned)/250000)*100)) > (cleanage-1)):
            break
                
        current = turtle.heading()
        x, y = turtle.pos()
        coord = (int(x)+249,int(y)+249)
        print("current coords: ",int(coord[0]),int(coord[1]))
        for i in range(50):
            for j in range(50):
                xclean = coord[0]+i
                yclean = coord[1]+j
                if 0<=xclean<500 and 0<=yclean<500 and (i**2+j**2 <= 30**2):
                    if not clean_grid[xclean,yclean]:
                        clean_grid[xclean,yclean] = True
                        num_uncleaned-=1
        print("num of coords: ",num_uncleaned)
#         if(len(coordinates)<100):
#             clean = True
        if (-width/2 < x < width/2) and (-height/2 < y < height/2):
                turtle.forward(1)
        else:
            turtle.undo()
            angle = random.randint(-180,180)
            turtle.setheading(current+angle)     
    end = time.time()
    
    # Return Roomba to its home; final goodbyes
    home(Roomba, homex, homey)
    msgbox("Roomba has cleaned "+str(int((((250000-num_uncleaned)/250000)*100)))+"% of your home in "+str(int(end-start))+" seconds. Good-bye!")
 def gestionEffacements(self, effacer):
     #Tracer desactive les animations de dessin (déplacement instantané)
     t.tracer(100, 0)
     if (effacer == True):
         for _ in range(len(villes) + 2):
             t.undo()
     for _ in range(3):
         self.turtleStats.undo()
Example #9
0
def score():
    turtle.undo()
    global scorev
    turtle.goto(-75,-400)
    scorev += 1
    turtle.hideturtle()
    turtle.pensize(20)
    turtle.write("Your score is " + str(scorev), font=("Arial", 16, "normal"))
Example #10
0
def jakebackward():
    turtle.backward(move_speed)
    x, y = turtle.position()

    #Changed the if condition from < (less than) sign to <= (less than or equal to) sign.
    if not -WIDTH / 2 <= x <= WIDTH / 2 or not -HEIGHT / 2 <= y < HEIGHT / 2:
        turtle.undo()  # undo error
        turtle.left(180)  # turn around
        turtle.forward(10)  # redo movement but in new direction
Example #11
0
def eat_food():
    global score
    for food in FOOD:
        if check_collision(MY_BALL, food):
            MY_BALL_r = MY_BALL.r
            food_r = food.r

            new_x = random.randint(-SCREEN_WIDTH + MAXIMUM_BALL_RADIUS,
                                   SCREEN_HEIGHT - MAXIMUM_BALL_RADIUS)
            new_y = random.randint(-SCREEN_WIDTH + MAXIMUM_BALL_RADIUS,
                                   SCREEN_HEIGHT - MAXIMUM_BALL_RADIUS)
            x_speed = random.randint(MINIMUM_BALL_DX, MAXIMUM_BALL_DX)
            y_speed = random.randint(MINIMUM_BALL_DY, MAXIMUM_BALL_DY)

            while x_speed == 0:
                x_speed = random.randint(MINIMUM_BALL_DX, MAXIMUM_BALL_DX)
            while y_speed == 0:
                y_speed = random.randint(MINIMUM_BALL_DY, MAXIMUM_BALL_DY)
            if MY_BALL.r < food.r:
                return False
            if MY_BALL.r > food.r:
                score = score + 1
                turtle.undo()
                turtle.update()
                turtle.goto(width, height)
                turtle.write(str(score),
                             move=False,
                             align="left",
                             font=("Arial", 50, "bold"))
                MY_BALL.r += 1
                MY_BALL.shapesize((MY_BALL_r + 1) / 10)
                food.goto(new_x, new_y)
                food.dx = x_speed
                food.dy = y_speed
        if check_collision(ball, food):
            ball_r = ball.r
            food_r = food.r

            new_x = random.randint(-SCREEN_WIDTH + MAXIMUM_BALL_RADIUS,
                                   SCREEN_HEIGHT - MAXIMUM_BALL_RADIUS)
            new_y = random.randint(-SCREEN_WIDTH + MAXIMUM_BALL_RADIUS,
                                   SCREEN_HEIGHT - MAXIMUM_BALL_RADIUS)
            x_speed = random.randint(MINIMUM_BALL_DX, MAXIMUM_BALL_DX)
            y_speed = random.randint(MINIMUM_BALL_DY, MAXIMUM_BALL_DY)

            while x_speed == 0:
                x_speed = random.randint(MINIMUM_BALL_DX, MAXIMUM_BALL_DX)
            while y_speed == 0:
                y_speed = random.randint(MINIMUM_BALL_DY, MAXIMUM_BALL_DY)
            if ball.r < food.r:
                return False
            if ball.r > food.r:
                ball.r += 1
                ball.shapesize((ball_r + 1) / 10)
                food.goto(new_x, new_y)
                food.dx = x_speed
                food.dy = y_speed
def pause():
    #global paused
    #paused = True
    turtle.write("The game is paused! ",
                 move=False,
                 align="center",
                 font=("Arial", 40, "normal"))
    time.sleep(5)
    turtle.undo()
    print(paused)
def banner(s):
    """
    Display a message then quit.
    :param s: String of your message
    """
    turtle.home()
    turtle.color("black")
    turtle.write(s, True, align="center", font=("Arial", 48, "italic"))
    time.sleep(2)
    turtle.undo()
    lander.delete()
Example #14
0
 def draw_no_useful():
     """
     没有停车位时,显式文字
     :return:
     """
     turtle.penup()
     turtle.goto(-100, 0)
     turtle.pencolor('red')
     turtle.write("没用可用车位", font=('Arial', 40, 'normal'))
     # sleep(0.5)
     turtle.undo()
Example #15
0
def move_simba():
    #global food_stamps
    my_pos = simba.pos()
    x_pos = my_pos[0]
    y_pos = my_pos[1]

    if simba.pos() in pos_list:
        print("you touched the wall")
        simba.goto(450, -450)
#if you press the up arrow simba will move forward
    elif simba.direction == 'Up':
        simba.goto(x_pos, y_pos + 50)
        print('you moved up')

#if you press the down arrow simba will move down
    elif simba.direction == 'Down':
        simba.goto(x_pos, y_pos - 50)
        print('you moved down')

    elif simba.direction == 'Right':
        simba.goto(x_pos + 50, y_pos)
        print('you moved right')

    elif simba.direction == 'Left':
        simba.goto(x_pos - 50, y_pos)
        print('you moved left')

    global score

    if simba.pos() in food_pos:
        food_index = food_pos.index(simba.pos())
        food.clearstamp(food_stamps[food_index])
        food_pos.pop(food_index)
        food_stamps.pop(food_index)
        print("You have eaten the food!")
        turtle.undo()
        score = score + 1
        turtle.penup()
        turtle.color('red')
        turtle.hideturtle()
        turtle.goto(-470, 450)
        turtle.pendown()
        turtle.write('score : ' + str(score),
                     False,
                     align="left",
                     font=("Arial", 20, "normal"))


#this one
    if len(food_stamps) < 1:
        make_food()
def clearStamp():
    global step
    step-=1
    turtle.undo()
    turtle.undo()
    turtle.undo()
    turtle.undo()
Example #17
0
def check_myball_collision():
    for ball in balls:
        if collide(my_ball, ball):
            rad1 = my_ball.r
            rad2 = ball.r
            x = random.randint(-screen_width + maximum_ball_radius,
                               screen_width - maximum_ball_radius)
            y = random.randint(-screen_height + maximum_ball_radius,
                               screen_height - maximum_ball_radius)
            dx = 0
            while dx == 0:
                dx = random.randint(minimum_ball_dx, maximum_ball_dx)
            dy = 0
            while dy == 0:
                dy = random.randint(minimum_ball_dy, maximum_ball_dy)
            radius = random.randint(minimum_ball_radius, maximum_ball_radius)
            color = (random.random(), random.random(), random.random())
            if rad2 >= rad1:
                return False
            else:
                my_ball.r += 1
                my_ball.shapesize((rad1 + 1) / 10)
                ball.shapesize(rad2 / 10)
                ball.r = radius
                ball.penup()
                ball.goto(x, y)
                ball.shape("circle")
                ball.color(color)
                ball.x = x
                ball.y = y
                ball.dx = dx
                ball.dy = dy

                #score
                global score
                score = score + 1
                turtle.undo()
                turtle.goto(200, 250)
                turtle.update()
                print("yummmm you have eaten a ball!")
                turtle.color("red")
                turtle.write(" Your Score:" + str(score),
                             font=("Arial", 16, "normal"))

                #background
                bg = ["bg1.gif", "bg2.gif", "bg3.gif", "bg4.gif", "bg5.gif"]
                i = random.randint(0, 4)
                screen.bgpic(bg[i])

    return True
Example #18
0
def redraw():
    global stars
    for i in range(len(stars)):  # clear old stars
        turtle.undo()
    for i in range(len(stars)):  # visits new star position
        this = stars[i]
        turtle.setpos(this.x, this.y)
        turtle.setheading(0)
        turtle.fd(this.vx)
        turtle.setheading(90)
        turtle.fd(this.vy)
        this.x, this.y = turtle.pos()
    for i in range(len(stars)):  # draws stars
        this = stars[i]
        turtle.setpos(this.x, this.y)
        turtle.dot(this.radius * 2)
Example #19
0
def deplacer(matrice, position, mouvement):
    """Déplacement général du personnage. Cette fonction fera la gestion des collision. Le paramètre position
    actuelle du personnage, et mouvement est sa destination"""

    case_cible = (position[0] + mouvement[0], position[1] + mouvement[1])
    print(case_cible)

    if matrice[case_cible[0]][case_cible[1]] in (0, 2, 4):
        position[0] += mouvement[0]
        position[1] += mouvement[1]
        turtle.undo()
        turtle.up()
        turtle.goto(coordonnees_personnage(position, calculer_pas(matrice)))
        turtle.down()
        print(position)
        turtle.dot(calculer_pas(matrice) * 0.9, 'red')
Example #20
0
def check_myball_collision():
    for ball in BALLS:
        if check_collision(MY_BALL, ball):
            MY_BALL_r = MY_BALL.r
            ball_r = ball.r

            new_x = random.randint(-SCREEN_WIDTH + MAXIMUM_BALL_RADIUS,
                                   SCREEN_HEIGHT - MAXIMUM_BALL_RADIUS)
            new_y = random.randint(-SCREEN_WIDTH + MAXIMUM_BALL_RADIUS,
                                   SCREEN_HEIGHT - MAXIMUM_BALL_RADIUS)
            x_speed = random.randint(MINIMUM_BALL_DX, MAXIMUM_BALL_DX)
            y_speed = random.randint(MINIMUM_BALL_DY, MAXIMUM_BALL_DY)
            new_radius = random.randint(MINIMUM_BALL_RADIUS,
                                        MAXIMUM_BALL_RADIUS)
            new_color = (random.random(), random.random(), random.random())
            while x_speed == 0:
                x_speed = random.randint(MINIMUM_BALL_DX, MAXIMUM_BALL_DX)
            while y_speed == 0:
                y_speed = random.randint(MINIMUM_BALL_DY, MAXIMUM_BALL_DY)
            if MY_BALL.r < ball.r:
                turtle.hideturtle()
                turtle.goto(0, 0)
                turtle.write("GAME OVER! NICE TRY!",
                             move=False,
                             align='center',
                             font=("Arial", 23, "bold"))
                turtle.update()
                turtle.sleep(2000)
                return False

            if MY_BALL.r > ball.r:
                global score
                score = score + ball.r
                turtle.undo()
                turtle.update()
                MY_BALL.r += 1
                MY_BALL.shapesize((MY_BALL_r + 1) / 10)
                ball.shapesize((MY_BALL_r + 1) / 10)
                ball.resizemode("earth2.gif")
                ball.goto(new_x, new_y)
                ball.dx = x_speed
                ball.dy = y_speed
                ball.r = new_radius
                ball.color(new_color)
                ball.shapesize(new_radius / 10)

    return True
Example #21
0
def undo():
    global commandList
    print("The number commands that can be undone: ", \
turtle.undobufferentries())
    undoInput = input("""If you would like to undo just one command type \
"undo".\n\n
Alternatively, if you would like to retrace all the turtle's steps to the \
beginning then please type "reversetimeloop".""")
    if undoInput == "undo":
        turtle.undo()
        commandList.pop()
    elif undoInput == "reversetimeloop":
        while turtle.undobufferentries():
            turtle.undo()
        pass
    else:
        print("Command not recognised")
Example #22
0
def check_myball_collision():
	global score
	for ball in BALLS:
		if collide(MY_BALL,ball) == True:
			ball_r4 = ball.r 
			my_ball_r4 = MY_BALL.r
			X_COORDINATE=random.randint(-SCREEN_WIDTH+MAXIMUM_BALL_RADIUS,SCREEN_WIDTH-MAXIMUM_BALL_RADIUS)
			Y_COORDINATE=random.randint(-SCREEN_HEIGHT+MAXIMUM_BALL_RADIUS,SCREEN_HEIGHT-MAXIMUM_BALL_RADIUS)
			X_AXISSPEED = random.randint(MINIMUM_BALL_DX , MAXIMUM_BALL_DX)
			Y_AXISSPEED = random.randint(MINIMUM_BALL_DY , MAXIMUM_BALL_DY)

			while X_AXISSPEED and Y_AXISSPEED == 0:
				X_AXISSPEED = random.randint(MINIMUM_BALL_DX , MAXIMUM_BALL_DY)
				Y_AXISSPEED = random.randint(MINIMUM_BALL_DY , MAXIMUM_BALL_DY)

			radius = random.randint(MINIMUM_BALL_RADIUS , MAXIMUM_BALL_RADIUS)
			

			color = (random.random(),random.random(),random.random())
			

			if my_ball_r4 > ball_r4:
				score = score + 2

				ball.r = radius
				ball.x = X_COORDINATE
				ball.y = Y_COORDINATE
				ball.goto(X_COORDINATE, Y_COORDINATE)
				ball.dx = X_AXISSPEED
				ball.dy = Y_AXISSPEED
				ball.color(color)
				ball.shapesize(ball.r/10)
				MY_BALL.r = my_ball_r4 + 2
				MY_BALL.shapesize(MY_BALL.r/10)
				turtle.undo()
				turtle.write("Score:"+str(score), move=False , align="right" , font=("Arial", 16 , "bold"))
				turtle.update()

			else:
				turtle.goto(0,0)
				turtle.write("YOU LOST!!", move=False , align="center" , font=("Arial", 16 , "bold"))
				hide_all_balls()
				return False

	return True		
def click(x, y):
    global Death, score, play
    play = False
    hammer.goto(x, y)
    x = hammer.pos()[0]
    y = hammer.pos()[1]
    z = 30
    click_trash = False
    for t in trash_list:
        if x in range(t.pos()[0] - z,
                      t.pos()[0] + z) and y in range(t.pos()[1] - z,
                                                     t.pos()[1] + z):
            show_trash()
            turtle.undo()
            turtle.hideturtle()
            turtle.penup()
            turtle.color('red')
            score += 1
            turtle.goto(900, 450)
            turtle.write(score,
                         move=False,
                         align='left',
                         font=('Arial', 30, 'normal'))
            click_trash = True
    if not click_trash:
        Death += 1
        for c in caleb_list:
            if x in range(c.pos()[0] - z,
                          c.pos()[0] + z) and y in range(
                              c.pos()[1] - z,
                              c.pos()[1] + z):
                show_caleb()
        if Death == 1:
            heart.ht()
        elif Death == 2:
            heart2.ht()
        elif Death == 3:
            heart3.ht()
            writer.ht()
            FONT = ('Arial', 60, 'normal')
            writer.color("white")
            writer.goto(-200, 0)
            writer.write("Game Over", font=FONT)
            return quit()
Example #24
0
def main():
    t.setundobuffer(10)
    # use number input method of turtle
    ch = t.numinput(
        "Number of players",
        "How many players will play Hangman - one or two. Please enter 1 or 2: ",
        1, 1, 2)
    print()
    if ch == 1:
        # use write method of turtle
        t.penup()
        t.setpos(x, y + 60)
        t.write(
            "OK. Here are the blanks for the letters of the word that the computer chose from dictionary.",
            True,
            align="left",
            font=("Arial", 10, "normal"))
        words = open("3000words.csv", "r")
        L = words.read()
        WL = list(L.split(","))
        words.close()
        onePlayer(WL)
    elif ch == 2:
        # use text input method of turtle
        Word = t.textinput("Word for the game",
                           "Player1 please enter the word for the game")
        twoPlayers(Word)
    else:
        # use write method of turtle
        t.penup()
        t.setpos(x, y + 20)
        t.pencolor("red")  # changing pen colors of turtle
        t.hideturtle()
        t.write("Invalid entry.",
                True,
                align="left",
                font=("Arial", 10, "normal"))
        time.sleep(1)
        t.undo()  # turtle function for undoing last action
        t.pencolor("black")  # changing pen colors of turtle
        choice()
Example #25
0
def interact():
	code = raw_input("Turtle Command: ")
	if code == "circle":
		value = float(raw_input("Select Value: "))
		turtle.circle(value)
	elif code == "color":
		value = raw_input("Select Value: ")
		turtle.color(value)
	elif code == "line":
		value = raw_input("Select Value: ")
		if value == "off":
			turtle.up()
		elif value == "on":
			turtle.down()
	elif code == "forward":
		value = float(raw_input("Select Value: "))
		turtle.forward(value)
	elif code == "backward":
		value = float(raw_input("Select Value: "))
		turtle.backward(value)
	elif code == "right":
		value = float(raw_input("Select Value: "))
		turtle.right(value)
	elif code == "left":
		value = float(raw_input("Select Value: "))
		turtle.left(value)
	elif code == "speed":
		value = float(raw_input("Select Value: "))
		turtle.speed(value)
	elif code == "origin":
		turtle.home()
	elif code == "undo":
		turtle.undo()
	elif code == "github":
		github()
	elif code == "quit":
		exit()
	elif code == "clear":
		turtle.clear()
	else:
		print "Unknown command."
Example #26
0
def check_myball_collision(MY_BALL):
    for ball in BALLS:
        if collide(MY_BALL, ball) == True:
            ball_r4 = ball.r
            my_ball_r4 = MY_BALL.r
            X_COORDINATE = random.randint(-SCREEN_WIDTH + MAXIMUM_BALL_RADIUS,
                                          SCREEN_WIDTH - MAXIMUM_BALL_RADIUS)
            Y_COORDINATE = random.randint(-SCREEN_HEIGHT + MAXIMUM_BALL_RADIUS,
                                          SCREEN_HEIGHT - MAXIMUM_BALL_RADIUS)
            X_AXISSPEED = random.randint(MINIMUM_BALL_DX, MAXIMUM_BALL_DX)
            Y_AXISSPEED = random.randint(MINIMUM_BALL_DY, MAXIMUM_BALL_DY)
            while X_AXISSPEED and Y_AXISSPEED == 0:
                X_AXISSPEED = random.randint(MINIMUM_BALL_DX, MAXIMUM_BALL_DY)
                Y_AXISSPEED = random.randint(MINIMUM_BALL_DY, MAXIMUM_BALL_DY)

            radius = random.randint(MINIMUM_BALL_RADIUS, MY_BALL.r)

            color = (random.random(), random.random(), random.random())
            global score
            score += 1
            turtle.undo()
            turtle.write("score = " + str(score),
                         font=("Comic Sans MS", 25, "normal"))

            if my_ball_r4 > ball_r4:

                ball.r = radius
                ball.x = X_COORDINATE
                ball.y = Y_COORDINATE
                ball.goto(X_COORDINATE, Y_COORDINATE)
                ball.dx = X_AXISSPEED
                ball.dy = Y_AXISSPEED
                ball.color(color)
                ball.shapesize(ball.r / 10)
                MY_BALL.r = my_ball_r4 + 2
                MY_BALL.shapesize(MY_BALL.r / 10)

            else:
                return False

    return True
Example #27
0
def eat_food():
    global score
    for food in FOOD:
        if collide(MY_BALL, food):
            MY_BALL_RADIUS = MY_BALL.radius
            foodRadius = food.radius
            x = random.randint(-SCREEN_WIDTH + MAXIMUM_BALL_RADIUS,
                               SCREEN_WIDTH - MINIMUM_BALL_RADIUS)
            y = random.randint(-SCREEN_HEIGHT + MAXIMUM_BALL_RADIUS,
                               SCREEN_HEIGHT - MAXIMUM_BALL_RADIUS)

            while x in range(int(-MY_BALL.radius + MY_BALL.xcor()),
                             int(MY_BALL.xcor() + MY_BALL.radius)):
                x = random.randint(-SCREEN_WIDTH + MAXIMUM_BALL_RADIUS,
                                   SCREEN_WIDTH - MINIMUM_BALL_RADIUS)

            while y in range(int(-MY_BALL.radius + MY_BALL.ycor()),
                             int(MY_BALL.ycor() + MY_BALL.radius)):
                y = random.randint(-SCREEN_HEIGHT + MAXIMUM_BALL_RADIUS,
                                   SCREEN_HEIGHT - MAXIMUM_BALL_RADIUS)
            dx = 0
            dy = 0
            while dx == 0:
                dx = random.uniform(MINIMUM_BALL_DX, MAXIMUM_BALL_DX)
            while dy == 0:
                dy = random.uniform(MINIMUM_BALL_DY, MAXIMUM_BALL_DY)
                MY_BALL.radius = MY_BALL.radius + 1
                MY_BALL.shapesize(MY_BALL.radius / 10)
                food.goto(x, y)
                food.dx = dx
                food.dy = dy
                score = score + 1
                turtle.undo()
                turtle.update()
                turtle.goto(Width, Height)
                turtle.write(str(score),
                             move=False,
                             align="right",
                             font=("Arial", 16, "bold"))
    return True
Example #28
0
def interact():
	code = raw_input("Turtle Command: ")
	if code == "circle":
		value = float(raw_input("Select Value: "))
		turtle.circle(value)
	elif code == "color":
		value = raw_input("Select Value: ")
		turtle.color(value)
	elif code == "line":
		value = raw_input("Select Value: ")
		if value == "off":
			turtle.up()
		elif value == "on":
			turtle.down()
	elif code == "forward":
		value = float(raw_input("Select Value: "))
		turtle.forward(value)
	elif code == "backward":
		value = float(raw_input("Select Value: "))
		turtle.backward(value)
	elif code == "right":
		value = float(raw_input("Select Value: "))
		turtle.right(value)
	elif code == "left":
		value = float(raw_input("Select Value: "))
		turtle.left(value)
	elif code == "speed":
		value = float(raw_input("Select Value: "))
		turtle.speed(value)
	elif code == "origin":
		turtle.home()
	elif code == "undo":
		turtle.undo()
	elif code == "quit":
		exit()
	elif code == "clear":
		turtle.clear()
	else:
		print "Unknown command."
Example #29
0
def line(lst):
    sl = [0, 0]
    len_ = len(lst)
    ok = False
    turtle.speed(10)
    turtle.clear()
    paintdot(lst)
    while not ok:
        ok = True
        for i in range(len_):
            ot = lst[i][0] * sl[0] + lst[i][1] * sl[1]
            if lst[i][2] == 1 and ot <= 0:
                sl[0] += lst[i][0]
                sl[1] += lst[i][1]
                ok = False
            elif lst[i][2] == -1 and ot >= 0:
                sl[0] -= lst[i][0]
                sl[1] -= lst[i][1]
                ok = False
        paintline(sl)
        if not ok:
            turtle.undo()
Example #30
0
def m_ball_col():
    for other in (Balls):
        for my_b in List_my_balls:
            if check_col(other, my_b):
                if other.r > my_b.r:
                    global score, h_scor
                    turtle.undo()
                    turtle.write(
                        " GAME OVER! your score is: " + str(score) +
                        " high score " + str(h_scor),
                        move=False,
                        align="left",
                        font=("Arial", 24,
                              "normal"))  #if your ball hit a bigger one
                    score = -1
                    answer = simpledialog.askstring(
                        "Input",
                        "Do you want to play again?",
                        parent=tk.Tk().withdraw())
                    if answer == "yes":
                        turtle.undo()
                        score += 1
                        for i in range(len(List_my_balls)
                                       ):  #making all of my balls restart
                            List_my_balls[i].r = 10
                            List_my_balls[i].shapesize(List_my_balls[i].r / 10)
                            List_my_balls[i].goto(400 - (20 * i),
                                                  400 - (20 * i))
                        for i in Balls:
                            if i.xcor() >= 350:
                                i.goto(100, 100)
                        turtle.write("Your score is:" + str(score) +
                                     " high score " + str(h_scor),
                                     move=False,
                                     align="left",
                                     font=("Arial", 24, "normal"))
                        s = turtle.getscreen()
                        s.onkey(space_bar, "space")
                    else:
                        quit()
                    return False
                elif my_b.r > other.r:  #if your ball hit a smaller one
                    if my_b.r > 100:  #in order that your ball w'ont be 2 big
                        my_b.r = 20
                    my_b.r += 10
                    score += 1  #because you ate a ball
                    if h_scor < score:
                        h_scor = score
                    turtle.undo()
                    my_b.r = 30
                    turtle.color(random.choice(colors))
                    turtle.write("Your score is:" + str(score) +
                                 " high score " + str(h_scor),
                                 move=False,
                                 align="left",
                                 font=("Arial", 24, "normal"))  #update score
                    my_b.shapesize(my_b.r / 10)
                    other.goto(100, 100)
                    return True
Example #31
0
def main():
    #设置一个画面
    windows = turtle.Screen()
    #设置背景
    windows.bgcolor('blue')
    #生成一个黄色乌龟
    bran = turtle.Turtle()
    bran.shape('turtle')
    bran.color('yellow')
    #开始你的表演
    # bran.circle(50,360,1000)

    bran.onclick(click(bran))

    for i in range(4):
        bran.speed(1)
        bran.fd(50)
        bran.lt(80)

    for i in range(8):
        turtle.undo()

    bran.pen(fillcolor="black", pencolor="red", pensize=10)
def game_over():
    if lives == 0:
        turtle.write(
            "oppsyy game over:( press S to continue or A to play again ",
            move=False,
            align="center",
            font=("Arial", 40, "normal"))  #this tells the player the bad news
        time.sleep(2)  #time so the player can read the bad news
        turtle.undo()  #we don't need the bad news to stay forever on te screen
        turtle.penup()
        turtle.goto(0, -50)
        turtle.write(
            "your score is " + str(score),
            align="center",
            font=("Arial", 40,
                  "normal"))  #basically it tells the player his/her score
        time.sleep(3)  #time so the player can read
        turtle.undo()  #we don't the score to stay forever
        print("oppssyyy game over")  #just to make sure my code worked
        turtle.onkeypress(
            continue_playing,
            S)  #when you hit s you continue from the place you've stopped
        turtle.onkeypress(play_again, A)  #when you hit a you start over again
        turtle.listen()
Example #33
0
def onclick_handler(x, y):
    if -100 < x < 100:
        if FONTSIZE < y < FONTSIZE * 3:
            turtle.undo()
            turtle.write("Option 1", font=FONT)
        elif -FONTSIZE < y < FONTSIZE:
            turtle.undo()
            turtle.write("Option 2", font=FONT)
        elif -FONTSIZE * 3 < y < -FONTSIZE:
            turtle.undo()
            turtle.write("Option 3", font=FONT)
Example #34
0
def fn(x, y):
    global dc, turn, a, b, c, d, count
    if x <= -480.0 and x >= -600.0 and y >= 250.0 and y <= 350.0:
        i = 0
        while i < 10:
            dc = random.randint(1, 6)
            image = str(dc) + ".gif"
            Dice = turtle.Turtle()
            screen.addshape(image)
            Dice.shape(image)
            Dice.ht()
            Dice.up()
            Dice.speed(0)
            Dice.setpos(-500, 300)
            screen.update()
            Dice.clear()
            Dice.st()
            i += 1

        if a == 100:
            style = ("Arial", 16, "bold")
            turtle.undo()
            turtle.write("Player1 win", font=style)

        elif b == 100:
            style = ("Arial", 16, "bold")
            turtle.undo()
            turtle.write("Player2 win", font=style)
        elif c == 100:
            style = ("Arial", 16, "bold")
            turtle.undo()
            turtle.write("Player3 win", font=style)
        elif d == 100:
            style = ("Arial", 16, "bold")
            turtle.undo()
            turtle.write("Player4 win", font=style)

        move()
    else:
        dice()
turtle.right(-90)
turtle.color('black')


turtle.speed(1)
turtle.color('blue')
b=turtle.stamp()
turtle.fd(100)
turtle.right(90)
turtle.color('red')
r=turtle.stamp()
turtle.fd(100)
turtle.right(90)
turtle.color('green')
g=turtle.stamp()
turtle.fd(100)
turtle.right(90)
turtle.color('yellow')
y=turtle.stamp()
turtle.fd(100)
turtle.right(90)
turtle.color('black')

turtle.clearstamp(y)
turtle.clearstamp(g)
turtle.clearstamp(r)
turtle.clearstamp(b)

turtle.undo()
turtle.exitonclick()
Example #36
0
def banner(s, color=TEXTCOLOR):
	turtle.home()
	turtle.color(color)
	turtle.write(s, True, align='center', font=('Arial', 48, 'italic'))
	time.sleep(3)
	turtle.undo()
Example #37
0
def banner(s):
	turtle.home()
	turtle.color('white')
	turtle.write(s, True, align='center', font=('Arial', 48, 'italic'))
	time.sleep(3)
	turtle.undo()
Example #38
0
def banner(s):
    turtle.home()
    turtle.color("white")
    turtle.write(s, True, align="center", font=("Arial", 48, "italic"))
    time.sleep(3)
    turtle.undo()