-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
52 lines (42 loc) · 1.27 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import turtle
import pandas
from states import States
# Setup
screen = turtle.Screen()
screen.setup(height=490, width=690)
screen.tracer(0)
screen.title("U.S. States Game")
IMAGE = "blank_states_img.gif"
GAME_STATE = True
SCORE = 0
screen.addshape(IMAGE)
turtle.shape(IMAGE)
# Data extraction from CSV
df = pandas.read_csv("50_states.csv")
# Global list creation
STATES_NAME = []
STATES_X = []
STATES_Y = []
# Append data from csv into list
for i in range(len(df)):
STATES_NAME.append(df["state"][i])
STATES_X.append(df["x"][i])
STATES_Y.append(df["y"][i])
# State object creation
for i in range(len(df)):
states = States(STATES_NAME[i], STATES_X[i], STATES_Y[i])
# Main loop
while GAME_STATE:
screen.update()
answer_state = (screen.textinput(title=f"{SCORE}/50", prompt="What's another state's name?")).title()
# Quit Game & Save Remaining
if answer_state == "Quit" or answer_state == "Exit" or answer_state == "Stop":
with open("remaining_states.txt", mode="w") as file:
file.write(states.exit())
GAME_STATE = False
# Increase score if true
if states.guess(answer_state):
SCORE += 1
# If score reaches 50
if SCORE == 50:
GAME_STATE = False