0.4.1
Gewinnfunktion
Projekt3D4G-0.4.1.py — text/python-source, 4 KB (4836 bytes)
Dateiinhalt
from visual import * from random import random scene.width=600 scene.height=600 scene.title="3D 4 in a row" #Matrix #for i in range(4): # for j in range(4): # for k in range( # 3dmatrix = [[[e1,e2,e3],[e3,e4, #zellex = 3dmatrix[0][3][1] # Koordinatenachsen in Form von Pfeilen xAchse = arrow(axis=(10,0,0), shaftwidth=0.05, color=color.red) yAchse = arrow(axis=(0,10,0), shaftwidth=0.05, color=(0,0,1)) zAchse = arrow(axis=(0,0,10), shaftwidth=0.05, color=color.green) # Beschriftungen xLabel = label(pos=(10,0,0), text="x-Achse") yLabel = label(pos=(0,10,0), text="y-Achse") zLabel = label(pos=(0,0,10), text="z-Achse") matrix = [[[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]], [[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]], [[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]], [[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]] #Blöcke werden generiert block = [] for i in range(4): for j in range(4): for k in range(4): block.append(box(pos=(i,j,k),opacity=0.05)) #Spieler 1 fängt an p = 1 #Umrechnung von i in Koordinate Z def getZ(i): z=0 for r in range(i): if z==3: z=0 else: z=z+1 return z #Umrechnung von i in Koordinate Y def getY(i): y=0 s=0 for r in range(i): if s==3: s=0 if y==3: y=0 else: y=y+1 else: s=s+1 return y while True: rate(50) if scene.mouse.events: sme=scene.mouse.getclick() for i in range(16): if sme.pick==block[i+48]: #and sme.click==True: print i,getZ(i) print i,getY(i) if p==1: if matrix[0][getY(i)][getZ(i)]==0: sphere(pos=(block[i].pos),radius=0.5,color=color.red) matrix[0][getY(i)][getZ(i)]=1 elif matrix[1][getY(i)][getZ(i)]==0: sphere(pos= (block[i+16].pos),radius=0.5,color=color.red) matrix[1][getY(i)][getZ(i)]=1 elif matrix[2][getY(i)][getZ(i)]==0: sphere(pos= (block[i+32].pos),radius=0.5,color=color.red) matrix[2][getY(i)][getZ(i)]=1 elif matrix[3][getY(i)][getZ(i)]==0: sphere(pos= (block[i+48].pos),radius=0.5,color=color.red) matrix[3][getY(i)][getZ(i)]=1 elif matrix[3][getY(i)][getZ(i)]!=0: print "voll" p=5 if p!=5: p=2 print "Spieler 2" else: print "bitte anders setzen" p=1 else: if matrix[0][getY(i)][getZ(i)]==0: sphere(pos= (block[i].pos),radius=0.5,color=color.blue) matrix[0][getY(i)][getZ(i)]=2 elif matrix[1][getY(i)][getZ(i)]==0: sphere(pos= (block[i+16].pos),radius=0.5,color=color.blue) matrix[1][getY(i)][getZ(i)]=2 elif matrix[2][getY(i)][getZ(i)]==0: sphere(pos= (block[i+32].pos),radius=0.5,color=color.blue) matrix[2][getY(i)][getZ(i)]=2 elif matrix[3][getY(i)][getZ(i)]==0: sphere(pos= (block[i+48].pos),radius=0.5,color=color.blue) matrix[3][getY(i)][getZ(i)]=2 elif matrix[3][getY(i)][getZ(i)]!=0: print "voll" p=5 if p!=5: p=1 print "Spieler 1" else: print "bitte anders setzen" p=2 #Ausrechnen, ob der Spieler gewonnen hat def max(s): if s>3: return False elif s<0: return False else: return True #def win(p): # if p=1: # if p1: # return True # else: # return False #elif p=2: # if p1: # return True # else: # return False def p1(x,y,z): w=1 #nach "unten" if (max(x-1)): if matrix[x-1][y][z]==1: w+1 if runter1(x-1,y,z,w)==4: return True else: return False def runter1(x,y,z,w): if (max(x-1)): if matrix[[x-1][y][z]]==1: w=w+1 return runter1(x-1,y,z,w) else: return 0 else: return 0