1
0

main.py 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. import tkinter as tk
  2. from random import shuffle, randint, choice
  3. from PIL import Image, ImageTk
  4. from pygame import mixer
  5. import webbrowser as wb
  6. import os
  7. basedir = os.path.dirname(__file__)
  8. # Window
  9. root = tk.Tk()
  10. root.title("Elite Four")
  11. root.resizable(False, False)
  12. root.geometry("1280x720")
  13. # Canvas
  14. cv = tk.Canvas(root, width=1280, height=720)
  15. cv.place(x=0, y=0)
  16. # Game variables
  17. game_number = 4
  18. games_list = ["N", "C", "E", "W"]
  19. ended = False
  20. # Creation of the start menu
  21. start_button: tk.Button
  22. def menu():
  23. global start_button
  24. cv.delete("all")
  25. bg_rect = cv.create_rectangle(0, 0, 1280, 720, fill="#7993a3", outline="#7993a3")
  26. title = cv.create_text(640, 360, text="Elite Four", font=("Helvetica", 48, "bold"), fill="aliceblue")
  27. start_button = tk.Button(bg="#7993a3", fg="aliceblue", activebackground="aliceblue", activeforeground="#7993a3", text="START", font=("Helvetica", 24, "bold"), cursor="hand2", borderwidth=0, highlightthickness=0, command=start)
  28. start_button.place(x=576, y=600)
  29. def start():
  30. global game_number, games_list
  31. shuffle(games_list)
  32. game_number = 0
  33. start_button.destroy()
  34. next_game()
  35. def next_game():
  36. global ended
  37. cv.delete("all")
  38. if game_number < len(games_list):
  39. if games_list[game_number] == "N":
  40. miss_n_init()
  41. elif games_list[game_number] == "C":
  42. mister_c_init()
  43. elif games_list[game_number] == "E":
  44. mister_e_init()
  45. elif games_list[game_number] == "W":
  46. miss_w_init()
  47. else:
  48. # The END
  49. cv.create_rectangle(0, 0, 1280, 720, fill="#b7ddeb", outline="#b7ddeb")
  50. cv.create_text(640, 100, text="Well played!", font=("Helvetica", 64, "bold"), fill="#194a5c")
  51. cv.create_text(640, 310, text="Thank you for playing <3", font=("Helvetica", 48, "bold"), fill="#194a5c")
  52. cv.create_text(640, 520, text="Goodbyyyyye", font=("Helvetica", 64, "bold"), fill="#194a5c")
  53. github_link = cv.create_text(640, 660, text="PS : You can click here to put a star ⭐️ on GitHub :)", font=("Helvetica", 16, "bold"), fill="#194a5c")
  54. cv.tag_bind(github_link, "<Button-1>", lambda _ : wb.open("https://github.com/Hvrnbi/elite-four"))
  55. ended = True
  56. def reset():
  57. global game_number, miss_n_state, flour_qtt, flour_qtt_inc, sugar_qtt, sugar_qtt_inc, eggs_qtt, eggs_qtt_inc, milk_qtt, milk_qtt_inc, ingredients_height, mister_c_state,\
  58. mister_c_dialog, mister_c_result, skyline_image, ptimage, mister_c_input, mister_c_score, mister_e_state, mister_e_time, mister_e_time_count, mister_e_timer, mask_images,\
  59. masks_list, happy_mask, mister_e_dialog, miss_w_state, miss_w_dialog, notes_id, f_list, g_list, h_list, j_list, k_list, l_list, miss_w_score, miss_w_score_text
  60. game_number = 4
  61. # Miss N
  62. miss_n_state = 0
  63. flour_qtt = 0
  64. flour_qtt_inc = True
  65. sugar_qtt = 0
  66. sugar_qtt_inc = True
  67. eggs_qtt = 0
  68. eggs_qtt_inc = True
  69. milk_qtt = 0
  70. milk_qtt_inc = True
  71. ingredients_height = 359
  72. # Mister C
  73. mister_c_state = 0
  74. mister_c_dialog = 0
  75. skyline_image = 0
  76. ptimage = None
  77. mister_c_input = tk.Entry(root)
  78. mister_c_input.bind("<Return>", enter)
  79. mister_c_score = 0
  80. # Mister E
  81. mister_e_state = 0
  82. mister_e_time = 0
  83. mister_e_time_count = 0
  84. mister_e_timer = 0
  85. mask_images = []
  86. masks_list = []
  87. happy_mask = {}
  88. mister_e_dialog = 0
  89. # Miss W
  90. miss_w_state = 0
  91. miss_w_dialog = 0
  92. notes_id = []
  93. f_list = [[i, 0] for i in range(len(notes_list)) if notes_list[i][0] == 202]
  94. g_list = [[i, 0] for i in range(len(notes_list)) if notes_list[i][0] == 384]
  95. h_list = [[i, 0] for i in range(len(notes_list)) if notes_list[i][0] == 566]
  96. j_list = [[i, 0] for i in range(len(notes_list)) if notes_list[i][0] == 748]
  97. k_list = [[i, 0] for i in range(len(notes_list)) if notes_list[i][0] == 930]
  98. l_list = [[i, 0] for i in range(len(notes_list)) if notes_list[i][0] == 1112]
  99. miss_w_score = 0
  100. miss_w_score_text = 0
  101. menu()
  102. # General GUI functions
  103. def draw_dialog_area():
  104. dialog_rect = cv.create_rectangle(8, 500, 1272, 712, fill="#ffffff", outline="#ffffff")
  105. dialog_name_rect = cv.create_rectangle(580, 484, 700, 500, fill="#ffffff", outline="#ffffff")
  106. # Miss N game
  107. miss_n_state = 0
  108. flour_qtt = 0
  109. flour_qtt_inc = True
  110. sugar_qtt = 0
  111. sugar_qtt_inc = True
  112. eggs_qtt = 0
  113. eggs_qtt_inc = True
  114. milk_qtt = 0
  115. milk_qtt_inc = True
  116. miss_n_dialog: int
  117. flour_qtt_text: int
  118. sugar_qtt_text: int
  119. eggs_qtt_text: int
  120. milk_qtt_text: int
  121. ingredients_height = 359
  122. def miss_n_init():
  123. bg_rect = cv.create_rectangle(0, 0, 1280, 720, fill="#6abd9c", outline="#6abd9c")
  124. draw_dialog_area()
  125. dialog_name = cv.create_text(640, 500, text="Miss N", font=("Helvetica", 16, "bold"), fill="#163226")
  126. container_rect = cv.create_rectangle(1140, 80, 1240, 360, fill="#c9c9c9", outline="#c9c9c9")
  127. flour_rect = cv.create_rectangle(40, 100, 180, 280, fill="#fff4de", outline="#fff4de")
  128. flour_text = cv.create_text(110, 88, text="FLOUR", font=("Helvetica", 16), fill="#163226")
  129. sugar_rect = cv.create_rectangle(220, 160, 360, 280, fill="#ffb34f", outline="#ffb34f")
  130. sugar_top = cv.create_polygon(220, 160, 360, 160, 290, 100, fill="#ffb34f", outline="#ffb34f")
  131. sugar_text = cv.create_text(290, 88, text="SUGAR", font=("Helvetica", 16), fill="#163226")
  132. eggs_oval = cv.create_oval(400, 100, 540, 280, fill="#e6c493", outline="#e6c493")
  133. eggs_text = cv.create_text(470, 88, text="EGGS", font=("Helvetica", 16), fill="#163226")
  134. milk_rect = cv.create_rectangle(580, 160, 720, 280, fill="#ffffff", outline="#ffffff")
  135. milk_top = cv.create_rectangle(580, 100, 720, 160, fill="#0000cc", outline="#0000cc")
  136. milk_text = cv.create_text(650, 88, text="MILK", font=("Helvetica", 16), fill="#163226")
  137. miss_n_game()
  138. def miss_n_game():
  139. global miss_n_dialog, flour_qtt, flour_qtt_inc, flour_qtt_text, sugar_qtt, sugar_qtt_inc, sugar_qtt_text, eggs_qtt, eggs_qtt_inc, eggs_qtt_text, milk_qtt, milk_qtt_inc, milk_qtt_text
  140. if miss_n_state == 0:
  141. miss_n_dialog = cv.create_text(640, 606, text="Hiiiiii! I'm Miss N and in my game, you'll have to make a crêpe!\n\
  142. The rules are easy, just press SPACE when you think that a quantity is good.\n\
  143. If you follow the recipe, you win. If you don't, you lose.\n\
  144. Here is the recipe:\n\
  145. - 170g of flour\n\
  146. - 40g of sugar\n\
  147. - 3 eggs\n\
  148. - 600mL of milk\n\n\
  149. Press SPACE to start, good luck <3", font=("Helvetica", 12), fill="#163226")
  150. flour_qtt_text = cv.create_text(110, 308, text="", font=("Helvetica", 16), fill="#163226")
  151. sugar_qtt_text = cv.create_text(290, 308, text="", font=("Helvetica", 16), fill="#163226")
  152. eggs_qtt_text = cv.create_text(470, 308, text="", font=("Helvetica", 16), fill="#163226")
  153. milk_qtt_text = cv.create_text(650, 308, text="", font=("Helvetica", 16), fill="#163226")
  154. elif miss_n_state == 1:
  155. if flour_qtt_inc:
  156. flour_qtt += 1
  157. if flour_qtt == 400:
  158. flour_qtt_inc = False
  159. else:
  160. flour_qtt -= 1
  161. if flour_qtt == 0:
  162. flour_qtt_inc = True
  163. cv.itemconfig(flour_qtt_text, text=str(flour_qtt))
  164. root.after(8, miss_n_game)
  165. elif miss_n_state == 2:
  166. if sugar_qtt_inc:
  167. sugar_qtt += 1
  168. if sugar_qtt == 100:
  169. sugar_qtt_inc = False
  170. else:
  171. sugar_qtt -= 1
  172. if sugar_qtt == 0:
  173. sugar_qtt_inc = True
  174. cv.itemconfig(sugar_qtt_text, text=str(sugar_qtt))
  175. root.after(10, miss_n_game)
  176. elif miss_n_state == 3:
  177. if eggs_qtt_inc:
  178. eggs_qtt += 1
  179. if eggs_qtt == 5:
  180. eggs_qtt_inc = False
  181. else:
  182. eggs_qtt -= 1
  183. if eggs_qtt == 0:
  184. eggs_qtt_inc = True
  185. cv.itemconfig(eggs_qtt_text, text=str(eggs_qtt))
  186. root.after(140, miss_n_game)
  187. elif miss_n_state == 4:
  188. if milk_qtt_inc:
  189. milk_qtt += 1
  190. if milk_qtt == 1000:
  191. milk_qtt_inc = False
  192. else:
  193. milk_qtt -= 1
  194. if milk_qtt == 0:
  195. milk_qtt_inc = True
  196. cv.itemconfig(milk_qtt_text, text=str(milk_qtt))
  197. root.after(4, miss_n_game)
  198. def miss_n_end():
  199. global miss_n_state
  200. score = abs(flour_qtt - 170) * 3 + abs(sugar_qtt - 40) * 15 + abs(eggs_qtt - 3) * 200 + abs(milk_qtt - 600)
  201. if score < 300:
  202. cv.itemconfig(miss_n_dialog, text="Those crepes look delicious, great job!\nPress SPACE to continue <3")
  203. miss_n_state = 6
  204. else:
  205. cv.itemconfig(miss_n_dialog, text="It seems absolutely uneatable, I hope you'll do better next time.")
  206. root.after(5000, reset)
  207. # Mister C game
  208. mister_c_state = 0
  209. images_list = [os.path.join(basedir, "images/bucharest.png"), os.path.join(basedir, "images/dallas.png"), os.path.join(basedir, "images/dublin.png"), os.path.join(basedir, "images/kualalumpur.png"), os.path.join(basedir, "images/lagos.png"), os.path.join(basedir, "images/lyon.png"), os.path.join(basedir, "images/warsaw.png")]
  210. mister_c_answers = {os.path.join(basedir, "images/bucharest.png"): ["bucharest", "Bucharest", "BUCHAREST"], os.path.join(basedir, "images/dallas.png"): ["dallas", "Dallas", "DALLAS"], os.path.join(basedir, "images/dublin.png"): ["dublin", "Dublin", "DUBLIN"], os.path.join(basedir, "images/kualalumpur.png"): ["kuala lumpur", "Kuala lumpur", "Kuala Lumpur", "KUALA LUMPUR"], os.path.join(basedir, "images/lagos.png"): ["lagos", "Lagos", "LAGOS"], os.path.join(basedir, "images/lyon.png"): ["lyon", "Lyon", "LYON"], os.path.join(basedir, "images/warsaw.png"): ["warsaw", "Warsaw", "WARSAW"]}
  211. mister_c_dialog: int
  212. mister_c_result: int
  213. skyline_image: int
  214. ptimage = None
  215. mister_c_input = tk.Entry(root)
  216. mister_c_score = 0
  217. def mister_c_init():
  218. shuffle(images_list)
  219. bg_rect = cv.create_rectangle(0, 0, 1280, 720, fill="#7cf27c", outline="#7cf27c")
  220. draw_dialog_area()
  221. dialog_name = cv.create_text(640, 500, text="Mister C", font=("Helvetica", 16, "bold"), fill="#0b6b0b")
  222. mister_c_game()
  223. def mister_c_game():
  224. global mister_c_dialog, skyline_image, ptimage
  225. if mister_c_state == 0:
  226. mister_c_dialog = cv.create_text(640, 606, text="Halloooo, my name is Mister C !\n\
  227. In my game, you'll have to recognize a city from his skyline, and the colors on the flag of its country.\n\
  228. You will see 3 images, and you'll have to make 2 correct guesses if you want to continue.\n\
  229. You only have one chance per image, good luck !\n\
  230. Press SPACE to start", font=("Helvetica", 12), fill="#0b6b0b")
  231. if mister_c_state == 1:
  232. cv.itemconfig(mister_c_dialog, text="Which city do you think it is ?")
  233. ptimage = ImageTk.PhotoImage(file=images_list[0])
  234. skyline_image = cv.create_image(640, 242, image=ptimage, anchor=tk.CENTER)
  235. mister_c_input.place(x=640, y=632, anchor=tk.CENTER)
  236. elif mister_c_state == 2:
  237. cv.itemconfig(mister_c_dialog, text="Which city do you think it is ?")
  238. ptimage = ImageTk.PhotoImage(file=images_list[1])
  239. cv.itemconfigure(skyline_image, image=ptimage)
  240. elif mister_c_state == 3:
  241. cv.itemconfig(mister_c_dialog, text="Which city do you think it is ?")
  242. ptimage = ImageTk.PhotoImage(file=images_list[2])
  243. cv.itemconfigure(skyline_image, image=ptimage)
  244. elif mister_c_state == 4:
  245. cv.itemconfig(mister_c_dialog, text="Well played!\nPress SPACE to continue.")
  246. elif mister_c_state == 5:
  247. cv.itemconfig(mister_c_dialog, text="You have to work a little more, see you later !")
  248. root.after(5000, reset)
  249. def mister_c_verif():
  250. global mister_c_score, mister_c_result
  251. if mister_c_input.get() in mister_c_answers[images_list[mister_c_state - 1]]:
  252. mister_c_score += 1
  253. if mister_c_state == 1:
  254. mister_c_result = cv.create_text(640, 680, text="Correct!", font=("Helvetica", 12), fill="#0b6b0b")
  255. else:
  256. cv.itemconfig(mister_c_result, text="Correct!")
  257. return True
  258. else:
  259. if mister_c_state == 1:
  260. mister_c_result = cv.create_text(640, 680, text="Wrong!", font=("Helvetica", 12), fill="#0b6b0b")
  261. else:
  262. cv.itemconfig(mister_c_result, text="Wrong!")
  263. return False
  264. # Mister E game
  265. mister_e_state = 0
  266. mister_e_time = 0
  267. mister_e_time_count = 0
  268. mister_e_timer: int
  269. mask_images = []
  270. masks_list = []
  271. happy_mask = {}
  272. mister_e_dialog: int
  273. def mister_e_init():
  274. bg_rect = cv.create_rectangle(0, 0, 1280, 720, fill="#fda3ff", outline="#fda3ff")
  275. draw_dialog_area()
  276. dialog_name = cv.create_text(640, 500, text="Mister E", font=("Helvetica", 16, "bold"), fill="#730075")
  277. mister_e_game()
  278. def mister_e_game():
  279. global mister_e_dialog, mister_e_state, mister_e_time, mister_e_time_count, mister_e_timer
  280. if mister_e_state == 0:
  281. mister_e_dialog = cv.create_text(640, 606, text="Hello! I'm Mister E, nice to meet you!\n\
  282. In my game, you'll see some comedy masks, and you'll just have to find the happy one.\n\
  283. Good luck!\n\
  284. Press SPACE to start.", font=("Helvetica", 12), fill="#730075")
  285. elif mister_e_state == 1:
  286. spawn_masks()
  287. mister_e_state = 2
  288. mister_e_time = 15
  289. mister_e_timer = cv.create_text(1252, 700, text="15", font=("Helvetica", 16, "bold"), fill="#730075")
  290. mister_e_game()
  291. elif mister_e_state == 2:
  292. move_masks()
  293. mister_e_countdown()
  294. root.after(100, mister_e_game)
  295. elif mister_e_state == 3:
  296. mister_e_clear()
  297. cv.itemconfig(mister_e_dialog, text="Well done! But it was the easy level,\nPress SPACE to continue.")
  298. elif mister_e_state == 4:
  299. spawn_masks()
  300. mister_e_time = 20
  301. cv.itemconfig(mister_e_timer, text="20")
  302. mister_e_time_count = 0
  303. mister_e_state = 5
  304. mister_e_game()
  305. elif mister_e_state == 5:
  306. move_masks()
  307. mister_e_countdown()
  308. root.after(100, mister_e_game)
  309. elif mister_e_state == 6:
  310. mister_e_clear()
  311. cv.itemconfig(mister_e_dialog, text="Good job! You're ready to the next step,\nPress SPACE to continue.")
  312. elif mister_e_state == 7:
  313. spawn_masks()
  314. mister_e_time = 25
  315. cv.itemconfig(mister_e_timer, text="25")
  316. mister_e_time_count = 0
  317. mister_e_state = 8
  318. mister_e_game()
  319. elif mister_e_state == 8:
  320. move_masks()
  321. mister_e_countdown()
  322. root.after(100, mister_e_game)
  323. elif mister_e_state == 9:
  324. mister_e_clear()
  325. cv.itemconfig(mister_e_dialog, text="Well played! The next one is the last one, good luck!\nPress SPACE to continue.")
  326. elif mister_e_state == 10:
  327. spawn_masks()
  328. mister_e_time = 30
  329. cv.itemconfig(mister_e_timer, text="30")
  330. mister_e_time_count = 0
  331. mister_e_state = 11
  332. mister_e_game()
  333. elif mister_e_state == 11:
  334. move_masks()
  335. mister_e_countdown()
  336. root.after(100, mister_e_game)
  337. elif mister_e_state == 12:
  338. mister_e_clear()
  339. cv.itemconfig(mister_e_dialog, text="You did it!\nPress SPACE to continue.")
  340. elif mister_e_state == 13:
  341. mister_e_clear()
  342. cv.itemconfig(mister_e_dialog, text="Oh nooooo, the time is up!\nyou'll be luckier next time darling.")
  343. root.after(5000, reset)
  344. def spawn_masks():
  345. global masks_list, happy_mask, mask_images
  346. mask_images.append(ImageTk.PhotoImage(file=os.path.join(basedir, "images/happy.png")))
  347. happy_mask = {"id": cv.create_image(randint(0, 1280), randint(0, 500), image=mask_images[0], anchor=tk.CENTER), "velx": mask_vel_gen(), "vely": mask_vel_gen()}
  348. cv.tag_bind(happy_mask["id"], "<Button-1>", button1)
  349. for i in range(40 * mister_e_state // 3 + 1):
  350. mask_images.append(ImageTk.PhotoImage(file=choice([os.path.join(basedir, "images/sad.png"), os.path.join(basedir, "images/fastfood.png")])))
  351. masks_list.append({"id": cv.create_image(randint(0, 1280), randint(0, 500), image=mask_images[i + 1], anchor=tk.CENTER), "velx": mask_vel_gen(), "vely": mask_vel_gen()})
  352. def move_masks():
  353. global masks_list
  354. for mask in masks_list:
  355. cv.move(mask["id"], mask["velx"], mask["vely"])
  356. if cv.coords(mask["id"])[0] < 0 or 1280 < cv.coords(mask["id"])[0]:
  357. mask["velx"] = -mask["velx"]
  358. if cv.coords(mask["id"])[1] < 0 or 500 < cv.coords(mask["id"])[1]:
  359. mask["vely"] = -mask["vely"]
  360. cv.move(happy_mask["id"], happy_mask["velx"], happy_mask["vely"])
  361. if cv.coords(happy_mask["id"])[0] < 0 or 1280 < cv.coords(happy_mask["id"])[0]:
  362. happy_mask["velx"] = -happy_mask["velx"]
  363. if cv.coords(happy_mask["id"])[1] < 0 or 500 < cv.coords(happy_mask["id"])[1]:
  364. happy_mask["vely"] = -happy_mask["vely"]
  365. def mask_vel_gen():
  366. vel = randint(6, 12)
  367. sign = randint(0, 1)
  368. if sign == 1:
  369. vel = -vel
  370. return vel
  371. def mister_e_clear():
  372. global mask_images, masks_list, happy_mask
  373. for elt in masks_list:
  374. cv.delete(elt)
  375. mask_images = []
  376. masks_list = []
  377. happy_mask = {}
  378. def mister_e_countdown():
  379. global mister_e_time, mister_e_time_count, mister_e_timer, mister_e_state
  380. mister_e_time_count += 1
  381. if mister_e_time_count % 10 == 0:
  382. mister_e_time -= 1
  383. cv.itemconfig(mister_e_timer, text=str(mister_e_time))
  384. if mister_e_time == 0:
  385. mister_e_state = 13
  386. # Miss W game
  387. miss_w_state = 0
  388. miss_w_dialog: int
  389. notes_list = [[748, -68], [930, -118], [1112, -168], [566, -314], [384, -364], [202, -414], [748, -524], [566, -624], [384, -724], [930, -724], [384, -774], [930, -774], [384, -824], [930, -824], [566, -968], [748, -1084], [566, -1162], [384, -1212], [202, -1262], [748, -1424], [384, -1524], [1112, -1624], [202, -1758],\
  390. [748, -68 - 1808], [930, -118 - 1808], [1112, -168 - 1808], [566, -314 - 1808], [384, -364 - 1808], [202, -414 - 1808], [748, -524 - 1808], [566, -624 - 1808], [384, -724 - 1860], [930, -724 - 1860], [384, -774 - 1860], [930, -774 - 1860], [384, -824 - 1860], [930, -824 - 1860], [566, -968 - 1860], [748, -1084 - 1860], [566, -1162 - 1880], [384, -1212 - 1860], [202, -1262 - 1860], [748, -1424 - 1860], [384, -1524 - 1860], [1112, -1624 - 1860], [202, -1758 - 1860],\
  391. [748, -68 - 3680], [930, -118 - 3680], [1112, -168 - 3680], [566, -314 - 3680], [384, -364 - 3680], [202, -414 - 3680], [748, -524 - 3700], [566, -624 - 3700], [384, -724 - 3700], [930, -724 - 3700], [384, -774 - 3700], [930, -774 - 3700], [384, -824 - 3700], [930, -824 - 3700], [566, -968 - 3700], [748, -1084 - 3700], [566, -1162 - 3700], [384, -1212 - 3700], [202, -1262 - 3700], [748, -1424 - 3700], [384, -1524 - 3700], [1112, -1624 - 3700], [202, -1758 - 3700],\
  392. [748, -68 - 5500], [930, -118 - 5500], [1112, -168 - 5500], [566, -314 - 5500], [384, -364 - 5500], [202, -414 - 5500], [748, -524 - 5500], [566, -624 - 5500], [384, -724 - 5500], [930, -724 - 5500], [384, -774 - 5500], [930, -774 - 5500], [384, -824 - 5500], [930, -824 - 5500], [566, -968 - 5500], [748, -1084 - 5500], [566, -1162 - 5500], [384, -1212 - 5500], [202, -1262 - 5500], [748, -1424 - 5500], [384, -1524 - 5500], [1112, -1624 - 5500], [202, -1758 - 5500]]
  393. notes_id = []
  394. f_list = [[i, 0] for i in range(len(notes_list)) if notes_list[i][0] == 202]
  395. g_list = [[i, 0] for i in range(len(notes_list)) if notes_list[i][0] == 384]
  396. h_list = [[i, 0] for i in range(len(notes_list)) if notes_list[i][0] == 566]
  397. j_list = [[i, 0] for i in range(len(notes_list)) if notes_list[i][0] == 748]
  398. k_list = [[i, 0] for i in range(len(notes_list)) if notes_list[i][0] == 930]
  399. l_list = [[i, 0] for i in range(len(notes_list)) if notes_list[i][0] == 1112]
  400. miss_w_score = 0
  401. miss_w_score_text = 0
  402. def miss_w_init():
  403. bg_rect = cv.create_rectangle(0, 0, 1280, 720, fill="#c892e0", outline="#c892e0")
  404. draw_dialog_area()
  405. dialog_name = cv.create_text(640, 500, text="Miss W", font=("Helvetica", 16, "bold"), fill="#481a5b")
  406. miss_w_game()
  407. def miss_w_game():
  408. global miss_w_state, miss_w_dialog, miss_w_score_text
  409. if miss_w_state == 0:
  410. miss_w_dialog = cv.create_text(640, 606, text="Helloooo, I'm Miss W!\n\
  411. My game is a rythm game, good luck!\n\
  412. Press SPACE to start.", font=("Helvetica", 12), fill="#481a5b")
  413. elif miss_w_state == 1:
  414. miss_w_draw_ui()
  415. spawn_notes()
  416. mixer.init()
  417. mixer.music.load(os.path.join(basedir, "audio/scottish.mp3"))
  418. mixer.music.set_volume(1.0)
  419. mixer.music.play()
  420. miss_w_state = 2
  421. miss_w_game()
  422. miss_w_score_text = cv.create_text(1252, 700, text="0", font=("Helvetica", 16, "bold"), fill="#481a5b")
  423. elif miss_w_state == 2:
  424. if cv.coords(notes_id[-1])[1] < 500:
  425. move_notes()
  426. root.after(20, miss_w_game)
  427. else:
  428. if miss_w_score < 840:
  429. miss_w_state = 3
  430. miss_w_game()
  431. else:
  432. miss_w_state = 4
  433. miss_w_game()
  434. elif miss_w_state == 3:
  435. cv.itemconfig(miss_w_dialog, text="You need more training, come back later !")
  436. root.after(5000, reset)
  437. elif miss_w_state == 4:
  438. cv.itemconfig(miss_w_dialog, text="Gg! That was a beautiful scottish! :D\nPress SPACE to continue")
  439. def miss_w_draw_ui():
  440. cv.create_rectangle(0, 438, 1280, 442, fill="#ffffff", outline="#ffffff")
  441. cv.create_text(182, 460, text="F", font=("Helvetica", 16, "bold"), fill="#ffffff")
  442. cv.create_text(364, 460, text="G", font=("Helvetica", 16, "bold"), fill="#ffffff")
  443. cv.create_text(546, 460, text="H", font=("Helvetica", 16, "bold"), fill="#ffffff")
  444. cv.create_text(728, 460, text="J", font=("Helvetica", 16, "bold"), fill="#ffffff")
  445. cv.create_text(910, 460, text="K", font=("Helvetica", 16, "bold"), fill="#ffffff")
  446. cv.create_text(1092, 460, text="L", font=("Helvetica", 16, "bold"), fill="#ffffff")
  447. def spawn_notes():
  448. global notes_id
  449. for note in notes_list:
  450. notes_id.append(cv.create_text(note[0], note[1], text="♩", font=("Helvetica", 64, "bold"), fill="#ffffff"))
  451. def move_notes():
  452. global notes_id
  453. for i in range(len(notes_id)):
  454. if cv.coords(notes_id[i])[1] < 500:
  455. cv.move(notes_id[i], 0, 4)
  456. if cv.coords(notes_id[i])[1] >= 500:
  457. cv.move(notes_id[i], 0, 500)
  458. # Handle the pressed keys
  459. def space(_):
  460. global game_number, miss_n_state, ingredients_height, mister_c_state, mister_e_state, miss_w_state
  461. if game_number < len(games_list):
  462. if games_list[game_number] == "N":
  463. if miss_n_state == 0:
  464. miss_n_state = 1
  465. miss_n_game()
  466. elif miss_n_state == 1:
  467. miss_n_state = 2
  468. ingredients_height -= round(flour_qtt / 3)
  469. cv.create_rectangle(1141, 359, 1239, ingredients_height, fill="#fff4de", outline="#fff4de")
  470. elif miss_n_state == 2:
  471. miss_n_state = 3
  472. cv.create_rectangle(1141, ingredients_height, 1239, ingredients_height - round(sugar_qtt / 3), fill="#ffb34f", outline="#ffb34f")
  473. ingredients_height -= round(sugar_qtt / 3)
  474. elif miss_n_state == 3:
  475. miss_n_state = 4
  476. cv.create_line(1141, ingredients_height, 1239, ingredients_height, fill="#ffffff")
  477. cv.create_line(1180, ingredients_height, 1200, ingredients_height, fill="#ffcc00")
  478. ingredients_height -= 1
  479. elif miss_n_state == 4:
  480. miss_n_state = 5
  481. cv.create_rectangle(1141, ingredients_height, 1239, ingredients_height - round(milk_qtt / 3), fill="#ffffff", outline="#ffffff")
  482. miss_n_end()
  483. elif miss_n_state == 6:
  484. game_number += 1
  485. next_game()
  486. elif games_list[game_number] == "C":
  487. if mister_c_state == 0:
  488. mister_c_state = 1
  489. mister_c_game()
  490. elif mister_c_state == 4:
  491. game_number += 1
  492. next_game()
  493. elif games_list[game_number] == "E":
  494. if mister_e_state in [0, 3, 6, 9]:
  495. mister_e_state += 1
  496. mister_e_game()
  497. elif mister_e_state == 12:
  498. game_number += 1
  499. next_game()
  500. elif games_list[game_number] == "W":
  501. if miss_w_state == 0:
  502. miss_w_state = 1
  503. miss_w_game()
  504. elif miss_w_state == 4:
  505. game_number += 1
  506. next_game()
  507. elif game_number == 4:
  508. if not ended:
  509. start()
  510. else:
  511. root.destroy()
  512. def enter(_):
  513. global mister_c_state, mister_c_score
  514. if game_number < len(games_list):
  515. if games_list[game_number] == "C":
  516. if mister_c_state == 1:
  517. mister_c_verif()
  518. mister_c_input.delete(0, tk.END)
  519. mister_c_state = 2
  520. mister_c_game()
  521. elif mister_c_state == 2:
  522. mister_c_verif()
  523. mister_c_input.delete(0, tk.END)
  524. if mister_c_score == 2:
  525. mister_c_state = 4
  526. mister_c_input.destroy()
  527. else:
  528. mister_c_state = 3
  529. mister_c_game()
  530. elif mister_c_state == 3:
  531. if mister_c_verif():
  532. mister_c_state = 4
  533. mister_c_game()
  534. else:
  535. mister_c_state = 5
  536. mister_c_game()
  537. mister_c_input.destroy()
  538. def button1(_):
  539. global mister_e_state
  540. if game_number < len(games_list):
  541. if games_list[game_number] == "E":
  542. if mister_e_state in [2, 5, 8, 11]:
  543. mister_e_state += 1
  544. def f(_):
  545. global miss_w_score, f_list
  546. if miss_w_state == 2:
  547. for note in f_list:
  548. if note[1] == 0 and 408 <= cv.coords(notes_id[note[0]])[1] <= 472:
  549. note[1] = 1
  550. miss_w_score += 10
  551. cv.itemconfig(miss_w_score_text, text=str(miss_w_score))
  552. cv.itemconfig(notes_id[note[0]], fill="#a9e092")
  553. def g(_):
  554. global miss_w_score, g_list
  555. if miss_w_state == 2:
  556. for note in g_list:
  557. if note[1] == 0 and 408 <= cv.coords(notes_id[note[0]])[1] <= 472:
  558. note[1] = 1
  559. miss_w_score += 10
  560. cv.itemconfig(miss_w_score_text, text=str(miss_w_score))
  561. cv.itemconfig(notes_id[note[0]], fill="#a9e092")
  562. def h(_):
  563. global miss_w_score, h_list
  564. if miss_w_state == 2:
  565. for note in h_list:
  566. if note[1] == 0 and 408 <= cv.coords(notes_id[note[0]])[1] <= 472:
  567. note[1] = 1
  568. miss_w_score += 10
  569. cv.itemconfig(miss_w_score_text, text=str(miss_w_score))
  570. cv.itemconfig(notes_id[note[0]], fill="#a9e092")
  571. def j(_):
  572. global miss_w_score, j_list
  573. if miss_w_state == 2:
  574. for note in j_list:
  575. if note[1] == 0 and 408 <= cv.coords(notes_id[note[0]])[1] <= 472:
  576. note[1] = 1
  577. miss_w_score += 10
  578. cv.itemconfig(miss_w_score_text, text=str(miss_w_score))
  579. cv.itemconfig(notes_id[note[0]], fill="#a9e092")
  580. def k(_):
  581. global miss_w_score, k_list
  582. if miss_w_state == 2:
  583. for note in k_list:
  584. if note[1] == 0 and 408 <= cv.coords(notes_id[note[0]])[1] <= 472:
  585. note[1] = 1
  586. miss_w_score += 10
  587. cv.itemconfig(miss_w_score_text, text=str(miss_w_score))
  588. cv.itemconfig(notes_id[note[0]], fill="#a9e092")
  589. def l(_):
  590. global miss_w_score, l_list
  591. if miss_w_state == 2:
  592. for note in l_list:
  593. if note[1] == 0 and 408 <= cv.coords(notes_id[note[0]])[1] <= 472:
  594. note[1] = 1
  595. miss_w_score += 10
  596. cv.itemconfig(miss_w_score_text, text=str(miss_w_score))
  597. cv.itemconfig(notes_id[note[0]], fill="#a9e092")
  598. root.bind("<space>", space)
  599. root.bind("f", f)
  600. root.bind("g", g)
  601. root.bind("h", h)
  602. root.bind("j", j)
  603. root.bind("k", k)
  604. root.bind("l", l)
  605. mister_c_input.bind("<Return>", enter)
  606. menu()
  607. root.mainloop()