summaryrefslogtreecommitdiff
path: root/ConcentrationGameV1.py
blob: dd8a91ef1f4950dc142a6f8d8d4a7ecce76a3b3b (plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import tkinter as tk
from tkinter import messagebox
import random
import time

class ShapeGame:
	def __init__(self):
		self.root = tk.Tk()
		self.root.title("Konzentration v1")

		self.shapes = ["Rechteck", "Kreis", "Dreieck"]
		self.display_shapes = ["Rechteck", "Kreis", "Dreieck", "Fünfeck", "Sechseck", "Stern"]
		self.selected_shape = ""
		self.displayed_shape = ""
		self.correct_presses = 0
		self.incorrect_presses = 0
		self.count = 0

		self.canvas = tk.Canvas(self.root, bg="white", width=500, height=400)
		self.canvas.pack(pady=20)

		self.selection_buttons = []
		for shape in self.shapes:
			btn = tk.Button(self.root, text=shape.capitalize(), command=lambda s=shape: self.Sternt_game(s))
			btn.pack(pady=10)
			self.selection_buttons.append(btn)

		self.root.bind("<Return>", self.check_shape)

	def Sternt_game(self, shape):
		for btn in self.selection_buttons:
			btn.pack_forget()

		self.selected_shape = shape
		self.show_random_shape()

	def show_random_shape(self):
		self.canvas.delete("all")
	
		if self.count < 30:
			while True:
				next_shape = random.choice(self.display_shapes)
				if next_shape != self.displayed_shape:
					break
	
			self.displayed_shape = next_shape
	
			if self.displayed_shape == "Rechteck":
				self.canvas.create_rectangle(150, 100, 350, 300, fill="blue")
			elif self.displayed_shape == "Kreis":
				self.canvas.create_oval(150, 100, 350, 300, fill="green")
			elif self.displayed_shape == "Dreieck":
				self.canvas.create_polygon(250, 100, 150, 300, 350, 300, fill="red")
			elif self.displayed_shape == "Fünfeck":
				self.canvas.create_polygon(250, 100, 150, 175, 200, 300, 300, 300, 350, 175, fill="yellow")
			elif self.displayed_shape == "Sechseck":
				self.canvas.create_polygon(250, 100, 150, 150, 150, 250, 250, 300, 350, 250, 350, 150, fill="purple")
			elif self.displayed_shape == "Stern":
				self.canvas.create_polygon(250, 100, 275, 200, 375, 200, 300, 250, 325, 350, 250, 275, 175, 350, 200, 250, 125, 200, 225, 200, fill="orange")
	
			self.count += 1
			self.root.after(3000, self.show_random_shape)
		else:
			self.end_game()



	def check_shape(self, event):
		if self.displayed_shape == self.selected_shape:
			self.correct_presses += 1
		else:
			self.incorrect_presses += 1

	def end_game(self):
		result = f"Richtig ausgewählt: {self.correct_presses}\nFalsch ausgewählt: {self.incorrect_presses}"
		messagebox.showinfo("Ergebnisse", result)
		self.root.quit()

if __name__ == "__main__":
	game = ShapeGame()
	game.root.mainloop()