Skip to content

Commit 6c82cf8

Browse files
authored
Merge pull request #17 from lironmiz/usStatesGame
Add files
2 parents a0c1a91 + 8fe3bc3 commit 6c82cf8

File tree

4 files changed

+172
-0
lines changed

4 files changed

+172
-0
lines changed

us_states_game/50_states.csv

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
state,x,y
2+
Alabama,139,-77
3+
Alaska,-204,-170
4+
Arizona,-203,-40
5+
Arkansas,57,-53
6+
California,-297,13
7+
Colorado,-112,20
8+
Connecticut,297,96
9+
Delaware,275,42
10+
Florida,220,-145
11+
Georgia,182,-75
12+
Hawaii,-317,-143
13+
Idaho,-216,122
14+
Illinois,95,37
15+
Indiana,133,39
16+
Iowa,38,65
17+
Kansas,-17,5
18+
Kentucky,149,1
19+
Louisiana,59,-114
20+
Maine,319,164
21+
Maryland,288,27
22+
Massachusetts,312,112
23+
Michigan,148,101
24+
Minnesota,23,135
25+
Mississippi,94,-78
26+
Missouri,49,6
27+
Montana,-141,150
28+
Nebraska,-61,66
29+
Nevada,-257,56
30+
New Hampshire,302,127
31+
New Jersey,282,65
32+
New Mexico,-128,-43
33+
New York,236,104
34+
North Carolina,239,-22
35+
North Dakota,-44,158
36+
Ohio,176,52
37+
Oklahoma,-8,-41
38+
Oregon,-278,138
39+
Pennsylvania,238,72
40+
Rhode Island,318,94
41+
South Carolina,218,-51
42+
South Dakota,-44,109
43+
Tennessee,131,-34
44+
Texas,-38,-106
45+
Utah,-189,34
46+
Vermont,282,154
47+
Virginia,234,12
48+
Washington,-257,193
49+
West Virginia,200,20
50+
Wisconsin,83,113
51+
Wyoming,-134,90

us_states_game/blank_states_img.gif

40.2 KB
Loading

us_states_game/main.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import turtle
2+
import pandas
3+
4+
# constant in the game
5+
BLANK_STATES_IMAGE_WIDTH = 725
6+
BLANK_STATES_IMAGE_HEIGHT = 495
7+
STATE_FONT = ("Verdana", 7, "normal")
8+
WELL_DONE_FONT = ("Verdana", 40, "normal")
9+
WELL_DONE_X_SPOT = 0
10+
WELL_DONE_Y_SPOT = 0
11+
ALIGN = 'center'
12+
NUM_STATES = 50
13+
X_COLUMN = 1
14+
Y_COLUMN = 2
15+
FIRST_USER_SCORE = 0
16+
WELL_DONE_TEXT = "well done!!"
17+
18+
pen = turtle.Turtle()
19+
screen = turtle.Screen()
20+
screen.title("liron us states game")
21+
image = "blank_states_img.gif"
22+
screen.addshape(image)
23+
turtle.shape(image)
24+
screen.setup(width=BLANK_STATES_IMAGE_WIDTH, height=BLANK_STATES_IMAGE_HEIGHT)
25+
# making data frame
26+
data = pandas.read_csv("50_states.csv")
27+
# making the state list and lower all the items
28+
data_state_list = data.state.to_list()
29+
data_state_list = [each_state.lower() for each_state in data_state_list]
30+
31+
32+
def main():
33+
user_need_to_learn_list = []
34+
user_score = FIRST_USER_SCORE
35+
user_right_answer = []
36+
print("welcome to liron us state game!!! if you done with the game enter 'Exit' ")
37+
while user_score < NUM_STATES:
38+
user_answer = screen.textinput(title=f"{user_score}/50", prompt="what's another state name?")
39+
if user_answer == "Exit":
40+
user_need_to_learn_list = [state for state in data.state if str(state).lower() not in user_right_answer]
41+
data_frame_user_need_to_learn = pandas.DataFrame(user_need_to_learn_list)
42+
data_frame_user_need_to_learn.to_csv("need_to_learn.csv")
43+
break
44+
for index, state in enumerate(data.state):
45+
if str(user_answer).lower() == str(data.iloc[index, 0]).lower() and str(
46+
user_answer).lower() not in user_right_answer:
47+
write_on_screen(data.iloc[index, X_COLUMN], data.iloc[index, Y_COLUMN], user_answer.lower(), STATE_FONT)
48+
user_score += 1
49+
user_right_answer.append(user_answer)
50+
# looping for all the states and checking if the user was right
51+
52+
if user_score == NUM_STATES:
53+
write_on_screen(WELL_DONE_X_SPOT, WELL_DONE_Y_SPOT, WELL_DONE_TEXT, WELL_DONE_FONT)
54+
turtle.mainloop()
55+
56+
57+
def write_on_screen(x_loc: int, y_loc: int, text: str, font: tuple) -> None:
58+
"""
59+
update the score of the users and show to screen
60+
Parameters: x_loc: int - the x coordinate of text, y_loc: int - the y coordinate of text
61+
text: str - the text data, font: tuple - the font style
62+
Returns: None
63+
"""
64+
pen.penup()
65+
pen.hideturtle()
66+
pen.color("black")
67+
pen.goto(x_loc, y_loc)
68+
pen.write(text, font=font, align=ALIGN)
69+
70+
71+
if __name__ == "__main__":
72+
main()

us_states_game/need_to_learn.csv

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
,0
2+
0,Alabama
3+
1,Arizona
4+
2,Arkansas
5+
3,California
6+
4,Colorado
7+
5,Connecticut
8+
6,Delaware
9+
7,Florida
10+
8,Georgia
11+
9,Hawaii
12+
10,Idaho
13+
11,Illinois
14+
12,Indiana
15+
13,Iowa
16+
14,Kansas
17+
15,Kentucky
18+
16,Louisiana
19+
17,Maine
20+
18,Maryland
21+
19,Massachusetts
22+
20,Michigan
23+
21,Minnesota
24+
22,Mississippi
25+
23,Missouri
26+
24,Montana
27+
25,Nebraska
28+
26,Nevada
29+
27,New Hampshire
30+
28,New Jersey
31+
29,New Mexico
32+
30,North Carolina
33+
31,North Dakota
34+
32,Ohio
35+
33,Oklahoma
36+
34,Oregon
37+
35,Pennsylvania
38+
36,Rhode Island
39+
37,South Carolina
40+
38,South Dakota
41+
39,Tennessee
42+
40,Texas
43+
41,Utah
44+
42,Vermont
45+
43,Virginia
46+
44,Washington
47+
45,West Virginia
48+
46,Wisconsin
49+
47,Wyoming

0 commit comments

Comments
 (0)