class Food(Turtle): def __init__(self): super().__init__() self.screen = Screen() self.screen.register_shape("apple.gif") self.screen.addshape("apple.gif") self.shape("apple.gif") self.penup() self.shapesize(stretch_len=0.5, stretch_wid=0.5) self.color("red") self.speed("fastest") self.refresh() def refresh(self): self.goto(x=randint(-270, 270), y=randint(-270, 270)) def draw_border(self): self.goto(x=-300, y=-300) self.pendown() self.pensize(20) for i in range(4): self.setheading(90 - 90 * i) self.forward(600) self.penup() self.refresh()
def add_all_cards(window: turtle.Screen): """function to create a list of all gif images in the ./gifs folder Args: window: turtle.Screen() instance Returns: [list]: list of gif images """ # list to hold card names cards = [] # path to folder gif_folder = './gifs/' # add each file to list for gif in os.listdir(gif_folder): if os.path.isfile(os.path.join(gif_folder, gif)): gif = os.path.join(gif_folder, gif) if gif.endswith('.gif'): cards.append(gif) # add gif to window shapes window.addshape(gif) # add default card gif window.addshape('./card.gif') return cards
def carregaimagens(caminho: str, tela: Screen) -> None: pastaatual = os.getcwd() os.chdir(caminho) imagens = glob('*.gif') for img in imagens: tela.addshape(img) os.chdir(pastaatual)
def draw_sections_controller(window: turtle.Screen): """Function to call functions that perform drawing """ # draw sections of board sections = turtle.Turtle() # hide cursor sections.hideturtle() draw_sections(sections) # draw out leaderboard draw_leaderboard() #draw the quit icon quit_icon = turtle.Turtle() window.addshape('./surrender.gif') draw_image(quit_icon, './surrender.gif', 320, -280)
class IssPlotter: def __init__(self): self.t = Turtle() self.screen = Screen() self.screen.title("ISS PLOTTER") self.image = "worldmap_grid.gif" self.screen.addshape(self.image) self.t.shape(self.image) self.t.goto(-16, 11) self.iss = Turtle() self.iss.shape('circle') self.iss.shapesize(0.25, 0.25) self.iss.penup()
class Board(Turtle): def __init__(self): super().__init__() self.points = 0 self.pen = Turtle() self.pen.color("black") self.pen.penup() self.pen.hideturtle() self.screen = Screen() self.screen.title("U.S States Game") self.image = "blank_states_img.gif" self.screen.addshape(self.image) self.shape(self.image) def write_on_board(self, x, y, txt): self.pen.goto(x, y) self.pen.write(txt)
class Map(Turtle): def __init__(self): super().__init__() self.screen = Screen() self.screen.title('U.S States Game') self.image = 'blank_states_img.gif' self.screen.addshape(self.image) self.screen.setup(width=735, height=491) self.shape(self.image) self.score = 0 self.states_chosen = [] def user_input(self): self.answer = self.screen.textinput( title=f"{self.score} / 50 States Correct", prompt="Whats another state's name?").lower() if self.answer != 'quit': self.states_chosen.append(self.answer) return self.answer def update_score(self): self.score += 1
def run(): data = pd.read_csv('50_states.csv') states = data[data.columns[0]] print(states) screen = Screen() screen.title('U.S. States Game') image = "blank_states_img.gif" screen.addshape(image) turtle.shape(image) # def get_mouse_click_cords(x, y): # print(x, y) # turtle.onscreenclick(get_mouse_click_cords) is_guessing = True counter = 0 guessed_states = [] while is_guessing: answer_state = screen.textinput(title=f"{counter}/50 Guess the State", prompt="What's another State name?").title().strip() if answer_state == "Exit": missing_states = [x for x in states if x not in guessed_states] print(f'The states that you missed guessing are:\n{missing_states}') # save a list with the missing states to learn: new_data = pd.DataFrame(missing_states) new_data.to_csv('states_to_learn.csv') break for st in data['state']: if st == answer_state: guessed_states.append(answer_state) counter += 1 state_data = data[data.state == answer_state] # Obtiene los datos de la fila state_cords = (int(state_data.x), int(state_data.y)) print_state = Naming(st, state_cords) # place_state(answer_state) if counter == 51: is_guessing = False
def us_states_game(): data = pandas.read_csv('50_states.csv') t=Turtle() t1= Turtle() t1.hideturtle() s=Screen() s.title("U.S State Game") image = "blank_states_img.gif" s.addshape(image) t.shape(image) num =0 while num != 50: answer = s.textinput(title=str(num)+"/50 "+"guess the corrently",prompt="What another State name?") if(answer !=None): value=data[data["state"].str.lower() == answer.lower()] t1.penup() t1.goto(value["x"].to_list()[0],value["y"].to_list()[0]) t1.write(answer) num +=1 else: s.exitonclick() print("You guess all state corretly!Try again") s.exitonclick()
elif (answer == "number"): #clicked on a number, only show number print(tile.number) tile.drawNumber() #clicked on an empty spot, show island else: # self.showIsland(xIndex, yIndex) #settings boxSize = 40 numberOfBoxes = [10, 10] numberOfMines = 10 screenWidth = numberOfBoxes[0] * (boxSize + 1) - 1 screenHeight = numberOfBoxes[1] * (boxSize + 1) - 1 screen = Screen() screen.setup(screenWidth, screenHeight) screen.setworldcoordinates(0, -screenHeight, screenWidth, 0) screen.bgcolor("gray") imageMine = "res/Mine.gif" screen.addshape(imageMine) screen.tracer(0, 0) #for making turtle instant myMap = TileMap(numberOfBoxes, boxSize, numberOfMines) screen.onclick(myMap.click) #set action for clicking screen.update() #for making turtle instant screen.mainloop()
BlueRocketLauncher = r"C:\Users\User\Desktop\a level computer science\Coursework\Week\Blue team\RocketLauncherBlueV20.gif" RedAntiAirTank = r"C:\Users\User\Desktop\a level computer science\Coursework\Week\Red team\AntiAirTankRedV20.gif" BlueAntiAirTank = r"C:\Users\User\Desktop\a level computer science\Coursework\Week\Blue team\AntiAirTankBlueV20.gif" RedSupplyTruck = r"C:\Users\User\Desktop\a level computer science\Coursework\Week\Red team\TransporterRedV20.gif" BlueSupplyTruck = r"C:\Users\User\Desktop\a level computer science\Coursework\Week\Blue team\TransporterBlueV20.gif" RedAntiAirMissleLauncher = r"C:\Users\User\Desktop\a level computer science\Coursework\Week\Red team\AntiAirMissleLauncherRedV20.gif" BlueAntiAirMissleLauncher = r"C:\Users\User\Desktop\a level computer science\Coursework\Week\Blue team\AntiAirMissleLauncherBlueV20.gif" RedHelicopter = r"C:\Users\User\Desktop\a level computer science\Coursework\Week\Red team\HelicopterRedV20.gif" BlueHelicopter = r"C:\Users\User\Desktop\a level computer science\Coursework\Week\Blue team\HelicopterBlueV20.gif" RedBomber = r"C:\Users\User\Desktop\a level computer science\Coursework\Week\Red team\BomberRedV20.gif" BlueBomber = r"C:\Users\User\Desktop\a level computer science\Coursework\Week\Blue team\BomberBlueV20.gif" RedJeep = r"C:\Users\User\Desktop\a level computer science\Coursework\Week\Red team\JeepRedV20.gif" BlueJeep = r"C:\Users\User\Desktop\a level computer science\Coursework\Week\Blue team\JeepBlueV20.gif" #Adding the red team screen.addshape(RedAntiAirMissleLauncher) screen.addshape(RedAntiAirTank) screen.addshape(RedBomber) screen.addshape(RedHelicopter) screen.addshape(RedInfantry) screen.addshape(RedJeep) screen.addshape(RedMobileGun) screen.addshape(RedRocketLauncher) screen.addshape(RedSupplyTruck) screen.addshape(RedTank) screen.addshape(BlueAntiAirMissleLauncher) screen.addshape(BlueAntiAirTank) screen.addshape(BlueBomber) screen.addshape(BlueHelicopter) screen.addshape(BlueInfantry) screen.addshape(BlueJeep)
from tkinter import PhotoImage from turtle import Turtle, Screen, Shape wn = Screen() # substitute 'subsample' for 'zoom' if you want to go smaller: smallerBee = PhotoImage(file="bee.gif").subsample(10, 10) wn.addshape("smaller", Shape("image", smallerBee)) player = Turtle("smaller") player.forward(100) wn.exitonclick() ##beeimage = "bee.gif" ##wn.addshape(beeimage) ##player.shape(beeimage) ##player.penup() ##player.speed(0) ## ##smallerBee = PhotoImage(file="bee.gif").subsample(10, 10) ##wn.addshape("smaller", Shape("image", smallerBee)) ##tortoise = Turtle("smaller") ##tortoise.stamp() ##screen.exitonclick()
screen.tracer(0) # Screen Dimension Variables SCREEN_TOP = screen.window_height() / 2 SCREEN_BOTTOM = screen.window_height() / 2 * -1 SCREEN_LEFT = screen.window_width() / 2 * -1 SCREEN_RIGHT = screen.window_width() / 2 SCREEN_DIMS = [(SCREEN_LEFT, SCREEN_RIGHT), (SCREEN_BOTTOM, SCREEN_TOP)] # Load invader_icons invader_icons = [] i = 0 for icon in INVADER_ICONS_SMALL: invader_icons.append(icon) screen.addshape(invader_icons[i]) i += 1 screen.addshape(SPACESHIP_IMG) # Initialise Game space_invaders_game = SpaceInvadersGame(initial_lives=3,screen_dims=SCREEN_DIMS,invader_icons=invader_icons, spaceship_img=SPACESHIP_IMG) # # # The game is watching your moves screen.listen() screen.onkey(fun=space_invaders_game.spaceship.move_left, key="Left") screen.onkey(fun=space_invaders_game.spaceship.move_right, key="Right") screen.onkey(fun=space_invaders_game.spaceship_shoot_laser, key="space") game_is_on = True loop_counter = 0
from turtle import Turtle, Screen from question import QuestionBoard import pandas question = QuestionBoard() my_screen = Screen() my_screen.title("Name a US state") image = "blank_states_img.gif" my_screen.addshape(image) my_turtle = Turtle() my_turtle.shape(image) state_turtle = Turtle() state_turtle.hideturtle() state_turtle.pu() answered_list = [] # continues asking for user input until all states have been gotten while question.score <= question.total_states: answered_question = question.ask_question() # if the user inputs exit, create a csv file of the remaining states of which the user did not answer if answered_question == "Exit": remaining_list = [states for states in question.STATES_READ if states not in answered_list] remaining_states = pandas.DataFrame(remaining_list) remaining_states.to_csv("remaining-states.csv") break elif question.check_answer(answered_question): if answered_question not in answered_list: question.add_score() state_turtle.goto(question.set_position(answered_question)) state_turtle.write(answered_question)
from turtle import Screen, shape from writer import Writer from score import Score import pandas as pd background = "blank_states_img.gif" states = pd.read_csv("50_states.csv") guessed_states = [] missing_states = [] screen = Screen() screen.title("Name US States Game") screen.addshape(background) shape(background) score = Score() writer = Writer() while score.total_score < 50: answer = screen.textinput( title=f"{score.total_score} / {score.total_states} States Correct", prompt="What's" " another state's name?").title() if answer == "Exit": for state in states["state"]: if state not in guessed_states: missing_states.append(state) missing_states_data = pd.DataFrame(missing_states) missing_states_data.to_csv("states_to_be_learned.csv") break
# Global Variables bars = [] removed_bars = [] # Starter Screen screen = Screen() screen.setup(width=800, height=800) screen.bgcolor("black") screen.title("Vaccinate!") screen.tracer(0) # Add Image Files to Screen ball_image = "gif/ball.gif" paddle_image = "gif/paddle.gif" screen.addshape(ball_image) screen.addshape(paddle_image) for i in range(2, 6): screen.addshape(f"gif/v{i}.gif") # Field def make_field(): global bars bar = Turtle() bar.penup() for i in range(2, 6): bar.shape(f"gif/v{i}.gif") for j in range(1, 11): bar.setpos(-400 + (j * 70), -100 + (i * 80)) a = bar.clone()
# # blk_sqr = sqr_data[sqr_data.Primary_Fur_Color=='Black'] # # print(len(gray_sqr),len(cin_sqr),len(blk_sqr)) # # # sqr_dict = { # "color":['Gray','Cinnamon','Black'], # "count":[g,c,b] # } # new_sqr_data = pandas.DataFrame(sqr_dict) # new_sqr_data.to_csv("new_sqr_data.csv") screen = Screen() tim = Turtle() screen.title("U.S. States Game") screen.setup(800, 800) screen.addshape("blank_states_img.gif") state_write = State_Writer("", 10, 100) tim.shape("blank_states_img.gif") # def mouse_click(x,y): # print(x,y) # screen.onscreenclick(fun=mouse_click) # screen.mainloop() states = pd.read_csv("50_states.csv") # # print(states) # for (idx,row) in states.iterrows(): # print(row.state) states_list = states.state.to_list()
from turtle import Screen, Turtle RedInfantry = r"C:\Users\User\Desktop\a level computer science\Coursework\Week\Red team\InfantryRedV20.gif" def InfantryRed(x, y): turtle = Turtle() turtle.shape(RedInfantry) turtle.penup() turtle.goto(x, y) return turtle screen = Screen() screen.addshape(RedInfantry) infantry_1 = InfantryRed(200, -200) infantry_2 = InfantryRed(-200, 200) #infantry_3 = InfantryRed(-200, -200) infantry_1.goto(200, 200) screen.exitonclick()
def DEFINE(): global player, bStamp, ANIMATE_TIMER, canDamage, animCount, playerHealth, BACHI, ST_HEALTH1, ST_HEALTH2, ST_HEALTH3, PHEALTH, FONT, t, COUNT_DIVISOR, sc, count, s, pStamp, movingBlocks, FALL_TIMER, CREATE_TIMER, CREATE_MAX, DEF_SPEED, SCORE_TIMER, DIED, StartStamp, RESTART_BOOLEAN, RESTART_TIMER, hasShot, ALL_MUSIC, shot, BOSS_TIMER, shotStamp, HEALTH, DAMAGE, bar, barStamp, CANSHOOT os.chdir(os.path.dirname(__file__)) RESTART_BOOLEAN = True FONT = 'Fixedsys' t = Turtle('square') t.color('red') t.pu() t.ht() t.shapesize(2) shot = Turtle('triangle') shot.color('green') shot.pu() shot.ht() shot.shapesize(0.5) sc = Turtle() sc.ht() sc.pu() sc.goto(-300, 325) sc.color('yellow') bar = Turtle('square') bar.ht() bar.pu() ALL_MUSIC = [ 'MEGALOVANIA.wav', 'mus_dummybattle.wav', 'mus_spider.wav', 'mus_vsasgore.wav', 'mus_x_undyne.wav', 'mus_mettaton_ex.wav' ] count = 0 HEALTH = 100 DAMAGE = 3.3334 CANSHOOT = True hasShot = 0 DEF_SPEED = 6 COUNT_DIVISOR = 70 PHEALTH = 3 canDamage = True s = Screen() s.tracer(False) s.screensize(400, 400) s.bgcolor('black') s.listen() for x in [ "HEART.gif", "oof.gif", "empty.gif", 'BACHI.gif', 'BACHI3.gif', 'BACHI2.gif' ]: s.addshape(x) playerHealth = Turtle("HEART.gif") playerHealth.pu() playerHealth.ht() BACHI = Turtle('BACHI.gif') player = Turtle('HEART.gif') player.color('blue') player.pu() player.ht() RANDINT = randint(0, 5) wav.PlaySound(ALL_MUSIC[RANDINT], wav.SND_LOOP | wav.SND_ASYNC) pStamp = None shotStamp = False barStamp = False movingBlocks = [] FALL_TIMER = 10 CREATE_TIMER = 400 SCORE_TIMER = 1000 RESTART_TIMER = 5000 BOSS_TIMER = 10000 CREATE_MAX = CREATE_TIMER ANIMATE_TIMER = 300 DIED = 0 animCount = 0 bStamp = BACHI.stamp() StartStamp = None Start()
from turtle import Screen from enemies import Enemies import time from turret import Turret from barriers import Barrier from scoreboard import Scoreboard enemy = "sprites/New Piskel.gif" ship = "sprites/ship.gif" screen = Screen() screen.bgcolor("black") screen.title("Space Invaders") screen.addshape(enemy) screen.addshape(ship) screen.setup(width=600, height=600) screen.tracer(0) enemies = Enemies() turret = Turret() barriers = Barrier() scoreboard = Scoreboard() def check_player_collisions(): for enemy in enemies.enemy_list: if turret.bullet: if turret.bullet.distance(enemy) < 20: enemies.kill(enemy) turret.destroy()
ball_count = 6 ball_size = 1.5 timeturtle = Turtle() timeturtle.penup() timeturtle.hideturtle() timeturtle.color("white") timeturtle.setpos(-20, 230) mixer.init() mixer.music.load("chomp.wav") eat_range = 200 ball_range = 45 ready = False round_time = 0 ball_list = [] second = time.time() screen.addshape('dog_left.gif') screen.addshape('dog_right.gif') screen.addshape('cat_right.gif') screen.addshape('cat_left.gif') screen.addshape('cross.gif') #Set up play area pen = Turtle() pen.width(3) pen.speed(0) pen.color("white") pen.penup() pen.setpos(-230, -230) pen.pendown() pen.hideturtle() for x in range(4):
dict_states = dict() answers = [] with open("50_states.csv") as file: data = list(file.readlines()) print(data) for row in data: line = row.strip().split(",") if line[0] != "state": dict_states[line[0].lower()] = (int(line[1]), int(line[2])) print(dict_states) screen = Screen() screen.title("U.S. States Game") img = "blank_states_img.gif" screen.addshape(img) shape(img) def get_mouse_click_coor(x, y): print(x, y) onscreenclick(get_mouse_click_coor) game_play = True lives = 3 score = 0 while lives > 0: ans = screen.textinput(f"What's another state's name?", f"{score}/50 States Correct\n{lives} lives remaining...").lower() if ans == "exit": break elif ans in dict_states:
import pandas import turtle from turtle import Screen, Turtle data = pandas.read_csv('50_states.csv') states = data['state'].to_list() screen = Screen() screen.title('U.S.A. States Game') usa_image = 'blank_states_img.gif' screen.addshape(usa_image) turtle.shape(usa_image) turtle = Turtle() turtle.hideturtle() turtle.up() states_remaining = len(states) states_total = states_remaining exit_loop = False while states_remaining > 0 and not exit_loop: answer = screen.textinput( title=f'{states_total - states_remaining}/{states_total} states', prompt='What\'s another state name?').title() if answer == 'Exit': exit_loop = True elif answer in states: row = data[data['state'] == answer] turtle.goto(int(row['x']), int(row['y'])) turtle.write(answer, align='center') states.remove(answer)
from turtle import Screen, Turtle import pandas screen = Screen() screen.title("Murica States Game") image = "blank_states_img.gif" screen.addshape(image) turtuga = Turtle() turtuga.shape(image) gegokte_states = [] data = pandas.read_csv("50_states.csv") all_states = data.state.to_list() while len(gegokte_states) < 50: antwoord_state = screen.textinput( title=f"{len(gegokte_states)}/50 States correct", prompt="State's name?") print(antwoord_state) if antwoord_state == "Exit": # missing_states = [] # for element in all_states: # if element not in gegokte_states: # missing_states.append(element) missing_states = [ element for element in all_states if element not in gegokte_states ] print(missing_states) df = pandas.DataFrame(missing_states) df.to_csv("states_to_learn.csv")
from turtle import Turtle, Screen import pandas as pd image_path = "blank_states_img.gif" data_path = "50_states.csv" turtle = Turtle() screen = Screen() correct_guessed_states = [] data = pd.read_csv(data_path) print(data.head()) screen.addshape(image_path) turtle.shape(image_path) while (len(correct_guessed_states) < len(data)): if len(correct_guessed_states) == 0: title = "Guess the state" else: title = f"{len(correct_guessed_states)}/{len(data)} States Correct" answer_state = screen.textinput( title, prompt="What's another state's name").title() if answer_state == "Exit": break found_row = data[data["state"] == answer_state] if len(found_row) > 0 and answer_state not in correct_guessed_states: correct_guessed_states.append(answer_state) turtle = Turtle() turtle.hideturtle() turtle.penup()
from turtle import Turtle, Screen from tatto import States import pandas screen = Screen() screen.title("U.S STATES GAME") image = "blank_states_img.gif" screen.addshape(image) # to load any shape for turtle turtle = Turtle() turtle.shape(image) screen.listen() # def mouse_click_coor(x, y): # print(x, y) # screen.onscreenclick(mouse_click_coor) guess_list = [] data = pandas.read_csv("50_states.csv") states_data = data.state while len(guess_list) < 50: answer = screen.textinput(title=f" {len(guess_list)}/50 States correct", prompt="What's the another guess").title() if answer == "Exit": missing_list = [ state for state in states_data if state not in guess_list ] missed_data = pandas.DataFrame(missing_list) missed_data.to_csv("missed_data.csv") break for state in states_data: if answer == state: state_data = data[data.state == answer] state_x = int(state_data.x)
from turtle import Turtle, Screen import turtle import pandas as p IMAGE_PATH = r"Working with CSV\Guess the state\blank_states_img.gif" CSV_PATH = r"Working with CSV\Guess the state\50_states.csv" screen = Screen() screen.title("U.S. States Game") screen.addshape(IMAGE_PATH) turtle.shape(IMAGE_PATH) statePosition = Turtle() statePosition.penup() statePosition.hideturtle() data = p.read_csv(CSV_PATH) stateList = data.state.to_list() answer_list = [] # xList = data.x.to_list() # yList = data.y.to_list() # To get the state coordinates # def getMouseClickCoor(x,y): # print(x,y) # turtle.onscreenclick(getMouseClickCoor) # turtle.mainloop() score = 0