Code For Each Game We Made

Code For |SQUARE_HUNTER|

# 1. Create a screen 500 by 500.
# 2. Make the screen green. # 3. Make arrow shaped turtle. # 4. Make arrow shaped turtle spin left. # 5. Let arrow shoot when you press space. # 6. Make a square shaped turtle that relocates after you pop it. # 7. Has reload time. # 8. Finish game. import turtle import random import time Player_turtle = turtle.Turtle() Target_Turtle = turtle.Turtle() bullet = turtle.Turtle() text_turtle = turtle.Turtle() window = turtle.Screen() window.bgcolor('green') window.tracer(0) length = 600 width = 600 bullet.shape('circle') bullet.penup() bullet.in_motion = False bullet_speed = 10 Target_Turtle.penup() Player_turtle.shape('triangle') Player_turtle.shapesize(1, 2) Target_Turtle.shape('square') Player_turtle.color('black') Player_turtle.penup() spin_speed = 1000 window = turtle.Screen() window.bgcolor('green') bullet.hideturtle() def game(): target_counter = 0 text_turtle.clear() start_time = time.time() time_left = max_time while time_left >= 0: text_turtle.write('Time left: {} seconds'.format(int(time_left)), font=('Courier', 20, 'bold italic')) time_left = max_time - (time.time() - start_time) text_turtle.clear() Player_turtle.left(5) if bullet.in_motion: bullet.forward(bullet_speed) if bullet.distance(Target_Turtle) < 20: Target_Turtle.hideturtle() reload() set_target() target_counter = target_counter + 1 if bullet.xcor() < -width / 2 or bullet.xcor() > width / 2: bullet.hideturtle() reload() if bullet.ycor() < -length / 2 or bullet.ycor() > length / 2: reload() bullet.hideturtle() window.update() window.update() text_turtle.write('You popped:{} bubbles,\npress r to retry Square_Hunter.io,'.format(int(target_counter)), font=('Courier', 20, 'bold italic'), align='center') def set_target(): randomx = random.randint(-width/2, width/2) randomy = random.randint(-length/2, length/2) Target_Turtle.setposition(randomx, randomy) Target_Turtle.showturtle() def shoot(): bullet.in_motion = True bullet.setheading(Player_turtle.heading()) window.onkeypress(None,'space') bullet.showturtle() window.onkeypress(game, 'r') window.onkeypress(shoot,'space') window.listen() bullet.showturtle() def reload(): bullet.hideturtle() bullet.setposition(Player_turtle.position()) bullet.in_motion = False window.onkeypress(shoot, 'space') set_target() max_time = 120 target_counter = 0 start_time = time.time() time_left = max_time while time_left >= 0: text_turtle.write('Time left: {} seconds'.format(int(time_left)), font=('Courier', 20, 'bold italic')) time_left = max_time - (time.time() - start_time) text_turtle.clear() Player_turtle.left(5) if bullet.in_motion: bullet.forward(bullet_speed) if bullet.distance(Target_Turtle) < 20: Target_Turtle.hideturtle() reload() set_target() target_counter = target_counter + 1 if bullet.xcor() < -width/2 or bullet.xcor() > width/2: bullet.hideturtle() reload() if bullet.ycor() < -length/2 or bullet.ycor() > length/2: reload() bullet.hideturtle() window.update() window.update() text_turtle.write('You popped:{} bubbles,\npress r to retry Square_Hunter.io,'.format(int(target_counter)), font=('Courier', 20, 'bold italic'), align='center')

Code for |GOBLIN_HUNT|

import random print('|GOBLIN_HUNT|') print("\nAre you scared of goblins?\n") # Grab input for the user user_name = input("Enter your name: ") print(user_name + ", can you find the scary goblin hiding in the kitchen cupboards?\n") number_of_doors=5 #print goblin doors print("|_||_||_||_||_|") # part 1: Decide which door goblin behind goblin_door = random.randint(1, number_of_doors) play_game = True #part 2: asking the user to guess while play_game: user_guess = input("Guess a door(using a number from 1 to 5):") user_guess_as_int = int(user_guess) #part 3: checking if the user is correct if goblin_door == int(user_guess): print("\nWell done! You have found the goblin") play_game = False else: print("\n Incorrect guess!") #part 4: continue game if the user guesses wrong

