1 from __future__
import annotations
2 from threading
import Lock, Thread
3 from typing
import Optional
7 WEISS = (255, 255, 255)
12 MAGENTA = (255,0, 255)
14 HELLGELB = (255, 255, 128)
15 HELLGRUEN = (128, 255, 128)
18 GRAU = (128, 128, 128)
24 _instanz: Optional[Singleton] =
None
70 kopie_von_beobachterliste = self.
beobachter.copy()
71 for beobachter
in kopie_von_beobachterliste:
72 beobachter.AktionAusfuehren()
80 kopie_von_beobachterliste = self.
beobachter.copy()
81 for beobachter
in kopie_von_beobachterliste:
82 beobachter.MausGeklickt(button, pos)
87 kopie_von_beobachterliste = self.
beobachter.copy()
88 for beobachter
in kopie_von_beobachterliste:
89 beobachter.TasteGedrueckt(taste)
110 self.
fenster = pygame.display.set_mode(groesse)
111 pygame.display.set_caption(
"Zeichenfenster")
114 pygame.event.set_blocked(pygame.ACTIVEEVENT)
115 pygame.event.set_blocked(pygame.MOUSEMOTION)
116 pygame.event.set_blocked(pygame.JOYAXISMOTION)
117 pygame.event.set_blocked(pygame.JOYBALLMOTION)
118 pygame.event.set_blocked(pygame.JOYHATMOTION)
119 pygame.event.set_blocked(pygame.JOYBUTTONUP)
120 pygame.event.set_blocked(pygame.JOYBUTTONDOWN)
121 pygame.event.set_blocked(pygame.VIDEORESIZE)
122 pygame.event.set_blocked(pygame.VIDEOEXPOSE)
123 pygame.event.set_blocked(pygame.USEREVENT)
126 clock=pygame.time.Clock()
142 for event
in pygame.event.get():
145 if event.type==pygame.QUIT:
149 elif event.type == pygame.MOUSEBUTTONUP:
155 elif event.type == pygame.MOUSEBUTTONDOWN:
156 pos = pygame.mouse.get_pos()
161 elif event.type == pygame.KEYUP:
173 self.
fenster.fill((230,230,230))
183 pygame.display.flip()
215 index_figur = liste.index(figur)
219 for i
in range(index_figur-1):
230 index_figur = liste.index(figur)
231 if index_figur < len(liste)-1:
234 for i
in range(index_figur):
252 def __init__(self, location, fenster, zeichenfenster):
254 self.
bg = (255,255,255)
260 self.
font = pygame.font.SysFont(
"Arial", 16)
278 pos = pygame.mouse.get_pos()
279 if self.
rect.collidepoint(pos):
280 self.
bg = (200,200,200)
284 if self.
txt==
"Start":
294 pos = pygame.mouse.get_pos()
295 if self.
rect.collidepoint(pos):
301 def __init__(self, name, val, mini, maxi, xpos, ypos, fenster, zeichenfenster):
307 self.
surf = pygame.surface.Surface((100, 50))
310 self.
font = pygame.font.SysFont(
"Arial", 12)
316 self.
surf.fill((100, 100, 100))
317 pygame.draw.rect(self.
surf, GRAU, [0, 0, 100, 50], 3)
318 pygame.draw.rect(self.
surf, ORANGE, [10, 10, 80, 10], 0)
319 pygame.draw.rect(self.
surf, WEISS, [10, 30, 80, 5], 0)
327 pygame.draw.circle(self.
button_surf, SCHWARZ, (10, 10), 6, 0)
328 pygame.draw.circle(self.
button_surf, ORANGE, (10, 10), 4, 0)
333 surf = self.
surf.copy()
345 self.
val = (pygame.mouse.get_pos()[0] - self.
xpos - 10) / 80 * (self.
maxi - self.
mini) + self.
mini
368 def __init__(self, farbe, x, y, breite, hoehe, winkel, sichtbar):
395 self.
image.fill((255,255,255))
396 self.
image.set_colorkey((255,255,255))
401 self.
rect.topleft = (self.
x,self.
y)
406 old_center = self.
rect.center
456 self.
winkel = winkel % 360
473 if wert
in (
"weiss",
"weiss",
"white"):
475 elif wert
in (
"red",
"rot"):
477 elif wert
in (
"gruen",
"grün",
"green"):
479 elif wert
in (
"blue",
"blau"):
481 elif wert
in (
"yellow",
"gelb"):
483 elif wert
in (
"magenta",
"pink"):
487 elif wert ==
"hellgelb":
489 elif wert
in (
"hellgruen",
"hellgrün"):
491 elif wert ==
"orange":
493 elif wert
in (
"braun",
"brown"):
495 elif wert
in (
"grau",
"grey"):
497 elif wert
in (
"black",
"schwarz"):
499 elif type(wert)
is tuple:
500 if (0,0,0) <= wert <= (255,255,255):
525 return self.
farbe == farbe
542 def __init__(self, farbe, x, y, breite, hoehe, winkel, sichtbar):
543 super().
__init__(farbe, x, y, breite, hoehe, winkel,sichtbar)
565 def __init__(self, farbe, x, y, radius, winkel, sichtbar):
566 super().
__init__(farbe, x, y, radius* 2, radius * 2, winkel, sichtbar)
589 def __init__(self, farbe, x, y, breite, hoehe, winkel, sichtbar):
590 super().
__init__(farbe, x, y, breite, hoehe, winkel, sichtbar)
612 def __init__(self, farbe, x, y, textgroesse, winkel, sichtbar):
616 super().
__init__(farbe, x, y, 0, 0, winkel,sichtbar)
654 font = pygame.font.SysFont(
"Arial", self.
groesse)
691 def __init__(self, x, y, groesse, winkel, sichtbar):
699 super().
__init__((255,255,255), x, y, groesse, groesse, winkel, sichtbar)
715 neuX = self.
xD + math.cos(self.
winkel*math.pi/180)*länge
716 neuY = self.
yD - math.sin(self.
winkel*math.pi/180)*länge
749 self.
rect.center = (self.
x,self.
y)
757 sprites_list.remove(self)
758 for figur
in sprites_list:
759 if not (isinstance(figur, TextIntern)):
760 if not(pygame.sprite.collide_mask(self, figur)
is None):
770 sprites_list.remove(self)
771 for figur
in sprites_list:
772 if not (isinstance(figur, TextIntern)):
773 if not(pygame.sprite.collide_mask(self, figur)
is None):
774 if figur.EnthältFarbe(self.
FarbeGeben(farbe)):
782 if (isinstance(objekt, TextIntern)):
784 return not (pygame.sprite.collide_mask(self, objekt.symbol)
is None)
790 self.
image.fill(GELB)
792 self.
figurenliste.append(
"pygame.draw.polygon(self.image, GELB, [(0, 0),(self.breite, self.hoehe/2),(0, self.hoehe)])")
793 self.
figurenliste.append(
"pygame.draw.ellipse(self.image, BLAU, (20, self.hoehe/2 -4,8,8))")
809 self.
image.fill(WEISS)
814 string =
"pygame.draw.rect(self.image,"+ str(farbeCodiert)+
", ("+str(x)+
","+str(y)+
","+str(breite)+
", "+str(hoehe)+
"))"
830 self.fenster.fill(WEISS)
834 string =
"pygame.draw.ellipse(self.image,"+ str(farbeCodiert)+
", ("+str(x)+
","+str(y)+
","+str(breite)+
", "+str(hoehe)+
"))"
852 self.fenster.fill(WEISS)
856 string =
"pygame.draw.polygon(self.image,"+ str(farbeCodiert)+
", [("+str(x1)+
","+str(y1)+
"),("+str(x2)+
", "+str(y2)+
"),("+str(x3)+
","+str(y3)+
")])"
867 return self.
FarbeGeben(farbe)
in self.Farbliste
876 def __init__(self, farbe, x, y, groesse, winkel, sichtbar):
890 super().
__init__(farbe, x, y, 60, 25, winkel, sichtbar)
905 neuX = self.
xD + math.cos(self.
winkel*math.pi/180)*länge
906 neuY = self.
yD - math.sin(self.
winkel*math.pi/180)*länge
945 sprites_list.remove(self)
946 for figur
in sprites_list:
947 if not (isinstance(figur, TextIntern)):
948 if not(pygame.sprite.collide_mask(self.
schwanzspitze, figur)
is None):
956 if 22.5 <= self.
winkel < 67.5:
959 elif 67.5 <= self.
winkel < 112.5:
962 elif 112.5 <= self.
winkel < 157.5:
965 elif 157.5 <= self.
winkel < 202.5:
968 elif 202.5 <= self.
winkel < 247.5:
971 elif 247.5 <= self.
winkel < 292.5:
974 elif 292.5 <= self.
winkel < 337.5:
986 if(wert1[i]!=wert2[i]):
994 if (isinstance(objekt, TextIntern)):
996 return not (pygame.sprite.collide_mask(self.
schwanzspitze, objekt.symbol)
is None)
1002 enthältFarbe =
False
1013 pygame.draw.ellipse(self.
image, GRUEN, (50,7,10, 12))
1015 pygame.draw.ellipse(self.
image, GRUEN, (36,0,8, 25))
1016 pygame.draw.ellipse(self.
image, GRUEN, (44,0,8, 25))
1018 pygame.draw.ellipse(self.
image, self.
farbe, (55,9,3, 2))
1019 pygame.draw.ellipse(self.
image, self.
farbe, (55,14,3, 2))
1021 pygame.draw.ellipse(self.
image, self.
farbe, (30,10,10, 5))
1023 pygame.draw.ellipse(self.
image, BRAUN, (32,2,24, 21))
1034 self.
rect.center = (self.
x,self.
y)
1057 pygame.sprite.Sprite.__init__(self)
1059 self.
image.fill(ROT)
1066 self.
rect.topleft = (x,y)
1070 self.
image.fill((255,255,255))
1071 self.
image.set_colorkey((255,255,255))
1073 self.
rect.center = (x,y)
1074 pygame.draw.rect(self.
image, farbe, (0,0,1, 1))