From 6c3c6679399663357c1207d802f341c381b0abe4 Mon Sep 17 00:00:00 2001 From: pythonboi Date: Sun, 10 Apr 2022 16:40:07 -0400 Subject: [PATCH 1/4] update the code and add comments --- turtleRace.py | 77 ++++++--------------------------------------------- 1 file changed, 9 insertions(+), 68 deletions(-) diff --git a/turtleRace.py b/turtleRace.py index 5ceb51f..16e055a 100644 --- a/turtleRace.py +++ b/turtleRace.py @@ -2,6 +2,7 @@ from turtle import Turtle, Screen import random +# Create a screen method screen = Screen() # Give a title to the Windows Interface @@ -10,6 +11,7 @@ # Create a scree size to use for the window screen.setup(700, 500) +# Create a variable and make it False is_RaceOn = False # Ask a question and Enter you input message @@ -17,24 +19,16 @@ player1 = screen.textinput("Player1 Choose", prompt="Which turtle color will win the race?") player2 = screen.textinput("Player2 Choose", prompt="Which turtle color will win the race?") -# print(Answer) - +# Create a list of rainbow colors rainbowColors = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'] -# userNames = ['jenny', 'pam', 'tom', 'jane', 'jim', 'kim']#, #'sam'] - +# Create a list for the y position coordinate y_Position = [-30, -60, -90, 0, 30, 60, 90] +# Create an empty list to hold the turtle position newTurtle = [] -# -# def changeRange(x, y): -# global num -# for num in range(0, 6): -# num = num + 10 -# turtle.goto(-335, num) - - +# For loop to create multiple turtle with different colors for pick in range(0, 7): userNames = Turtle() # userNames.shape('turtle') userNames.shape("turtle") @@ -43,11 +37,12 @@ userNames.goto(-335, y_Position[pick]) newTurtle.append(userNames) -# print(newTurtle) +# Check if the players place a bet or have an input if player1 != '' and player2 != '': is_RaceOn = True +# Keep running the turtle until is False while is_RaceOn: for turtle in newTurtle: @@ -67,59 +62,5 @@ count = random.randint(0, 10) turtle.forward(count) - - -# def pickUser(): -# for name in userNames: -# name. - - -# for n in userNames: -# if n in userNames: -# n.goto(-335, 30) - -# pam = Turtle() -# pam.color("orange") -# pam.shape('turtle') -# pam.penup() -# pam.goto(-335, 30) -# -# tom = Turtle() -# tom.color("yellow") -# tom.shape('turtle') -# tom.penup() -# tom.goto(-335, 60) -# -# jane = Turtle() -# jane.color("green") -# jane.shape('turtle') -# jane.penup() -# jane.goto(-335, 90) -# -# jim = Turtle() -# jim.color("blue") -# jim.shape('turtle') -# jim.penup() -# jim.goto(-335, -30) -# -# kim = Turtle() -# kim.color("indigo") -# kim.shape('turtle') -# kim.penup() -# kim.goto(-335, -60) -# -# sam = Turtle() -# sam.color("violet") -# sam.shape('turtle') -# sam.penup() -# sam.goto(-335, -90) -# -# -# class Select: -# def __init__(self, color, shape, position): -# self.color = color -# self.shape = shape -# self.position = position - - +# Create the onclick exit once the task is completed screen.exitonclick() From 2646725cc281673bacbdba20873a5ab77a778bfa Mon Sep 17 00:00:00 2001 From: pythonboi Date: Wed, 13 Apr 2022 08:07:29 -0400 Subject: [PATCH 2/4] new code to make snake game --- Snake_game/main.py | 51 ++++++++++++++++++++++++++++++++++++++++++++++ snake_game.py | 0 2 files changed, 51 insertions(+) create mode 100644 Snake_game/main.py create mode 100644 snake_game.py diff --git a/Snake_game/main.py b/Snake_game/main.py new file mode 100644 index 0000000..7fa5f55 --- /dev/null +++ b/Snake_game/main.py @@ -0,0 +1,51 @@ +import time +from turtle import Turtle, Screen +import random + +myScreen = Screen() + +snakePosition = [0, -20, -40] +snake_draw = [] +# snake_color = ['white', 'white', 'white'] + +is_running = True + +myScreen.setup(width=600, height=600) +myScreen.bgcolor("black") +myScreen.title("Snake_Game ") + +myScreen.tracer(0) + +# myT.shape("square") +# myT.color('white') +# myT.penup() +# myT.goto(0, 0) +# snake_draw.append(myT) +# +# myT.shape("square") +# myT.color('white') +# myT.penup() +# myT.goto(-20, 20) +# snake_draw.append(myT) + + +for build in range(0, 3): + myT = Turtle() + myT.shape("square") + myT.color('white') + myT.penup() + myT.goto(snakePosition[build], 0) + snake_draw.append(myT) + + +# if snakePosition == 3: +# is_running = True + + +while is_running: + myScreen.update() + time.sleep(1) + for snake in snake_draw: + snake.forward(10) + +myScreen.exitonclick() diff --git a/snake_game.py b/snake_game.py new file mode 100644 index 0000000..e69de29 From 5878038cb9555fb3db90a5caeab4783bc6698154 Mon Sep 17 00:00:00 2001 From: pythonboi Date: Wed, 13 Apr 2022 08:09:23 -0400 Subject: [PATCH 3/4] added a second player option --- turtleRace.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/turtleRace.py b/turtleRace.py index 16e055a..0bb1d3a 100644 --- a/turtleRace.py +++ b/turtleRace.py @@ -41,6 +41,8 @@ # Check if the players place a bet or have an input if player1 != '' and player2 != '': is_RaceOn = True +else: + print("Please pick a color") # Keep running the turtle until is False while is_RaceOn: From 9ee030b1c325593970010159091694ab8f6f501c Mon Sep 17 00:00:00 2001 From: pythonboi Date: Fri, 15 Apr 2022 23:58:52 -0400 Subject: [PATCH 4/4] fix the snake movement --- Snake_game/main.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/Snake_game/main.py b/Snake_game/main.py index 7fa5f55..233157e 100644 --- a/Snake_game/main.py +++ b/Snake_game/main.py @@ -16,18 +16,6 @@ myScreen.tracer(0) -# myT.shape("square") -# myT.color('white') -# myT.penup() -# myT.goto(0, 0) -# snake_draw.append(myT) -# -# myT.shape("square") -# myT.color('white') -# myT.penup() -# myT.goto(-20, 20) -# snake_draw.append(myT) - for build in range(0, 3): myT = Turtle()