Code for |TURTLE_RUN|

import turtle import random import time width = 600 length = 600 player_turtle = turtle.Turtle() player_turtle.penup() player_turtle.shape('turtle') player_turtle.color('orange') bubble_turtle = turtle.Turtle() text_turtle = turtle.Turtle() text_turtle.hideturtle() bubble_turtle.penup() bubble_turtle.hideturtle() # Instruction screen code window = turtle.Screen() window.bgcolor('green') window.setup(width, length) window.tracer(0) text_turtle.write('Press Right arrow and Left arrow to turn the turtle,\npress space to start Turtle.io', font=('Courier', 20, 'bold italic'), align='center',) # Instruction screen code player_turtle.hideturtle() window.tracer(0) def make_bubble(): randomx = random.randint(-300, 300) randomy = random.randint(-300, 300) bubble_turtle.setx(randomy) bubble_turtle.sety(randomx) bubble_turtle.dot(20) def move_left(): player_turtle.left(90) def move_right(): player_turtle.right(90) max_time=20 def game(): bubble_counter = 0 text_turtle.clear() make_bubble() start_time=time.time() time_left = max_time while time_left >= 0: text_turtle.write('Time left: {} seconds'.format(int(time_left)), font=('Courier', 20, 'bold italic')) time_left = max_time - (time.time() - start_time) text_turtle.clear() player_turtle.showturtle() player_turtle.forward(5) if player_turtle.xcor() > width/2 or player_turtle.xcor() < -width/2: player_turtle.setx(-player_turtle.xcor()) if player_turtle.ycor() > length/2 or player_turtle.ycor() < -length/2: player_turtle.sety(-player_turtle.ycor()) if player_turtle.distance(bubble_turtle) < 20: bubble_turtle.clear() make_bubble() bubble_counter = bubble_counter + 1 window.update() text_turtle.write('You popped: {} bubbles,\npress space to retry Turtle.io,\nExtra Rule:\nyou can only pop the new bubble on a new try.'.format(int(bubble_counter)), font=('Courier', 20, 'bold italic'), align='center') window.onkeypress(game,'space') window.onkeypress(move_left,'Left') window.onkeypress(move_right,'Right') window.listen() turtle.done() import turtle import random import time width = 700 length = 700 player_turtle = turtle.Turtle() player_turtle.penup() player_turtle.shape('turtle') player_turtle.color('orange') bubble_turtle = turtle.Turtle() text_turtle = turtle.Turtle() text_turtle.hideturtle() bubble_turtle.penup() bubble_turtle.hideturtle() # Instruction screen code window = turtle.Screen() window.bgcolor('green') window.setup(width, length) window.tracer() text_turtle.write('Press Right arrow and Left arrow to turn the turtle,\npress space to start Turtle.io', font=('Courier', 20, 'bold italic'), align='center',) # Instruction screen code player_turtle.hideturtle() window.tracer(0) def make_bubble(): randomx = random.randint(-300, 300) randomy = random.randint(-300, 300) bubble_turtle.setx(randomy) bubble_turtle.sety(randomx) bubble_turtle.dot(20) def move_left(): player_turtle.left(90) def move_right(): player_turtle.right(90) max_time=20 def game(): bubble_counter = 0 text_turtle.clear() make_bubble() start_time = time.time() time_left = max_time while time_left >= 0: text_turtle.write('Time left: {} seconds'.format(int(time_left)), font=('Courier', 20, 'bold italic')) time_left = max_time - (time.time() - start_time) text_turtle.clear() player_turtle.showturtle() player_turtle.forward(5) if player_turtle.xcor() > width/2 or player_turtle.xcor() < -width/2: player_turtle.setx(-player_turtle.xcor()) if player_turtle.ycor() > length/2 or player_turtle.ycor() < -length/2: player_turtle.sety(-player_turtle.ycor()) if player_turtle.distance(bubble_turtle) < 20: bubble_turtle.clear() make_bubble() bubble_counter = bubble_counter + 1 window.update() text_turtle.write('You popped: {} bubbles,\npress space to retry Turtle.io,\nExtra Challenge:\nyou can only pop the new bubble on a new try.'.format(int(bubble_counter)), font=('Courier', 20, 'bold italic'), align='center') window.onkeypress(game,'space') window.onkeypress(move_left,'Left') window.onkeypress(move_right,'Right') window.listen() turtle.done()

