Game where there is a picture and the correct text you input flies to the place where the state is.
import turtle
import pandas
import time
n = 0
FONT = ('Arial',7,'normal')
#state turtle - move to states
state = turtle.Turtle()
state.hideturtle()
state.penup()
state.speed('fastest')
#solely for text that is displayed
text = turtle.Turtle()
text.hideturtle()
text.penup()
text.speed('fastest')
#screen management
screen = turtle.Screen()
screen.title('US states guess game')
image = 'blank_states_img.gif'
screen.addshape(image)
turtle.shape(image)
data = pandas.read_csv('50_states.csv')
states = data['state'].to_list()
game_is_on =True
while game_is_on:
title = f'US states game: {n}/50' #this has to be refreshed too
state_answer = (screen.textinput(title=title, prompt='What\'s a state name')).title()
if state_answer in states:
n += 1
x_cor = int(data[data['state'] == state_answer].x)
y_cor = int(data[data['state']==state_answer].y)
state.goto(x = x_cor, y = y_cor)
state.write(arg = state_answer,font = FONT)
else:
text.goto(-300,0)
text.write(arg='Wrong input, guess again', font= ('Arial', 50, 'normal'))
time.sleep(1.3)
text.clear()
if n == 50:
game_is_on = False
screen.exitonclick()
##make sure to put refresh needing things inside loop
Comments