From 8e3caf43740a126bf6a92f8b1d4b05e93572f66c Mon Sep 17 00:00:00 2001 From: sonyi00 Date: Sat, 27 Nov 2021 13:16:09 +0900 Subject: [PATCH 1/6] redesign code and translate --- projects/Speed_Game/windows/main.py | 114 +--------------------------- 1 file changed, 1 insertion(+), 113 deletions(-) diff --git a/projects/Speed_Game/windows/main.py b/projects/Speed_Game/windows/main.py index 3b5905808..c2719f90b 100644 --- a/projects/Speed_Game/windows/main.py +++ b/projects/Speed_Game/windows/main.py @@ -160,116 +160,4 @@ def count(self, canv, timer_text): else: canv.after(1000, self.count, canv, timer_text) - # click check button - def checkBtn_click(self, master, user_text, check_answer, canv, check_img): - global answer, country_img - global correct_count, problem_count - problem_count -= 1 - - user_text = user_text.upper().replace(" ", "") - check_answer = check_answer.replace(" ", "") - - if (user_text == check_answer): - # correct - print('맞았습돠') - ImagePath = 'correct.png' - self.img3 = ImageTk.PhotoImage(Image.open(ImagePath).resize((100, 100), Image.ANTIALIAS)) - resultImage = canv.create_image(450, 30, anchor="nw", image=self.img3) - correct_count += 1 - else: - # wrong - print('틀렸슴돠') - ImagePath = 'wrong.png' - self.img4 = ImageTk.PhotoImage(Image.open(ImagePath).resize((100, 100), Image.ANTIALIAS)) - - resultImage = canv.create_image(450, 30, anchor="nw", image=self.img4) - - # resolve 15 problems - if problem_count <= 0: - master.switch_frame(FinishPage) - canv.after(1000, self.delete_img, canv, resultImage) - filename = random.choice(os.listdir("./images")) - code = filename.split(".")[0] - - # 엑셀에 없는 이미지일 경우 예외처리 - while code.upper() not in df.index: - filename = random.choice(os.listdir("./images")) - code = filename.split(".")[0] - - countryPath = "./images/" + filename - canv.after(1000,self.delete_img, canv, check_img) - self.img2 = ImageTk.PhotoImage(Image.open(countryPath).resize((180, 130), Image.ANTIALIAS)) - country_img = canv.create_image(210, 130, anchor="nw", image=self.img2) - answer = df["country"][code.upper()] - - print(answer) - - def passBtn_click(self, tk, canv, check_img): - global pass_count, pass_window - global country_img, answer - pass_count = pass_count - 1 - if (pass_count < 0): - print("패스 그만") - pass_count = 0 - tk.messagebox.showerror('Pass', 'You Don\'t have pass ticket!') - else: - filename = random.choice(os.listdir("./images")) - code = filename.split(".")[0] - - # 엑셀에 없는 이미지일 경우 예외처리 - while code.upper() not in df.index: - filename = random.choice(os.listdir("./images")) - code = filename.split(".")[0] - - countryPath = "./images/" + filename - canv.after(1000, self.delete_img, canv, check_img) - self.img2 = ImageTk.PhotoImage(Image.open(countryPath).resize((180, 130), Image.ANTIALIAS)) - country_img = canv.create_image(210, 130, anchor="nw", image=self.img2) - answer = df["country"][code.upper()] - - self.delete_img(canv, pass_window) - BtnFont = tkFont.Font(family="Consolas", size=15) - pass_btn = tk.Button(self, text="pass: " + str(pass_count) + "/3", - width=10, height=1, font=BtnFont, foreground="yellow", - background="black", relief="ridge", - activebackground="yellow", activeforeground="black", - command=lambda: self.passBtn_click(tk, canv, country_img)) - pass_window = canv.create_window((600 // 2) + 80, (500 // 2) + 140, window=pass_btn) - - def delete_img(self, canv, dele_img_name): - canv.delete(dele_img_name) - - -class FinishPage(tk.Frame): - def __init__(self, master): - tk.Frame.__init__(self, master) - ImagePath = 'halloween.png' - canv = tk.Canvas(self, width=600, height=500, bg='white') - canv.pack(side='bottom') - self.img = ImageTk.PhotoImage(Image.open(ImagePath).resize((600, 500), Image.ANTIALIAS)) - canv.create_image(0, 0, anchor="nw", image=self.img) - - labelFont = tkFont.Font(family="Arial", size=40, weight="bold") - canv.create_text((600 // 2), (500 // 2) - 50, fill="white", text="total score : " + str(correct_count)+ "/15", font=labelFont) - canv.create_text((600 // 2), (500 // 2) + 50, fill="white", text="Good Job!", font=labelFont) - - -if __name__ == "__main__": - pygame.init() - mySound = pygame.mixer.Sound("SpeedGameBgm.mp3") - mySound.play(-1) - pass_count = 3 - problem_count = 15 - correct_count = 0 - answer = 0 - country_img = 0 - pass_window = 0 - - df = pd.read_excel("./CountryCodeData.xlsx", index_col=0, names=["code", "country"]) - print(df["country"]["KR"]) - - app = SampleApp() - app.title("Speed Game") - - app.geometry('600x500+100+100') - app.mainloop() + From 2f781c831f940837ebedcb54526c3f1190104d8d Mon Sep 17 00:00:00 2001 From: GwakMirae Date: Sat, 27 Nov 2021 13:20:39 +0900 Subject: [PATCH 2/6] add checkBtn_click func --- projects/Speed_Game/windows/main.py | 71 ++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/projects/Speed_Game/windows/main.py b/projects/Speed_Game/windows/main.py index c2719f90b..8d0ccc2f1 100644 --- a/projects/Speed_Game/windows/main.py +++ b/projects/Speed_Game/windows/main.py @@ -160,4 +160,73 @@ def count(self, canv, timer_text): else: canv.after(1000, self.count, canv, timer_text) - + # click check button + def checkBtn_click(self, master, user_text, check_answer, canv, check_img): + global answer, country_img + global correct_count, problem_count + problem_count -= 1 + + user_text = user_text.upper().replace(" ", "") + check_answer = check_answer.replace(" ", "") + + if (user_text == check_answer): + # correct + print('correct') + ImagePath = 'correct.png' + self.img3 = ImageTk.PhotoImage( + Image.open(ImagePath).resize((100, 100), Image.ANTIALIAS)) + resultImage = canv.create_image( + 450, 30, anchor="nw", image=self.img3) + correct_count += 1 + else: + # wrong + print('wrong') + ImagePath = 'wrong.png' + self.img4 = ImageTk.PhotoImage( + Image.open(ImagePath).resize((100, 100), Image.ANTIALIAS)) + + resultImage = canv.create_image( + 450, 30, anchor="nw", image=self.img4) + + # resolve 15 problems + if problem_count <= 0: + master.switch_frame(FinishPage) + canv.after(1000, self.delete_img, canv, resultImage) + filename = random.choice(os.listdir("./images")) + code = filename.split(".")[0] + + # no entry in excel, Exception + while code.upper() not in df.index: + filename = random.choice(os.listdir("./images")) + code = filename.split(".")[0] + + countryPath = "./images/" + filename + canv.after(1000,self.delete_img, canv, check_img) + self.img2 = ImageTk.PhotoImage(Image.open(countryPath) + .resize((180, 130), Image.ANTIALIAS)) + country_img = canv.create_image(210, 130, anchor="nw", image=self.img2) + answer = df["country"][code.upper()] + + print(answer) + + +if __name__ == "__main__": + pygame.init() + mySound = pygame.mixer.Sound("SpeedGameBgm.mp3") + mySound.play(-1) + pass_count = 3 + problem_count = 15 + correct_count = 0 + answer = 0 + country_img = 0 + pass_window = 0 + + df = pd.read_excel( + "./CountryCodeData.xlsx", index_col=0, names=["code", "country"]) + print(df["country"]["KR"]) + + app = SampleApp() + app.title("Speed Game") + + app.geometry('600x500+100+100') + app.mainloop() \ No newline at end of file From 679d527f2a53c5e310e77cb0bc62fc8d0f8b1eed Mon Sep 17 00:00:00 2001 From: leecr1215 Date: Sat, 27 Nov 2021 13:24:14 +0900 Subject: [PATCH 3/6] add passBtn_click function and delete_img function --- projects/Speed_Game/windows/main.py | 39 +++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/projects/Speed_Game/windows/main.py b/projects/Speed_Game/windows/main.py index 8d0ccc2f1..970315d83 100644 --- a/projects/Speed_Game/windows/main.py +++ b/projects/Speed_Game/windows/main.py @@ -208,6 +208,45 @@ def checkBtn_click(self, master, user_text, check_answer, canv, check_img): answer = df["country"][code.upper()] print(answer) + + def passBtn_click(self, tk, canv, check_img): + global pass_count, pass_window + global country_img, answer + pass_count = pass_count - 1 + if (pass_count < 0): + print("Don't pass") + pass_count = 0 + tk.messagebox.showerror('Pass', 'You Don\'t have pass ticket!') + else: + filename = random.choice(os.listdir("./images")) + code = filename.split(".")[0] + + + while code.upper() not in df.index: + filename = random.choice(os.listdir("./images")) + code = filename.split(".")[0] + + countryPath = "./images/" + filename + canv.after(1000, self.delete_img, canv, check_img) + self.img2 = ImageTk.PhotoImage(Image.open(countryPath) + .resize((180, 130), Image.ANTIALIAS)) + country_img = canv.create_image(210, 130, anchor="nw", image=self.img2) + answer = df["country"][code.upper()] + + self.delete_img(canv, pass_window) + BtnFont = tkFont.Font(family="Consolas", size=15) + pass_btn = tk.Button( + self, text="pass: " + str(pass_count) + "/3", + width=10, height=1, font=BtnFont, foreground="yellow", + background="black", relief="ridge", + activebackground="yellow", activeforeground="black", + command=lambda: self.passBtn_click(tk, canv, country_img)) + pass_window = canv.create_window( + (600 // 2) + 80, (500 // 2) + 140, window=pass_btn) + + def delete_img(self, canv, dele_img_name): + canv.delete(dele_img_name) + if __name__ == "__main__": From 1a61df33dcc7be3cfefa00401c9556d29c742ffd Mon Sep 17 00:00:00 2001 From: Yejin Song <67140032+jinyesong@users.noreply.github.com> Date: Sat, 27 Nov 2021 13:30:29 +0900 Subject: [PATCH 4/6] Add FinishPage class --- projects/Speed_Game/windows/main.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/projects/Speed_Game/windows/main.py b/projects/Speed_Game/windows/main.py index 970315d83..a3c99a540 100644 --- a/projects/Speed_Game/windows/main.py +++ b/projects/Speed_Game/windows/main.py @@ -247,7 +247,18 @@ def passBtn_click(self, tk, canv, check_img): def delete_img(self, canv, dele_img_name): canv.delete(dele_img_name) +class FinishPage(tk.Frame): + def __init__(self, master): + tk.Frame.__init__(self, master) + ImagePath = 'halloween.png' + canv = tk.Canvas(self, width=600, height=500, bg='white') + canv.pack(side='bottom') + self.img = ImageTk.PhotoImage(Image.open(ImagePath).resize((600, 500), Image.ANTIALIAS)) + canv.create_image(0, 0, anchor="nw", image=self.img) + labelFont = tkFont.Font(family="Arial", size=40, weight="bold") + canv.create_text((600 // 2), (500 // 2) - 50, fill="white", text="total score : " + str(correct_count)+ "/15", font=labelFont) + canv.create_text((600 // 2), (500 // 2) + 50, fill="white", text="Good Job!", font=labelFont) if __name__ == "__main__": pygame.init() From f4e660f478e0969233854091f0ae057c30e2066e Mon Sep 17 00:00:00 2001 From: Yejin Song <67140032+jinyesong@users.noreply.github.com> Date: Sat, 27 Nov 2021 13:34:26 +0900 Subject: [PATCH 5/6] korean to english --- projects/Speed_Game/macOS/main.py | 2 +- projects/Speed_Game/windows/main.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/projects/Speed_Game/macOS/main.py b/projects/Speed_Game/macOS/main.py index fc1ca6a51..958add8c7 100644 --- a/projects/Speed_Game/macOS/main.py +++ b/projects/Speed_Game/macOS/main.py @@ -206,7 +206,7 @@ def passBtn_click(self, tk, canv, check_img): global country_img, answer pass_count = pass_count - 1 if (pass_count < 0): - print("패스 그만") + print("Don't pass") pass_count = 0 tk.messagebox.showerror('Pass', 'You Don\'t have pass ticket!') else: diff --git a/projects/Speed_Game/windows/main.py b/projects/Speed_Game/windows/main.py index a3c99a540..11a35f312 100644 --- a/projects/Speed_Game/windows/main.py +++ b/projects/Speed_Game/windows/main.py @@ -91,7 +91,6 @@ def __init__(self, master): filename = random.choice(os.listdir("./images")) code = filename.split(".")[0] - # 엑셀에 없는 이미지일 경우 예외처리 while code.upper() not in df.index: filename = random.choice(os.listdir("./images")) code = filename.split(".")[0] From 1aa606033deb97271b53c167cf863c8f833cf28c Mon Sep 17 00:00:00 2001 From: Yejin Song <67140032+jinyesong@users.noreply.github.com> Date: Sat, 27 Nov 2021 13:36:27 +0900 Subject: [PATCH 6/6] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 238369a94..af46692e4 100644 --- a/README.md +++ b/README.md @@ -198,3 +198,4 @@ SR No | Project | Author 101 | [Whatsapp Bot](https://github.com/Python-World/python-mini-projects/tree/master/projects/whatsapp_Bot)| [urmil89](https://github.com/urmil89) 102 | [Zip Bruter](https://github.com/Python-World/python-mini-projects/tree/master/projects/Zip_Bruter) | [Erdoğan YOKSUL](https://www.github.com/eredotpkfr) 103 | [CountDown Timer](https://github.com/Python-World/python-mini-projects/tree/master/projects/Countdown_timer) | [Japneet Kalra](https://github.com/japneetsingh035) +104 | [Speed Game](https://github.com/Python-World/python-mini-projects/tree/master/projects/Speed_Game) | [CNU CSE](https://github.com/songyi00/Speed_Game)