Code For |SPACE_INVADERS|

import turtle import random window = turtle.Screen() #variables width = 600 height = 600 bullet_speed = 10 window.game_over = False bullet = turtle.Turtle() bullet.penup() write = turtle.Turtle() write.penup() write.color("white") write.hideturtle() bullet.in_motion = False bullet.hideturtle() bullet.shape("circle") bullet.color("white") bullet.setposition(0, -300) spaceship = turtle.Turtle() screen_turtle = turtle.Turtle() alien_for_the_game = [] window.tracer(0) no_of_aliens = 50 spaceship.shape("triangle") spaceship.color("white") spaceship.penup() spaceship.left(90) def reload(): bullet.hideturtle() bullet.setposition(spaceship.position()) bullet.in_motion = False window.onkeypress(shoot, 'space') def intro_screen(): window.bgcolor("black") screen_turtle.hideturtle() screen_turtle.color("white") screen_turtle.write("Press s to start game, click space to shoot", font=("Comic sans", 18, "normal"), align="center") spaceship.setposition(0, -300) def right(): spaceship.right(10) def left(): spaceship.left(10) def shoot(): bullet.in_motion = True bullet.setheading(spaceship.heading()) window.onkeypress(None,'space') bullet.showturtle() def game_screen(): no_of_points = 0 screen_turtle.clear() window.bgcolor("black") spaceship.setposition(0, -300) for i in range(no_of_aliens): alien = turtle.Turtle() alien.color("green") alien.shape("circle") alien.hideturtle() alien.penup() alien.showturtle() alien.setx(random.randint(-width / 2, width / 2)) alien.sety(random.randint(height/2, height*2)) alien.right(90) alien_for_the_game.append(alien) while not window.game_over: for my_alien in alien_for_the_game: my_alien.forward(1) if bullet.in_motion: bullet.forward(bullet_speed) if bullet.ycor() > height/2: reload() for my_alien in alien_for_the_game: if bullet.distance(my_alien) < 20: my_alien.clear() my_alien.hideturtle() alien_for_the_game.remove(my_alien) write.setposition(240, 300) write.clear() no_of_points = no_of_points + 10 write.write(f"YOUR SCORE:{no_of_points}", font=("Cosmic sans", 12, "bold")) reload() if my_alien.ycor() < -height/2: window.game_over = True window.clear() window.bgcolor('red') write.color("black") write.setposition(0,0) write.write("YOU DIED :D", font=("Cosmic sans", 120, "bold"), align="center") write.setposition(160, 300) write.write(f"YOU SCORED:{no_of_points} POINTS", font=("Cosmic sans", 14, "bold")) window.update() window.onkeypress(shoot, "space") window.onkeypress(right, "Right") window.onkeypress(left, "Left") window.onkeypress(game_screen, "s") window.listen() intro_screen() turtle.done()

Code For |RPG_DUNGEON|

