Added V1 of the game.

This commit is contained in:
David Leutgeb 2023-08-15 14:28:56 +02:00
parent 12349c4e21
commit 285c033447
1 changed files with 81 additions and 0 deletions

81
ConcentrationGameV1.py Normal file
View File

@ -0,0 +1,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()