Mini mensch ärgere dich nicht 2.0
SpielfigurNeu3.py — Python Source, 10 KB (11143 bytes)
Dateiinhalt
from visual import * from random import choice #scene.stereo = "redblue" #scene.stereodepth=2 from netzwerk import * class Br(frame): def __init__(self,farbe=color.cyan,stoff=materials.wood,x=0,y=0,z=0): frame.__init__(self) self.stein=box(frame=self,color=farbe,material=stoff,length=1,height=0.25,width=1,pos=(x,y,z)) class Ri(frame): def __init__(self, farbe=color.blue,x=0,z=0): frame.__init__(self) self.Ringe=ring(frame=self,pos=(x,0.2,z),radius=0.45,axis=(0,1,0),thickness=0.05,color=farbe,material=materials.plastic) class Sp(Teilnehmer): def __init__(self): Teilnehmer.__init__(self,12345) self.R1=Ri(x=-2,z=-2) self.R2=Ri(x=-3,z=-3) self.R3=Ri(x=-3,z=-1) self.R4=Ri(x=-2,z=0) self.R5=Ri(x=-1,z=0) self.R6=Ri(x=0,z=-2,farbe=color.red) self.R7=Ri(x=0,z=-1,farbe=color.red) self.R8=Ri(x=1,z=-3,farbe=color.red) self.R9=Ri(x=3,z=-3,farbe=color.red) self.R10=Ri(x=2,z=-2,farbe=color.red) self.R11=Ri(x=1,z=0,farbe=color.orange) self.R12=Ri(x=2,z=0,farbe=color.orange) self.R13=Ri(x=3,z=1,farbe=color.orange) self.R14=Ri(x=3,z=3,farbe=color.orange) self.R15=Ri(x=2,z=2,farbe=color.orange) self.R16=Ri(x=0,z=1,farbe=color.yellow) self.R17=Ri(x=0,z=2,farbe=color.yellow) self.R18=Ri(x=-1,z=3,farbe=color.yellow) self.R19=Ri(x=-3,z=3,farbe=color.yellow) self.R20=Ri(x=-2,z=2,farbe=color.yellow) self.b1=Br(x=-4,z=-4) self.b2=Br(x=-3,z=-4) self.b3=Br(x=-2,z=-4) self.b4=Br(x=-1,z=-4) self.b5=Br(x=0,z=-4) self.b6=Br(x=1,z=-4) self.b7=Br(x=2,z=-4) self.b8=Br(x=3,z=-4) self.b9=Br(x=4,z=-4) self.b10=Br(x=-4,z=-3) self.b11=Br(x=-3,z=-3) self.b12=Br(x=-2,z=-3,) self.b13=Br(x=-1,z=-3,farbe=color.black,stoff=materials.plastic) self.b14=Br(x=0,z=-3,farbe=color.white,stoff=materials.plastic) self.b15=Br(x=1,z=-3,farbe=color.black,stoff=materials.plastic) self.b16=Br(x=2,z=-3) self.b17=Br(x=3,z=-3) self.b18=Br(x=4,z=-3) self.b19=Br(x=-4,z=-2) self.b20=Br(x=-3,z=-2) self.b21=Br(x=-2,z=-2) self.b22=Br(x=-1,z=-2,farbe=color.white,stoff=materials.plastic) self.b23=Br(x=0,z=-2) self.b24=Br(x=1,z=-2,farbe=color.white,stoff=materials.plastic) self.b25=Br(x=2,z=-2) self.b26=Br(x=3,z=-2) self.b27=Br(x=4,z=-2) self.b28=Br(x=-4,z=-1) self.b29=Br(x=-3,z=-1,farbe=color.black,stoff=materials.plastic) self.b30=Br(x=-2,z=-1,farbe=color.white,stoff=materials.plastic) self.b31=Br(x=-1,z=-1,farbe=color.black,stoff=materials.plastic) self.b32=Br(x=0,z=-1) self.b33=Br(x=1,z=-1,farbe=color.black,stoff=materials.plastic) self.b34=Br(x=2,z=-1,farbe=color.white,stoff=materials.plastic) self.b35=Br(x=3,z=-1,farbe=color.black,stoff=materials.plastic) self.b36=Br(x=4,z=-1) self.b37=Br(x=-4,z=0) self.b38=Br(x=-3,z=0,farbe=color.white,stoff=materials.plastic) self.b39=Br(x=-2,z=0) self.b40=Br(x=-1,z=0) self.b41=Br(x=0,z=0) self.b42=Br(x=1,z=0) self.b43=Br(x=2,z=0) self.b44=Br(x=3,z=0,farbe=color.white,stoff=materials.plastic) self.b45=Br(x=4,z=0) self.b46=Br(x=-4,z=1) self.b47=Br(x=-3,z=1,farbe=color.black,stoff=materials.plastic) self.b48=Br(x=-2,z=1,farbe=color.white,stoff=materials.plastic) self.b49=Br(x=-1,z=1,farbe=color.black,stoff=materials.plastic) self.b50=Br(x=0,z=1) self.b51=Br(x=1,z=1,farbe=color.black,stoff=materials.plastic) self.b52=Br(x=2,z=1,farbe=color.white,stoff=materials.plastic) self.b53=Br(x=3,z=1,farbe=color.black,stoff=materials.plastic) self.b54=Br(x=4,z=1) self.b55=Br(x=-4,z=2) self.b56=Br(x=-3,z=2) self.b57=Br(x=-2,z=2) self.b58=Br(x=-1,z=2,farbe=color.white,stoff=materials.plastic) self.b59=Br(x=0,z=2) self.b60=Br(x=1,z=2,farbe=color.white,stoff=materials.plastic) self.b61=Br(x=2,z=2) self.b62=Br(x=3,z=2) self.b63=Br(x=4,z=2) self.b64=Br(x=-4,z=3) self.b65=Br(x=-3,z=3) self.b66=Br(x=-2,z=3) self.b67=Br(x=-1,z=3,farbe=color.black,stoff=materials.plastic) self.b68=Br(x=0,z=3,farbe=color.white,stoff=materials.plastic) self.b69=Br(x=1,z=3,farbe=color.black,stoff=materials.plastic) self.b70=Br(x=2,z=3) self.b71=Br(x=3,z=3) self.b72=Br(x=4,z=3) self.b73=Br(x=-4,z=4) self.b74=Br(x=-3,z=4) self.b75=Br(x=-2,z=4) self.b76=Br(x=-1,z=4) self.b77=Br(x=0,z=4) self.b78=Br(x=1,z=4) self.b79=Br(x=2,z=4) self.b80=Br(x=3,z=4) self.b81=Br(x=4,z=4) self.Wuerfel=box(pos=(0,1.15,0),color=color.magenta) self.r1 = Spielfigur(farbe1 = color.red, farbe2 = color.green,pos = (3,0.15,-3)) self.r2 = Spielfigur(farbe1 = color.red, farbe2 = color.green, pos = (2,0.15,-2)) self.b1 = Spielfigur(farbe1 = color.blue, farbe2 = color.magenta, pos = (-2,0.15,-2)) self.b2 = Spielfigur(farbe1 = color.blue, farbe2 = color.magenta, pos = (-3,0.15,-3)) self.y1 = Spielfigur(farbe1 = color.yellow, farbe2 = color.black, pos = (-2,0.15,2)) self.y2 = Spielfigur(farbe1 = color.yellow, farbe2 = color.black, pos = (-3,0.15,3)) self.o1 = Spielfigur(farbe1 = color.orange, farbe2 = color.blue, pos = (2,0.15,2)) self.o2 = Spielfigur(farbe1 = color.orange, farbe2 = color.blue, pos = (3,0.15,3)) self.kugely = sphere( color = color.yellow, radius = 0.25, pos = (-4,0.15,4)) self.kugelb = sphere( color = color.blue, radius = 0.25, pos = (-4,0.15,-4)) self.kugelr = sphere( color = color.red, radius = 0.25, pos = (4,0.15,-4)) self.kugelo = sphere( color = color.orange, radius = 0.25, pos = (4,0.15,4)) self.figurenliste=[self.r1,self.r2,self.b1,self.b2,self.y1,self.y2,self.o1,self.o2] self.felderliste=[self.b71,self.b69,self.b68,self.b67,self.b65,self.b61,self.b60,self.b59,self.b58,self.b57,self.b53,self.b52,self.b51,self.b50,self.b49,self.b48,self.b47,self.b44,self.b43,self.b42,self.b40,self.b39,self.b38,self.b35,self.b34,self.b33,self.b32,self.b31,self.b30,self.b29,self.b25,self.b24,self.b23,self.b22,self.b21,self.b17,self.b15,self.b14,self.b13,self.b11] self.w=wuerfeln() def figur_positionieren(self,wer,wo): for z in range(len(self.figurenliste) ): if z==wer: break for p in range(len(self.felderliste)): if p==wo: break self.figurenliste[z].pos = self.felderliste[p].stein.pos +(0,0.15,0) def wuerfelzahl_anzeigen(self,Augenzahl): self.w.aus.text=str(Augenzahl) def explosiony_anzeigen(self): y=helix(pos=(-4,4,4),color=color.yellow,radius=1.5,axis=(5,5,-5),length=9) ok= points(pos=[(7,4,-4),(6,3,4),(2,7,2),(1,1,-1),(-9,2,5)],size=5,color=color.yellow) def explosionb_anzeigen(self): y=helix(pos=(-4,4,-4),color=color.blue,radius=1.5,axis=(5,5,5),length=15) uk= points(pos=[(-4,4,-4),(4,8,-4),(-5,3,3),(6,3,4)],size=5,color=color.cyan) def explosionr_anzeigen(self): y=helix(pos=(4,4,-4),color=color.red,radius=1.5,axis=(-5,5,5),length=10) zk= points(pos=[(-4,7,-4),(6,8,-4),(-3,3,3),(0,2,0),(-9,2,5)],size=5,color=color.red) def explosiono_anzeigen(self): y=helix(pos=(4,4,4),color=color.orange,radius=1.5,axis=(-5,5,-5),length=13) pk= points(pos=[(-3,3,3),(-6,1,4),(2,7,2),(1,1,-1),(-9,2,5)],size=5,color=color.orange) def run(self): pick=None while True: rate(30) if scene.mouse.events: m1=scene.mouse.getevent() if m1.drag and m1.pick: for i in self.figurenliste: if m1.pick in i.objects: drag_pos = i.pos pick = m1.pick print pick break if m1.pick==self.Wuerfel: self.w=wuerfeln() self.senden("self.wuerfelzahl_anzeigen("+str(self.w.aus.text)+")") if m1.pick==self.kugely: #self.explosiony_anzeigen() self.senden("self.explosiony_anzeigen()") if m1.pick==self.kugelb: self.senden("self.explosionb_anzeigen()") if m1.pick==self.kugelr: self.senden("self.explosionr_anzeigen()") if m1.pick==self.kugelo: self.senden("self.explosiono_anzeigen()") elif m1.drop: for z in range(len(self.figurenliste) ): if pick in self.figurenliste[z].objects: #print z break for p in range(len(self.felderliste)): print mag (self.felderliste[p].stein.pos - pick.frame.pos) if mag (self.felderliste[p].stein.pos - pick.frame.pos) <0.8: print p break # self.figur_positionieren(z,p) self.senden("self.figur_positionieren("+str(z)+","+str(p)+")") pick = None if pick: new_pos = scene.mouse.project(normal=(0,1,0)) if new_pos != drag_pos : drag_pos = new_pos i.pos = drag_pos + vector(0,0.15,0) class Spielfigur(frame) : def __init__ (self,farbe1 = color.orange,farbe2=color.red,pos = (0,0,0)): frame.__init__(self,pos = pos) self.pos = pos self.figur = cone(frame=self,pos=(0,0,0),axis =(0,1,0),color = farbe1,radius = (0.4),material = (materials.chrome)) self.kopf = sphere(frame=self,pos = (0,1.2,0),radius = (0.3),color = farbe1,material = (materials.chrome)) self.ring1 = ring(frame=self,pos =(0,0,0),axis = (0,1,0),color = farbe2,radius = (0.4),material = (materials.wood)) self.ring2 = ring(frame=self,pos =(0,0.7,0) ,axis = (0,1,0),color = farbe2, radius = (0.3),material = (materials.wood)) self.punkt = sphere(frame=self,pos = (0,1.58,0),color = farbe2,radius = (0.1),material = (materials.wood)) zufallszahl=(1,2,3,4,5,6) class wuerfeln(frame): def __init__(self): self.aus = label(pos=(0,1.2,0),color=color.white,text=(str(choice(zufallszahl)))) #class Kugel(frame) : # def __init__ (self,farbe = color.yellow, position = (4,0.15,4)) : # self.Kugel = sphere (pos = position, color = farbe, radius = 0.25) x= Sp() x.run()