import random flees_left = 3 user_strength = random.randint(1, 10) enemies_slayed = 0 def RPG_Rules(): print('------------') print('How To Play') print('------------') print("1. You can choose to fight or flee an enemy\n2.If you choose to fight, your chances of winning are higher if " "your\n " "strength is higher than the enemy's and the higher your strength,\n the higher chance you have of winning." "\n3. If you beat the enemy you gain strength, but if you lose then your strength will decrease." "\n4. You can only choose to flee up to three times after you have used your three go's at fleeing" "\n you will have to fight." "\n5. You win if you can escape the dungeon by beating 10 enemies" "\n6. You lose if your strength falls to zero before you manage to escape") input("\n\nPress Enter to proceed") def show_player_stats(user_name, user_strength, flees_left, enemies_slayed): print(f"\nPLAYER STATS | {user_name}" f"\nStrength:{user_strength}" f"\nFlees left: {flees_left}" f"\nEnemies slayed: {enemies_slayed}\n\n\n") def show_options(): print("--------") print("1. Fight\n") print("2. Flee\n") print("3. Show rules\n") print("Q. Quit\n") selected = input("Enter number/letter") return selected.upper() def intro_screen(): print("-----------------") print("LOST IN A DUNGEON") print("-----------------") print(f"\n{user_name}, you are in a dark, damp dungeon.\n" "You don't remember how you got into the dungeon.\n" "You've got to get out, quickly.\n") print('Hope you are feeling brave...') input("\n\nPress Enter to proceed") RPG_Rules() def get_player_name(): user_name = input("Enter your name:") return user_name def choose_enemy(): enemies = ["Frog","Alex","Dumpling","Rice","Sushi","Noodle","Hippopotamus"] enemy = random.choice(enemies) strength = random.randint(1,10) if enemy == "Alex": article = "an" else: article = "a" print(f"You have encountered {article} {enemy}.\nIts strength is {strength}") return enemy, strength user_name = get_player_name() intro_screen() show_player_stats(user_name, user_strength, flees_left, enemies_slayed) def fight(enemies_slayed, user_strength): result = random.choice([1, 0]) if result == 1: print ('You have eliminated an enemy!') user_strength += 1 enemies_slayed = enemies_slayed + 1 show_player_stats(user_name, user_strength, flees_left, enemies_slayed) # show_options() else: print('You have lost a battle but not the war...') user_strength -= 1 show_player_stats(user_name, user_strength, flees_left, enemies_slayed) # show_options() return enemies_slayed, user_strength def flees(): print('Are you that scared?') def are_we_still_alive(user_strength, enemies_slayed): if enemies_slayed == 10: print("You have won the game, VICTORY ROYALE") return False if user_strength == 0: print("You have lost the game, LOSER ROYALE") return False return True still_alive = True while still_alive: choose_enemy() choice = show_options() if choice == '1': enemies_slayed, user_strength = fight(enemies_slayed, user_strength) still_alive = are_we_still_alive(user_strength, enemies_slayed) elif choice == '3': RPG_Rules() elif choice == "Q": print("you have quited the game, click the restart button to play the game. ") still_alive = False elif choice == '2': if flees_left == 0: print("you can't flee anymore haha sucker!") enemies_slayed, user_strength = fight(enemies_slayed, user_strength) still_alive = are_we_still_alive(user_strength, enemies_slayed) else: flees_left = flees_left - 1 flees() show_player_stats(user_name, user_strength, flees_left, enemies_slayed)

Code For |CROSSY_TURTLE|

