a
This commit is contained in:
+5
-25
@@ -22,7 +22,11 @@ class MeinSpiel:
|
|||||||
|
|
||||||
def tasteGedrueckt(self, taste):
|
def tasteGedrueckt(self, taste):
|
||||||
print("taste gedrückt")
|
print("taste gedrückt")
|
||||||
|
|
||||||
|
def feldAngeklickt(self, x, y):
|
||||||
|
print("Feld angeklickt:", x, y)
|
||||||
|
|
||||||
|
self.spielfeld[x][y] = 2
|
||||||
|
|
||||||
# Von 0 bis 10 in Schritten von 2
|
# Von 0 bis 10 in Schritten von 2
|
||||||
for i in range(0, 11, 5):
|
for i in range(0, 11, 5):
|
||||||
@@ -33,28 +37,4 @@ class MeinSpiel:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
from pynput import mouse
|
|
||||||
|
|
||||||
# Callback-Funktion bei Mausklick
|
|
||||||
def on_click(x, y, button, pressed):
|
|
||||||
if pressed:
|
|
||||||
print(f"Mausklick gedrückt bei Position ({x}, {y}) mit Taste {button}")
|
|
||||||
else:
|
|
||||||
print(f"Mausklick losgelassen bei Position ({x}, {y}) mit Taste {button}")
|
|
||||||
|
|
||||||
# Callback-Funktion bei Mausbewegung
|
|
||||||
def on_move(x, y):
|
|
||||||
print(f"Maus bewegt zu Position ({x}, {y})")
|
|
||||||
|
|
||||||
# Callback-Funktion beim Mausrad-Scrollen
|
|
||||||
def on_scroll(x, y, dx, dy):
|
|
||||||
print(f"Mausrad bewegt bei Position ({x}, {y}) – Delta: ({dx}, {dy})")
|
|
||||||
|
|
||||||
# Listener starten
|
|
||||||
with mouse.Listener(
|
|
||||||
on_click=on_click,
|
|
||||||
on_move=on_move,
|
|
||||||
on_scroll=on_scroll
|
|
||||||
) as listener:
|
|
||||||
print("Maus-Event-Listener gestartet. Beenden mit STRG+C.")
|
|
||||||
listener.join()
|
|
||||||
@@ -35,6 +35,14 @@ while True:
|
|||||||
if event.type==QUIT or (event.type==KEYDOWN and event.key==K_ESCAPE):
|
if event.type==QUIT or (event.type==KEYDOWN and event.key==K_ESCAPE):
|
||||||
pygame.quit()
|
pygame.quit()
|
||||||
|
|
||||||
|
# MAUS
|
||||||
|
if event.type == MOUSEBUTTONDOWN:
|
||||||
|
mausX, mausY = pygame.mouse.get_pos()
|
||||||
|
feldX = mausX // Pixel
|
||||||
|
feldY = mausY // Pixel
|
||||||
|
meinSpiel.feldAngeklickt(feldX, feldY)
|
||||||
|
|
||||||
|
|
||||||
# Spiellogik
|
# Spiellogik
|
||||||
if event.type==KEYDOWN:
|
if event.type==KEYDOWN:
|
||||||
meinSpiel.tasteGedrueckt(event.key)
|
meinSpiel.tasteGedrueckt(event.key)
|
||||||
|
|||||||
Reference in New Issue
Block a user