def create_screen(): screen = Screen() screen.bgpic(IMAGE_PATH) screen.setup(width=700, height=500) screen.title("US States Quiz") screen.listen() return screen
def setup_screen(screen: turtle.Screen) -> None: screen.title("US states game") screen.setup(SCREEN_WIDTH, SCREEN_HEIGHT) screen.bgpic("./states_img.gif") screen.bgcolor("gray") screen.listen() screen.tracer(0)
def create_screen(title='Crossy Road Game', width=600, height=600, color='white', bg_image=BACKGROUND): screen = Screen() screen.tracer(0) screen.bgcolor(color) screen.bgpic(bg_image) screen.listen() screen.setup() screen.title(title) return screen
def main(): screen = Screen() screen.bgpic("blank_states_img.gif") screen.setup(width=725, height=491) screen.title("Guess the state game") screen.onkey(screen.exitonclick, "Escape") screen.listen() states = pandas.read_csv("50_states.csv") states_guessed = [] while len(states_guessed) < len(states): answer = screen.textinput( title=f"{len(states_guessed)}/50 Guessed states", prompt="Guess the name of the states") if answer.lower() == "exit": # for state in states.state: # if state not in states_guessed: # state_data = states[states.state == state] # x = int(state_data.x) # y = int(state_data.y) # new_csv.append([state]) # Replaced code above with list comprehension method new_csv = [(row.state, row.x, row.y) for (index, row) in states.iterrows() if row.state not in states_guessed] df = pandas.DataFrame(new_csv) df.columns = ['state', 'x', 'y'] df.to_csv("Missed_states.csv", index=False) screen.bye() elif answer is not None: answer = answer.title() if answer in states.state.to_list(): states_guessed.append(answer) state_data = states[states.state == answer] x = int(state_data.x) y = int(state_data.y) position = (x, y) t = Turtle() t.hideturtle() t.penup() t.setpos(position) t.write(answer)
import time # Define Globals player = Turtle() wn = Screen() score = 0 scorestring = 'Score: %s' %score # Register Graphics turtle.register_shape('enemy.gif') turtle.register_shape('player.gif') wn.setup(700, 700) wn.title('Space Invaders') wn.bgcolor('black') wn.bgpic('background.gif') bp = Turtle() bp.speed(10) bp.color('white') bp.penup() bp.setposition(-300, -300) bp.pendown() bp.pensize(3) for side in range(4): bp.fd(600) bp.left(90) bp.hideturtle() en = 10 enemies = [] for i in range(en):
turtle.clear() dessineIntro1() screen.update() t2 = time.time() turtle.goto(0, -750) chrono = 0.0 x, y = turtle.position() t1 = time.time() while y < 450.00: turtle.clear() dessineIntro2() t2 = time.time() chrono += (time.time() - t1) while t2 - t1 > 0.01: screen.update() t1 = time.time() turtle.forward(1) x, y = turtle.position() screen = Screen() # Permet de définir la taille de la fenêtre qui va s'ouvrir screen.setup(width=1280, height=720) # Permet de changer le titre de la fenêtre screen.title("Bazar Bizarre Version Star Wars !") # Permet de changer le fond avec l'image "space.gif" screen.bgpic("space.gif") turtle = Turtle()
def main(): """Main loop where all the game logic is handled. Args: None. Returns: None. """ game_window = Screen() game_window.bgcolor("black") game_window.title("The Bouncy Space Ship Game") game_window.bgpic("background.gif") border = Border() game = Game() player1_score = Score(-290, 310, 1) player2_score = Score(190, 310, 2) border.draw_border() player1 = Player("blue") player2 = Player("purple") the_food = [] #List of Food objects. for _ in range(Food.amount): the_food.append( Food() ) #Spawning the food onto the screen and adding them to the food list. the_traps = [] #List of Trap objects. for _ in range(Traps.amount): the_traps.append( Traps() ) #Spawning the traps onto the screen and adding them to the food list. game_window.tracer(0) #Turn automatic scren updates off for preformance. player1_score.change_score(0) #Start the score at 0. player2_score.change_score(0) game_active1 = True game_active2 = True game_window.listen() game_window.onkey( player1.turnleft, "Left" ) #Turn the player's avatar left when the left button is pressed. game_window.onkey(player1.turnright, "Right") game_window.onkey( player1.increasespeed, "Up" ) #Increase the speed of the player's avatar when the up button is pressed. game_window.onkey(player1.decreasespeed, "Down") game_window.listen() game_window.onkey(player2.turnleft, "A") game_window.onkey(player2.turnright, "D") game_window.onkey(player2.increasespeed, "W") game_window.onkey(player2.decreasespeed, "S") game_window.onkey(player2.turnleft, "a") game_window.onkey(player2.turnright, "d") game_window.onkey(player2.increasespeed, "w") game_window.onkey(player2.decreasespeed, "s") while game_active1 or game_active2: game_window.update() #Update the game window every loop. for food in the_food: food.move() #Move the food. if player1 is not None and game.touch_checker( player1, food ): #If the player touches a food reset the food's position, play the eating sound, and update the score. food.regenerate() game.play_eating_sound() player1_score.change_score(10) if player2 is not None and game.touch_checker(player2, food): food.regenerate() game.play_eating_sound() player2_score.change_score(10) for trap in the_traps: trap.move() #Move the trap. if player1 is not None and game.game_over( player1, trap ): #If a player's avatar hits a trap take it out of the game. game.play_game_over_sound() game_active1 = False player1.hideturtle() del player1 player1 = None if player2 is not None and game.game_over(player2, trap): game.play_game_over_sound() game_active2 = False player2.hideturtle() del player2 player2 = None if game_active1: player1.move() #Move the player's avatar. if game_active2: player2.move() if not game_active1: #End the game if player 1's avatar has a lower score than player 1 and it gets hit by a trap. if player1_score.score < player2_score.score: game_active2 = False if not game_active2: #End the game if player 2's avatar has a lower score than player 2 and it gets hit by a trap. if player2_score.score < player1_score.score: game_active1 = False game.update_game_status(player1_score.score, player2_score.score) #Display the winner/ a draw. sleep(2.5)
def get_action( ): # This function gets what the player wants to do and where the player wants to move. global module, last_module, possible_moves, power, alive valid_action = False while not valid_action: print( "What do you want to do next ? (MOVE + MODULE, FUEL, SCANNER, POWER, LIFEFORMS, INFO, MAP, DIE)" ) action = input(">") while True: try: action_modified = (''.join( (item for item in action if not item.isdigit()))).replace(" ", "") if action_modified.upper() == "MOVE" or action_modified.upper( ) == "M": move = int(''.join( (item for item in action if not item.isalpha()))) if move in possible_moves or move == 99: valid_action = True last_module = module module = move else: print( "The module must be connected to the current module." ) elif action_modified.upper() == "SCANNER": command = input( "Scanner ready. Enter command (LOCK, SCAN):") if command.upper() == "LOCK": lock() if command.upper() == "SCAN": print( "Enter the module you want to scan. It must be connected to your current module." ) action = 0 while action not in possible_moves: print(possible_moves) action = int(input(">")) if action == queen: print("\nThere is a queen in there...") power -= 25 print("25 fuel has been used.") input("Press any button to continue...") print( "-----------------------------------------------------------------" ) elif action in workers: print("\nThere are workers in there...") power -= 25 print("25 fuel has been used.") input("Press any button to continue...") print( "-----------------------------------------------------------------" ) elif action in vent_shafts: print("\nThere are vent shafts in there...") power -= 25 print("25 fuel has been used.") input("Press any button to continue...") print( "-----------------------------------------------------------------" ) elif action in info_panels: print("\nThere are info panels in there...") power -= 25 print("25 fuel has been used.") input("Press any button to continue...") print( "-----------------------------------------------------------------" ) else: print("There is nothing in there...") power -= 25 print("25 fuel has been used.") input("Press any button to continue...") print( "-----------------------------------------------------------------" ) elif action_modified.upper() == "POWER": print("The space station has:", power, "power.") print( "-----------------------------------------------------------------" ) elif action_modified.upper() == "LIFEFORMS": print("Worker aliens are located in modules:", workers) input("Press any button to continue...") print( "-----------------------------------------------------------------" ) elif action_modified.upper() == "FUEL": print("You have:", fuel, "in your flamethrower.") input("Press any button to continue...") print( "-----------------------------------------------------------------" ) elif action_modified.upper() == "MAP": wn = Screen() wn.bgpic('map.gif') wn.mainloop() elif action_modified.upper() == "INFO": print("Ventilation shafts are located in modules:", vent_shafts) print("Information panels are located in modules:", info_panels) print("You are in module", module, ".") input("Press any button to continue...") print( "-----------------------------------------------------------------" ) elif action_modified.upper() == "EGG": print("Easter egg found!") action_egg = "Action Egg" if action_egg not in easter_eggs: easter_eggs.append(action_egg) input("Press any button to continue...") elif action_modified.upper() == "DIE": print( r""" ██████╗ ███████╗███████╗███████╗ █████╗ ████████╗ ██╔══██╗██╔════╝██╔════╝██╔════╝██╔══██╗╚══██╔══╝ ██║ ██║█████╗ █████╗ █████╗ ███████║ ██║ ██║ ██║██╔══╝ ██╔══╝ ██╔══╝ ██╔══██║ ██║ ██████╔╝███████╗██║ ███████╗██║ ██║ ██║ ╚═════╝ ╚══════╝╚═╝ ╚══════╝╚═╝ ╚═╝ ╚═╝ """) print("\nGame Over. You lose.") input("Press any key to finish...") reset() print( "-----------------------------------------------------------------\n" ) print( "-----------------------------------------------------------------\n" ) menu() break except: print( "Please type 'm' then the number of the module. e.g. 'm17'" ) break
import time from turtle import Screen from player import Player from car_manager import CarManager from scoreboard import Scoreboard screen = Screen() screen.setup(width=600, height=600) screen.bgcolor('black') screen.bgpic('cross_road_bg.gif') screen.tracer(0) screen.register_shape('turtle.gif') screen.register_shape('car_green.gif') screen.register_shape('car_blue.gif') screen.register_shape('car_pink.gif') screen.register_shape('car_purple.gif') screen.register_shape('car_orange.gif') screen.register_shape('car_yellow.gif') car_manager = CarManager() scoreboard = Scoreboard() player = Player() screen.listen() screen.onkey(player.go_up, "Up") game_is_on = True while game_is_on: time.sleep(0.1) screen.update()
def screen_init(): screen = Screen() screen.bgpic('blank_states_img.gif') screen.setup(725, 491) screen.title('Name the States') return screen
def main(): screen = Screen() screen.title("U.S.A. States game") screen.bgpic("blank_states_img.gif") play(screen) screen.exitonclick()
from turtle import Turtle, Screen import pandas as pd # # Screen setup screen = Screen() screen.title("U.S Guess the State") image = "blank_states_img.gif" screen.bgpic(image) # Getting the states data states_data = pd.read_csv("50_states.csv") all_states = states_data.state.to_list() right_guesses = [] while len(right_guesses) < 50: user_answer = screen.textinput( title=f"States correct {len(right_guesses)}/{len(states_data.state)}", prompt="Guess a state: ").title() if user_answer == "Exit": states_to_learn = [ all_states.remove(guess) for guess in right_guesses if guess in all_states ] states_to_learn.append(all_states) df = pd.DataFrame(states_to_learn) df.to_csv("states_to_learn.csv") break for state in states_data.state:
from turtle import Turtle, Screen import pandas as pd screen = Screen() screen.setup(725, 491) screen.bgpic('100_days_of_python\Day 25\\25_usa_quiz\\blank_states_img.gif') data = pd.read_csv('100_days_of_python\Day 25\\25_usa_quiz\\50_states.csv') df = pd.DataFrame(data) states = df['state'].tolist() print(states) state = Turtle() state.hideturtle() state.penup() state.speed('fastest') score = 0 game_on = True while game_on: guess = screen.textinput("Name all of the states", f"You have guessed {score} states.\n{len(states)-score} states left.\nType 'Give Up' to quit.\n\nName a state: ").title() if guess in states: score += 1 usa = df[df['state'] == guess] state.goto(int(usa['x']), int(usa['y'])) state.write(f"{guess}", move=False, align="center", font=("Arial", 8, "bold")) elif guess == 'Give Up': for i in states: usa = df[df['state'] == i] state.goto(int(usa['x']), int(usa['y'])) state.write(f"{i}", move=False, align="center", font=("Arial", 8, "bold"))
class Game(): """Make the game loop into a class. Responsible for drawing and updating all our objects""" def __init__(self): # Set up the screen self.screen = Screen() self.screen.bgcolor("black") self.screen.setup(width=650, height=700) self.screen.title("Space Invaders") self.screen.bgpic("assets\\sprites\\space_invaders_background.gif") # Register the shapes self.screen.register_shape("assets\\sprites\\invader.gif") self.screen.register_shape("assets\\sprites\\player.gif") # initial objects self.player = Player() self.bullet = Bullet(self.player) self.score = Score() self.border = Border() self.game_over = False # Create invaders self.number_of_enemies = 5 self.enemies = [] for i in range(self.number_of_enemies): self.enemies.append(Invader()) # Create keyboard bindings self.screen.listen() self.screen.onkey(self.player.move_left, "Left") self.screen.onkey(self.player.move_right, "Right") self.screen.onkey(self.bullet.fire_bullet, "space") def play_sound(self, filename): winsound.PlaySound("assets\\sounds\\{}".format(filename), winsound.SND_ASYNC) def run(self): """Make the game loop a function.""" while True: # When game_over is set, stop updating objects if not self.game_over: # for each enemy for invader in self.enemies: # Move the enemy left/right invader.move_left_right() # get the enemy back and down if (invader.xcor() < -280 or invader.xcor() > 280): # Move all enemies down for enemy in self.enemies: enemy.move_down() # Change enemy direction enemy.invader_speed *= -1 if invader.ycor() < -250: self.game_over = True print("Game Over") if is_collision(self.bullet, invader) == True: self.play_sound("explosion.wav") self.bullet.reset_positon() self.score.change_score(10) invader.reset_positon() if is_collision(self.player, invader) == True: self.player.hideturtle() invader.hideturtle() self.game_over = True print("Game Over") # Move the bullet if self.bullet.state == "fire": self.bullet.move_up() # Check to see if bullet has gone to the top if self.bullet.ycor() > 275: self.bullet.reset_positon() # Display the screen. self.screen.update() else: break # pause game input("Press enter to finish")
from turtle import Screen, Turtle import time from snake import Snake from food import Food from scoreboard import Scoreboard screen = Screen() screen.setup(width=600, height=600) screen.bgpic("random.png") screen.title("Snake Game") screen.tracer(0) snake = Snake() food = Food() scoreboard = Scoreboard() screen.listen() screen.onkeypress(snake.up, "Up") screen.onkeypress(snake.down, "Down") screen.onkeypress(snake.left, "Left") screen.onkeypress(snake.right, "Right") game_is_on = True while game_is_on: screen.update() time.sleep(0.05) snake.move() # Collision with food if snake.head.distance(food) < 15: scoreboard.update()
import pandas as pd from turtle import Screen from text import Text from score import Score df = pd.read_csv('50_states.csv') states = df.state.values.tolist() screen = Screen() screen.setup(730, 496) screen.bgpic('blank_states_img.gif') screen.tracer(0) score = Score() while states: answer = screen.textinput('Question', 'Type the name of state you know:').title() if answer in states: state, x, y = df[df.state == answer].values[0] Text(state, x, y) states.remove(answer) score.points += 1 score.hits += 1 score.refresh() screen.update() screen.exitonclick()
def main(): """Main loop where all the game logic is handled. Args: None. Returns: None. """ game_window = Screen() game_window.bgcolor("black") game_window.title("The Bouncy Space Ship Game") game_window.bgpic("background.gif") player = Player() border = Border() game = Game() border.draw_border() the_food = [] #List of Food objects. for _ in range(Food.amount): the_food.append( Food() ) #Spawning the food onto the screen and adding them to the food list. the_traps = [] #List of Trap objects. for _ in range(Traps.amount): the_traps.append( Traps() ) #Spawning the traps onto the screen and adding them to the food list. game_window.listen() game_window.onkey( player.turnleft, "Left" ) #Turn the player's avatar left when the left button is pressed. game_window.onkey(player.turnright, "Right") game_window.onkey( player.increasespeed, "Up" ) #Increase the speed of the player's avatar when the up button is pressed. game_window.onkey(player.decreasespeed, "Down") game_window.tracer(0) #Turn automatic scren updates off for preformance. game.change_score(0) #Start the score at 0. game_active = True while game_active: game_window.update() #Update the game window every loop. player.move() #Move the player's avatar. for food in the_food: food.move() #Move the food. if game.touch_checker( player, food ): #If the player touches a food reset the food's position, play the eating sound, and update the score. food.regenerate() game.play_eating_sound() game.change_score(10) for trap in the_traps: trap.move() #Move the trap. if game.game_over( player, trap ): #If the player hits a trap play the "Game Over" sound and end the game. game.play_game_over_sound() game_active = False game.update_game_status() #Display the "Game Over" message. sleep(2.5) #Keep the message displayed for 2.5 seconds before exiting.
import pandas from turtle import Screen, Turtle screen = Screen() screen.title("India State Game") screen.setup(width=583, height=684) screen.bgpic("india_map.gif") DATA = pandas.read_csv("india_state.csv") STATES = DATA["state"].to_list() correct_guess = 0 no_of_guess = 0 guessed_states = [] missed_states = [] while correct_guess < len(STATES): answer_state = screen.textinput( title=f"{correct_guess}/{len(STATES)} | {no_of_guess} Attempts", prompt="whats another state name ? \nType 'exit' to end").title() no_of_guess += 1 if answer_state == "Exit": for state in STATES: if state not in guessed_states: missed_states.append(state) missed_data = pandas.DataFrame(missed_states) missed_data.to_csv("states_to_learn.csv", index=False, header=["state"]) break if answer_state in STATES: if answer_state not in guessed_states:
from turtle import Turtle, Screen import pandas data = pandas.read_csv('50_states.csv') total = 50 correct_guess = [] screen = Screen() screen.setup(width=725, height=491) screen.title('US states game') img = 'blank_states_img.gif' screen.bgpic(img) t = Turtle() t.hideturtle() t.penup() states = data.state.to_list() while len(correct_guess) < total: ans = screen.textinput(f'Guess the state?({len(correct_guess)}/{total})', "What's another state name?").title() # ans = states[correct] if ans == 'Exit': missed_states = [s for s in states if s not in correct_guess] pandas.Series(missed_states).to_csv('missed_states.csv') break else: new_data = data[data.state == ans] if new_data.size: x = int(new_data.x) y = int(new_data.y) t.goto(x, y)
import sys from turtle import Screen, Turtle from time import sleep from random import randint import json import turtle screen = Screen() screen.setup(width=600, height=600) screen.bgpic('img/bg_image.png') screen.title("Snake Game") screen.tracer(0) class Snake: # Starts with a 3 squares long body def __init__(self, food_): self.starting_position = [(0, 0), (-20, 0), (-40, 0)] self.segments = [] self.food_ = food_ # Creating the snake initial body def create_snake_body(self): for position in self.starting_position: s = Turtle('square') s.color("green") s.pu() s.goto(position) self.segments.append(s) # Adds a body segment
from turtle import Screen, Turtle import pandas score =0 screen = Screen() screen.setup(725, 491) screen.title("US States Quiz Game") screen.bgpic("blank_states_img.gif") us_data = pandas.read_csv("50_states.csv") all_state = us_data.state.to_list() guessed_state = [] while len(guessed_state) < 50: user_guess = screen.textinput(f"{score}/50", "Please Input the State Name") if user_guess == "Exit": missing_state = [state for state in all_state if state not in guessed_state] missing_data = pandas.DataFrame(missing_state) missing_data.to_csv("states_to_learn.csv") break if user_guess in all_state: guessed_state.append(user_guess) score +=1 t = Turtle() t.hideturtle() t.penup() state_data = us_data[us_data.state == user_guess] # print(f"state location : ({state_data.x},{state_data.y})") t.goto(int(state_data.x), int(state_data.y))
class ScreenCursor: def __init__(self): self.screen = Screen() self.screen.tracer(0) self.screen.title("U.S. States Game") self.screen.setup(725, 632) self.screen.bgpic("blank_states_img.gif") ##------------------------------------------- self.main_cursor = Turtle() self.main_cursor.ht() self.main_cursor.pu() self.display_game_title() ##------------------------------------------- self.message_cursor = Turtle() self.message_cursor.ht() self.message_cursor.pu() self.message_cursor.color("black") ##------------------------------------------- self.state_cursor = Turtle() self.state_cursor.ht() self.state_cursor.pu() self.state_cursor.color("black") def display_game_title(self): self.main_cursor.color("black") self.main_cursor.setposition(160, 267) self.main_cursor.write("U.S. States Game", move=False, align="center", font=("Verdana", 28, "bold")) self.main_cursor.color("grey") self.main_cursor.setposition(210, 252) self.main_cursor.write(f"How well do you memorize US States?", move=False, align="center", font=("Verdana", 10, "italic")) def display_game_title(self): self.main_cursor.color("black") self.main_cursor.setposition(160, 267) self.main_cursor.write("U.S. States Game", move=False, align="center", font=("Verdana", 28, "bold")) self.main_cursor.color("grey") self.main_cursor.setposition(210, 252) self.main_cursor.write(f"How well do you memorize US States?", move=False, align="center", font=("Verdana", 10, "italic")) def display_welcome_message(self, x_position): self.message_cursor.clear() self.message_cursor.setposition(x_position, 0) self.message_cursor.write("Welcome to U.S. States Game", move=False, align="center", font=("Verdana", 18, "bold")) def display_input(self, message): self.message_cursor.clear() self.message_cursor.setposition(-350, -243) self.message_cursor.write(message, move=False, align="left", font=("Courier", 14, "bold")) def display_state_name(self, state_name, x_position, y_position): self.state_cursor.setposition(x_position, y_position) self.state_cursor.write(state_name, move=False, align="center", font=("Verdana", 8, "bold"))
from turtle import Turtle, Screen import random is_race_on = False colors = ['red', 'orange', 'yellow', 'green', 'blue', 'purple'] screen = Screen() screen.setup(width=500, height=400) screen.bgpic('turtle.png') user_bet = screen.textinput(title="Make Your Bet", prompt="Which Turtle Will Win The Race? Pick A Color: ") y_position = [-80, -50, -10, 30, 60, 90] all_turtles = [] for turtle_index in range(0, 6): new_turtle = Turtle(shape='turtle') new_turtle.color(colors[turtle_index]) new_turtle.penup() new_turtle.goto(x=-230, y=y_position[turtle_index]) all_turtles.append(new_turtle) if user_bet: is_race_on = True while is_race_on: for turtle in all_turtles: if turtle.xcor() > 230: is_race_on = False winning_color = turtle.pencolor() if winning_color == user_bet: print(f'Congratulations! The {winning_color} is the winner!')
# game will utilize graphics.py as opposed to turtle graphics from turtle import * from turtle import Turtle, Screen from random import * from math import * import os from mpg123 import * # screen set up win = Screen() win.bgcolor("black") win.title("Frenchie in Space Game") win.bgpic("Space.gif") # draw a border border_pen = Turtle() border_pen.speed(0) border_pen.color("white") border_pen.penup() border_pen.setposition(-300, -300) border_pen.pensize(5) border_pen.pendown() for side in range(4): border_pen.fd(600) border_pen.lt(90) border_pen.hideturtle() # register custom graphics to assigned turtles Screen().register_shape("space_cat.gif") Screen().register_shape("bone.gif") Screen().register_shape("frenchie.gif")
for names, x in data["x"].items(): new_dict[names] = [x] for names, y in data["y"].items(): new_dict[names].append(y) city_names = [] for names, values in new_dict.items(): new_dict[names] = tuple(values) city_names.append(names) #setting screen screen = Screen() screen.title("US MAP") screen.bgpic("Day 025/us-states-game-start/blank_states_img.gif") pen = Turtle() pen.hideturtle() pen.penup() right_names = [] while len(right_names) < len(city_names): city = screen.textinput(title="city",prompt= "Name a city on the map to stop write 'stop': ") if new_dict.get(city): pen.goto(new_dict[city]) right_names.append(city) pen.write(f"{city}", align = "center", font= ("Courier", 10, "normal")) if city == "stop": break screen.exitonclick()
""" Snake game """ from turtle import Screen # importing all reqd modules from snake import Snake from food_object import Food from score_tracker import ScoreTracker, HighScore from boundary_lines import BoundaryLines import time screen = Screen() # creating a screen instance screen.title("Snake Game - By Ashim") screen.setup(width=600, height=600) screen.cv._rootwindow.resizable(False, False) # preventing user from resizing screen screen.bgcolor("black") screen.bgpic("background.png") screen.tracer(0) speed = 0.1 def updater(): screen.update() time.sleep(speed) snake = Snake() food = Food() current_score = ScoreTracker() high_score = HighScore() high_score.print_high_score() boundary = BoundaryLines()
#1. Import Statements ################################### from turtle import Turtle, Screen import pandas as pd #2. Initialize the turtle and the screen ################################### sc = Screen() t = Turtle() #3. Make background and other settings ################################### SHAPE = "blank_states_img.gif" sc.bgpic(SHAPE) sc.title('🇺🇸 Game') t.penup() t.hideturtle() #4. Logistics ################################### state_guess = [] #Array to be populated in while loop df = pd.read_csv('50_states.csv') all_states = df.state.to_list() #Getting an array of states using the CSV file #5. Game Start ################################### while len(state_guess) < 50: #While they haven't guessed all the states
import time from turtle import Screen from player import Player from car_manager import Cars from scoreboard import Scoreboard cars = ["car1.gif", "car2.gif", "car4.gif", "car5.gif", "car6.gif", "car7.gif", "car8.gif"] screen = Screen() screen.title("Turtle Crossing Game") screen.setup(width=600, height=600) screen.bgpic("highway1.gif") for car_index in cars: screen.register_shape(car_index) screen.tracer(0) player = Player() car_manager = Cars(cars) scoreboard = Scoreboard() screen.listen() screen.onkey(fun=player.move_up, key="Up") screen.onkey(fun=player.move_down, key="Down") game_on = True while game_on: screen.update() time.sleep(0.1) car_manager.create_car() car_manager.move()
pos_y=pos_y, color='red') heading = calc_heading(x1=pos_x, y1=pos_y, x2=BASE_X, y2=BASE_Y) else: missile = Missile(x, y) heading = calc_heading(x1=pos_x, y1=pos_y, x2=x, y2=y) missile.pendown() missile.setheading(heading) missile.showturtle() missiles.append(missile) # создаем окно игры: window = Screen() window.setup(1200 + 3, 800 + 3) window.bgpic(os.path.join(BASE_PATH, "images", "background.png")) window.screensize(1200, 800) # window.tracer(n=2, delay=0) # инициализируем список для хранения объектов ракет: missiles = [] # Запускаем вражеские ракеты: for i in range(1, randint(2, N + 1)): fire_missile(x=BASE_X, y=BASE_Y, pos_x=randint(-600, 600), pos_y=400) # главный цикл игры: while True: window.update() window.onclick(fire_missile)
import time from turtle import Screen, Turtle from player import Player from car_manager import CarManager from scoreboard import ScoreBoard my_screen = Screen() my_screen.bgpic("road.jpg") my_screen.tracer(0) my_screen.colormode(255) my_screen.setup(width=800, height=600) my_screen.listen() player = Player() car_manager = CarManager() scoreboard = ScoreBoard() my_screen.onkey(fun=player.go_up, key="Up") def death_pointer(): point = Turtle() point.hideturtle() point.pencolor("red") point.penup() point.pensize(5) my_screen.bgcolor("red") point.goto(player.xcor(), player.ycor() - 20) player.stamp() player.hideturtle() point.pendown() for a in range(4):