import turtle import random height = 600 length = 600 play_game = True difficulty_level = input("\nEnter difficulty level (easy, hard, crazy):") no_of_bubbles = 20 if difficulty_level == 'easy': no_of_bubbles = 10 if difficulty_level == 'hard': no_of_bubbles = 20 if difficulty_level == 'crazy': no_of_bubbles = 30 print(difficulty_level) writer_turtle = turtle.Turtle() Player_Turtle = turtle.Turtle() window = turtle.Screen() window.setup(length, height) window.tracer(0) window.bgcolor('light grey') Player_Turtle.shape('turtle') Player_Turtle.color('red') Player_Turtle.penup() Player_Turtle.setposition(0,-300) Player_Turtle.left(90) buffer = 20 Eater_turtles = [] Player_Turtle.sety(-height/2 + buffer) for _ in range(no_of_bubbles): my_turtle = turtle.Turtle() my_turtle.shape('circle') my_turtle.penup() my_turtle.color(random.random(), random.random(), random.random()) Eater_turtles.append(my_turtle) spacing = height/no_of_bubbles starting_y = Player_Turtle.ycor() row = 1 for my_turtle in Eater_turtles: my_turtle.setx(random.randint(-length/2, length/2)) my_turtle_pos_y = starting_y + (spacing * row) my_turtle.sety(my_turtle_pos_y) print(my_turtle_pos_y) row = row + 1 def forward(): Player_Turtle.forward(10) window.update() def right(): Player_Turtle.right(90) window.update() def left(): Player_Turtle.left(90) window.update() def backwards(): Player_Turtle.forward(-10) window.update() def winning_screen(): window.clear() writer_turtle.write('#1 Victory Royal', font=('Courier', 24, 'bold italic'), align='center') def losing_screen(): window.clear() writer_turtle.write('You Were Eliminated by Eater_Ball You Placed Last', font=('Courier', 20, 'bold italic'), align='center') window.onkeypress(forward, 'Up') window.onkeypress(left, 'Left') window.onkeypress(right, 'Right') window.onkeypress(backwards, 'Down') window.listen() window.update() while True: for each in Eater_turtles: each.forward(10) if each.xcor() > length / 2 or each.xcor() < -length / 2: each.left(180) if Player_Turtle.distance(each) < 20: losing_screen() if Player_Turtle.distance(0,300) < 20: winning_screen() window.update()

Code For |DINO_RUNNER|

import turtle import random import time width = 600 height = 600 cacti = [] window = turtle.Screen() window.setup(width, height) window.tracer(0) window.register_shape("urmom.gif") window.register_shape("dino.gif") window.register_shape("Cactus.gif") draw_turtle = turtle.Turtle() Dino = turtle.Turtle() Dino.left(90) Dino.shape("dino.gif") Dino.penup() Dino.setposition(-280, 0) write = turtle.Turtle() draw_turtle.penup() draw_turtle.setposition(-300, -20) draw_turtle.pendown() draw_turtle.forward(600) write.hideturtle() draw_turtle.hideturtle() min_spawn_time = 1 max_spawn_time = 5 Dino.is_jumping = False def dino_jump(): Dino.is_jumping = True def spawn_cactus(): cactus = turtle.Turtle() cactus.shape("Cactus.gif") cactus.penup() cactus.setx(300) cacti.append(cactus) window.update() spawn_cactus() spawn_cactus() spawn_cactus() spawn_cactus() window.update() game_over = False timer = time.time() start_timer = time.time() window.onkeypress(dino_jump, "space") window.listen() step = 5 end_time = 0 start_time = time.time() while not game_over: if time.time() - timer > random.randint(min_spawn_time, max_spawn_time): spawn_cactus() timer = time.time() end_timer = time.time() for cactus in cacti: cactus.forward(-2) if cactus.distance(Dino) < 20: game_over = True window.clear() window.bgpic("urmom.gif") alive_seconds = (time.time() - start_time) write.setposition(-300, 270) write.write(f"YOU LASTED {alive_seconds} SECONDS", font=("Cosmic Sans", 20, "bold")) write.setposition(-105, -100) write.write(f"CLICK R TO TRY AGAIN", font=("Cosmic Sans", 20, "italic")) window.onkeypress(game_over, "r") if Dino.is_jumping: Dino.forward(step) if Dino.ycor() > 100: step = -step if Dino.ycor() < 0: step = -step Dino.sety(0) Dino.is_jumping = False window.update()

 

©2019 by TurtleGaming. Proudly created with Wix.com

This site was designed with the
.com
website builder. Create your website today.
Start Now