Feb-02-2018, 11:05 PM
Yeah. I've been working on simplifying the code for a bit. I've found that the while/if approach is very clunky. So, I'll for sure work on simplifying the code! Thanks buran!
import turtle from tkinter import * import time import random A = turtle.Pen() B = turtle.Pen() C = turtle.Pen() D = turtle.Pen() E = turtle.Pen() F = turtle.Pen() A.shape('circle') A.shapesize(3) A.color('black', (0, 1, 1)) A.up() B.up() C.up() D.up() E.up() F.up() B.shape('square') B.up() B.color('black', 'blue') B.shapesize(25, 30) B.stamp() C.shape('square') C.shapesize(7) C.color('grey') C.goto(150, 150) D.shape('square') D.shapesize(7) D.color('grey') D.goto(-150, -150) E.shape('square') E.shapesize(7) E.color('grey') E.goto(-150, 150) F.shape('square') F.shapesize(7) F.color('grey') F.goto(150, -150) A.goto(-150, 150) canvas = Canvas() A.speed(0) B.up() B.shapesize(3) B.color('black', 'blue') B.speed(3) CC = 0 DD = 0 EE = 0 FF = 0 screen = turtle.Screen() s = turtle.Shape("compound") poly1 = ((-10,-10),(0,-10),(0,10),(-10,10)) poly2 = ((0, -15),(0, 15),(15, -5)) poly6 = ((0, -5), (-5, -5)) poly7 = ((0, 5), (-5, 5)) s.addcomponent(poly1, "peach puff", "black") s.addcomponent(poly2, "brown", "black") s.addcomponent(poly6, "blue", "black") s.addcomponent(poly7, "blue", "black") screen.register_shape("myshape", s) A.shape('myshape') A.seth(180) A.shapesize(4.5) s = turtle.Shape("compound") poly1 = ((-10,-10),(-10,10),(5,10),(5,-10)) poly2 = ((0, -5), (-5, -5)) poly3 = ((0, 5), (-5, 5)) poly4 = ((-8, 0), (-5, -5), (-5, 5)) poly5 = ((-15, -15), (-15, 15), (10, 15), (10, -15)) s.addcomponent(poly5, "blue", "black") s.addcomponent(poly1, "white", "black") s.addcomponent(poly2, "black", "black") s.addcomponent(poly3, "black", "black") s.addcomponent(poly4, "yellow", "black") screen.register_shape("penguin", s) B.shape('penguin') B.shapesize(4.5) B.seth(180) OPTS = [1, 2, 3, 4] def BEGIN(): A.color('black', (0, 1, 1)) B.goto(A.xcor(), A.ycor()) while 0 == 0: random.shuffle(OPTS) if OPTS[0] == 1 and F.isvisible() == True: B.goto(150, -150) if OPTS[0] == 2 and E.isvisible() == True: B.goto(-150, 150) if OPTS[0] == 3 and C.isvisible() == True: B.goto(150, 150) if OPTS[0] == 4 and D.isvisible() == True: B.goto(-150, -150) if B.xcor() == A.xcor() and B.ycor() == A.ycor(): A.seth(270) sys.exit() def MOVE(event): global CC global DD global EE global FF if A.xcor() == C.xcor() and A.ycor() == C.ycor(): if CC == 0: C.color('black', 'white') if CC == 3: C.color('black', 'yellow') if CC == 6: C.color('black', 'red') if CC == 9: C.hideturtle() CC = CC+1 if A.xcor() == D.xcor() and A.ycor() == D.ycor(): if DD == 0: D.color('black', 'white') if DD == 3: D.color('black', 'yellow') if DD == 6: D.color('black', 'red') if DD == 9: D.hideturtle() DD = DD+1 if A.xcor() == E.xcor() and A.ycor() == E.ycor(): if EE == 0: E.color('black', 'white') if EE == 3: E.color('black', 'yellow') if EE == 6: E.color('black', 'red') if EE == 9: E.hideturtle() EE = EE+1 if A.xcor() == F.xcor() and A.ycor() == F.ycor(): if FF == 0: F.color('black', 'white') if FF == 3: F.color('black', 'yellow') if FF == 6: F.color('black', 'red') if FF == 9: F.hideturtle() FF = FF+1 if event.keysym == 'Up': if A.ycor() != 150: A.goto(A.xcor(), A.ycor()+300) if event.keysym == 'Down': if A.ycor() != -150: A.goto(A.xcor(), A.ycor()-300) if event.keysym == 'Left': if A.xcor() != -450: A.goto(A.xcor()-300, A.ycor()) if event.keysym == 'Right': if A.xcor() != 450: A.goto(A.xcor()+300, A.ycor()) if event.keysym == 'Return': BEGIN() if A.xcor() == C.xcor() and A.ycor() == C.ycor() and C.isvisible() == False: A.seth(0) if A.xcor() == D.xcor() and A.ycor() == D.ycor() and D.isvisible() == False: A.seth(0) if A.xcor() == E.xcor() and A.ycor() == E.ycor() and E.isvisible() == False: A.seth(0) if A.xcor() == F.xcor() and A.ycor() == F.ycor() and F.isvisible() == False: A.seth(0) canvas.bind_all('<KeyPress-Up>', MOVE) canvas.bind_all('<KeyPress-Down>', MOVE) canvas.bind_all('<KeyPress-Left>', MOVE) canvas.bind_all('<KeyPress-Right>', MOVE) canvas.bind_all('<KeyPress-Return>', MOVE)
import turtle from tkinter import * import random import time import sys import winsound A = turtle.Pen() B = turtle.Pen() canvas = Canvas() OPTS = [1, 2, 3, 4] B.up() A.speed(0) B.speed(0) B.goto(-450, 270) A.shapesize(3) B.down() for x in range(0, 3): A.shape('square') time.sleep(0.1) A.color('red') time.sleep(0.1) A.color('green') time.sleep(0.1) A.color('blue') time.sleep(0.1) A.color('black') LIFE = 5 SCORE = 0 def SORT(event,): global SCORE global LIFE global TIME global AA TIME = time.clock() AA = TIME if LIFE < 1: A.color('black') sys.exit() if TIME > AA+5: B.undo() SCORE = SCORE -100 B.write(SCORE) LIFE = LIFE-1 A.speed(1) A.right(360) A.speed(0) if event.keysym == 'Up': if A.color() == ('red', 'red'): winsound.Beep(500, 100) A.up() A.goto(0, 250) A.stamp() A.home() SCORE = SCORE +100 B.undo() B.write(SCORE) if A.color() != ('red', 'red'): B.undo() SCORE = SCORE -100 B.write(SCORE) LIFE = LIFE-1 A.speed(1) A.right(360) A.speed(0) TIME = time.clock() if LIFE < 1: A.color('black') sys.exit() if TIME > AA+5: B.undo() SCORE = SCORE -100 B.write(SCORE) LIFE = LIFE-1 A.speed(1) A.right(360) A.speed(0) if event.keysym == 'Left': if A.color() == ('green', 'green'): winsound.Beep(500, 100) A.up() A.goto(-450, 0) A.stamp() A.home() B.undo() SCORE = SCORE +100 B.write(SCORE) if A.color() != ('green', 'green'): B.undo() SCORE = SCORE -100 B.write(SCORE) LIFE = LIFE-1 A.speed(1) A.right(360) A.speed(0) TIME = time.clock() if LIFE < 1: A.color('black') sys.exit() if TIME > AA+5: B.undo() SCORE = SCORE -100 B.write(SCORE) LIFE = LIFE-1 A.speed(1) A.right(360) A.speed(0) if event.keysym == 'Right': if A.color() == ('blue', 'blue'): winsound.Beep(500, 100) A.up() A.goto(450, 0) A.stamp() A.home() B.undo() SCORE = SCORE +100 B.write(SCORE) if A.color() != ('blue', 'blue'): B.undo() SCORE = SCORE -100 B.write(SCORE) LIFE = LIFE-1 A.speed(1) A.right(360) A.speed(0) TIME = time.clock() if LIFE < 1: A.color('black') sys.exit() if TIME > AA+5: B.undo() SCORE = SCORE -100 B.write(SCORE) LIFE = LIFE-1 A.speed(1) A.right(360) A.speed(0) if event.keysym == 'Down': if A.color() == ('gold', 'gold'): winsound.Beep(500, 100) A.up() A.goto(0, -270) A.stamp() A.home() B.undo() SCORE = SCORE +100 B.write(SCORE) if A.color() != ('gold', 'gold'): B.undo() SCORE = SCORE -100 B.write(SCORE) LIFE = LIFE-1 A.speed(1) A.right(360) A.speed(0) TIME = time.clock() if LIFE < 1: A.color('black') sys.exit() if TIME > AA+5: B.undo() SCORE = SCORE -100 B.write(SCORE) LIFE = LIFE-1 A.speed(1) A.right(360) A.speed(0) if event.keysym == 'Return': pass random.shuffle(OPTS) if OPTS[0] == 1: A.color('red') if OPTS[0] == 2: A.color('green') if OPTS[0] == 3: A.color('blue') if OPTS[0] == 4: A.color('gold') canvas.bind_all('<KeyPress-Up>', SORT) canvas.bind_all('<KeyPress-Left>', SORT) canvas.bind_all('<KeyPress-Right>', SORT) canvas.bind_all('<KeyPress-Down>', SORT) canvas.bind_all('<KeyPress-Return>', SORT)