1.1 Beta
Verringerung des Hostvorteils (Blau kann auch gewinnen)
Projekt3D4G-1.1.py — text/python-source, 14 KB (14829 bytes)
Dateiinhalt
# -*- coding: utf-8 -*-
from visual import *
from random import random
scene.width=600
scene.height=600
scene.title="3D 4 in a row"
# 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")
#Button
f=frame()
cbox = box (pos=(0,7,0),color=color.white)
unbox = box (frame=f,pos=(0,5,0))
cLabel = label(pos=cbox.pos, text="Clear")
unLabel = label(frame=f,pos=unbox.pos, text="NoClear")
for obj in f.objects:
obj.visible=False
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 = []
kugel = []
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
wi=True
#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
#Abfangen der vollen Matrix
def max(s):
if s>3:
return False
elif s<0:
return False
else:
return True
#Gewinn
def winn(x,y,z,p):
g=True
r=p
w=1
#nach "hinten"
if (max(x-1)):
if matrix[x-1][y][z]==r:
w=w+1
if (max(x-2)):
if matrix[x-2][y][z]==r:
w=w+1
if (max(x-3)):
if matrix[x-3][y][z]==r:
print "Spieler",r,"hat gewonnen"
g=False
#nach oben/unten
w=1
if(max(y-1)):
if matrix[x][y-1][z]==r:
w=w+1
if (max(y-2)):
if matrix[x][y-2][z]==r:
w=w+1
if (max(y-3)):
if matrix[x][y-3][z]==r:
w=w+1
if(max(y+1)):
if matrix[x][y+1][z]==r:
w=w+1
if (max(y+2)):
if matrix[x][y+2][z]==r:
w=w+1
if (max(y+3)):
if matrix[x][y+3][z]==r:
w=w+1
if(w==4):
print "Spieler",r,"hat gewonnen"
g=False
#nach links/rechts
w=1
if(max(z-1)):
if matrix[x][y][z-1]==r:
w=w+1
if (max(z-2)):
if matrix[x][y][z-2]==r:
w=w+1
if (max(z-3)):
if matrix[x][y][z-3]==r:
w=w+1
if(max(z+1)):
if matrix[x][y][z+1]==r:
w=w+1
if (max(z+2)):
if matrix[x][y][z+2]==r:
w=w+1
if (max(z+3)):
if matrix[x][y][z+3]==r:
w=w+1
if(w==4):
print "Spieler",r,"hat gewonnen"
g=False
#von rechts unten nach lnks oben
w=1
if(max(z-1))and (max(y-1)):
if matrix[x][y-1][z-1]==r:
w=w+1
if (max(z-2))and (max(y-2)):
if matrix[x][y-2][z-2]==r:
w=w+1
if (max(z-3))and (max(y-3)):
if matrix[x][y-3][z-3]==r:
w=w+1
if(max(z+1))and (max(y+1)):
if matrix[x][y+1][z+1]==r:
w=w+1
if (max(z+2))and (max(y+2)):
if matrix[x][y+2][z+2]==r:
w=w+1
if (max(z+3))and (max(y+3)):
if matrix[x][y+3][z+3]==r:
w=w+1
if(w==4):
print "Spieler",r,"hat gewonnen"
g=False
#von links unten nach recht oben
w=1
if(max(z-1))and (max(y+1)):
if matrix[x][y+1][z-1]==r:
w=w+1
if (max(z-2))and (max(y+2)):
if matrix[x][y+2][z-2]==r:
w=w+1
if (max(z-3))and (max(y+3)):
if matrix[x][y+3][z-3]==r:
w=w+1
if(max(z+1))and (max(y-1)):
if matrix[x][y-1][z+1]==r:
w=w+1
if (max(z+2))and (max(y-2)):
if matrix[x][y-2][z+2]==r:
w=w+1
if (max(z+3))and (max(y-3)):
if matrix[x][y-3][z+3]==r:
w=w+1
if(w==4):
print "Spieler",r,"hat gewonnen"
g=False
#von hinten unten nach vorne oben
w=1
if(max(x+1))and (max(y+1)):
if matrix[x+1][y+1][z]==r:
w=w+1
if (max(x+2))and (max(y+2)):
if matrix[x+2][y+2][z]==r:
w=w+1
if (max(x+3))and (max(y+3)):
if matrix[x+3][y+3][z]==r:
w=w+1
if(max(x-1))and (max(y-1)):
if matrix[x-1][y-1][z]==r:
w=w+1
if (max(x-2))and (max(y-2)):
if matrix[x-2][y-2][z]==r:
w=w+1
if (max(x-3))and (max(y-3)):
if matrix[x-3][y-3][z]==r:
w=w+1
if(w==4):
print "Spieler",r,"hat gewonnen"
g=False
#von hinten oben nach vorne unten
w=1
if(max(x-1))and (max(y+1)):
if matrix[x-1][y+1][z]==r:
w=w+1
if (max(x-2))and (max(y+2)):
if matrix[x-2][y+2][z]==r:
w=w+1
if (max(x-3))and (max(y+3)):
if matrix[x-3][y+3][z]==r:
w=w+1
if(max(x+1))and (max(y-1)):
if matrix[x+1][y-1][z]==r:
w=w+1
if (max(x+2))and (max(y-2)):
if matrix[x+2][y-2][z]==r:
w=w+1
if (max(x+3))and (max(y-3)):
if matrix[x+3][y-3][z]==r:
w=w+1
if(w==4):
print "Spieler",r,"hat gewonnen"
g=False
#von hinten rechts unten nach vorne links oben
w=1
if(max(x+1))and (max(y+1)) and(max(z+1)):
if matrix[x+1][y+1][z+1]==r:
w=w+1
if (max(x+2))and (max(y+2))and(max(z+2)):
if matrix[x+2][y+2][z+2]==r:
w=w+1
if (max(x+3))and (max(y+3))and(max(z+3)):
if matrix[x++3][y+3][z+3]==r:
w=w+1
if(max(x-1))and (max(y-1))and(max(z-1)):
if matrix[x-1][y-1][z-1]==r:
w=w+1
if (max(x-2))and (max(y-2))and(max(z-2)):
if matrix[x-2][y-2][z-2]==r:
w=w+1
if (max(x-3))and (max(y-3))and(max(z-3)):
if matrix[x-3][y-3][z-3]==r:
w=w+1
if(w==4):
print "Spieler",r,"hat gewonnen"
g=False
#von hinten links unten nach vorne rechts oben
w=1
if(max(x+1))and (max(y+1)) and(max(z-1)):
if matrix[x+1][y+1][z-1]==r:
w=w+1
if (max(x+2))and (max(y+2))and(max(z-2)):
if matrix[x+2][y+2][z-2]==r:
w=w+1
if (max(x+3))and (max(y+3))and(max(z-3)):
if matrix[x+3][y+3][z-3]==r:
w=w+1
if(max(x-1))and (max(y-1))and(max(z+1)):
if matrix[x-1][y-1][z+1]==r:
w=w+1
if (max(x-2))and (max(y-2))and(max(z+2)):
if matrix[x-2][y-2][z+2]==r:
w=w+1
if (max(x-3))and (max(y-3))and(max(z+3)):
if matrix[x-3][y-3][z+3]==r:
w=w+1
if(w==4):
print "Spieler",r,"hat gewonnen"
g=False
#von hinten links oben nach vorne rechts unten
w=1
if(max(x+1))and (max(y-1)) and(max(z-1)):
if matrix[x+1][y-1][z-1]==r:
w=w+1
if (max(x+2))and (max(y-2))and(max(z-2)):
if matrix[x+2][y-2][z-2]==r:
w=w+1
if (max(x+3))and (max(y-3))and(max(z-3)):
if matrix[x+3][y-3][z-3]==r:
w=w+1
if(max(x-1))and (max(y+1))and(max(z+1)):
if matrix[x-1][y+1][z+1]==r:
w=w+1
if (max(x-2))and (max(y+2))and(max(z+2)):
if matrix[x-2][y+2][z+2]==r:
w=w+1
if (max(x-3))and (max(y+3))and(max(z+3)):
if matrix[x-3][y+3][z+3]==r:
w=w+1
if(w==4):
print "Spieler",r,"hat gewonnen"
g=False
#von hinten rechts oben nach vorne links unten
w=1
if(max(x+1))and (max(y-1)) and(max(z+1)):
if matrix[x+1][y-1][z+1]==r:
w=w+1
if (max(x+2))and (max(y-2))and(max(z+2)):
if matrix[x+2][y-2][z+2]==r:
w=w+1
if (max(x+3))and (max(y-3))and(max(z+3)):
if matrix[x+3][y-3][z+3]==r:
w=w+1
if(max(x-1))and (max(y+1))and(max(z-1)):
if matrix[x-1][y+1][z-1]==r:
print 1
w=w+1
if (max(x-2))and (max(y+2))and(max(z-2)):
if matrix[x-2][y+2][z-2]==r:
w=w+1
if (max(x-3))and (max(y+3))and(max(z-3)):
if matrix[x-3][y+3][z-3]==r:
w=w+1
if(w==4):
print "Spieler",r,"hat gewonnen"
g=False
return g
def clear(sme):
sme=scene.mouse.getclick()
if sme.pick==cbox:
if cbox.color==color.red:
#bereits angeklickt
while len(kugel):
kugel[-1].visible=False
del(kugel[-1])
for i in range(4):
for j in range(4):
for k in range(4):
matrix[i][j][k]=0
unbox.visible=False
unLabel.visible=False
cbox.color=color.white
cLabel.text="Clear"
return False
p=1
else:
#noch nicht angeklickt
cbox.color=color.red
cLabel.text="Are you sure?"
unbox.visible=True
unLabel.visible=True
return True
elif sme.pick==unbox:
#Abbruch Clear
cbox.color=color.white
cLabel.text="Clear"
print "Clear undone"
unbox.visible=False
unLabel.visible=False
return True
else:
return True
def do(wi,p):
while wi:
wi=True
rate(50)
if scene.mouse.events:
sme=scene.mouse.getclick()
if sme.pick==cbox or sme.pick==unbox:
clear(sme)
for i in range(16):
if sme.pick==block[i+48]:
if p==1:
if matrix[0][getY(i)][getZ(i)]==0:
kugel.append(sphere(pos=(block[i].pos),radius=0.5,color=color.red))
matrix[0][getY(i)][getZ(i)]=1
wi=winn(0,getY(i),getZ(i),p)
elif matrix[1][getY(i)][getZ(i)]==0:
kugel.append(sphere(pos= (block[i+16].pos),radius=0.5,color=color.red))
matrix[1][getY(i)][getZ(i)]=1
wi=winn(1,getY(i),getZ(i),p)
elif matrix[2][getY(i)][getZ(i)]==0:
kugel.append(sphere(pos= (block[i+32].pos),radius=0.5,color=color.red))
matrix[2][getY(i)][getZ(i)]=1
wi=winn(2,getY(i),getZ(i),p)
elif matrix[3][getY(i)][getZ(i)]==0:
kugel.append(sphere(pos= (block[i+48].pos),radius=0.5,color=color.red))
matrix[3][getY(i)][getZ(i)]=1
wi=winn(3,getY(i),getZ(i),p)
elif matrix[3][getY(i)][getZ(i)]!=0:
print "voll"
p=5
if p!=5:
p=2
print "Spieler",p,"ist dran"
else:
print "bitte anders setzen"
p=1
else:
if matrix[0][getY(i)][getZ(i)]==0:
kugel.append(sphere(pos= (block[i].pos),radius=0.5,color=color.blue))
matrix[0][getY(i)][getZ(i)]=2
wi=winn(0,getY(i),getZ(i),p)
elif matrix[1][getY(i)][getZ(i)]==0:
kugel.append(sphere(pos= (block[i+16].pos),radius=0.5,color=color.blue))
matrix[1][getY(i)][getZ(i)]=2
wi=winn(1,getY(i),getZ(i),p)
elif matrix[2][getY(i)][getZ(i)]==0:
kugel.append(sphere(pos= (block[i+32].pos),radius=0.5,color=color.blue))
matrix[2][getY(i)][getZ(i)]=2
wi=winn(2,getY(i),getZ(i),p)
elif matrix[3][getY(i)][getZ(i)]==0:
kugel.append(sphere(pos= (block[i+48].pos),radius=0.5,color=color.blue))
matrix[3][getY(i)][getZ(i)]=2
wi=winn(3,getY(i),getZ(i),p)
elif matrix[3][getY(i)][getZ(i)]!=0:
print "voll"
p=5
if p!=5:
p=1
print "Spieler",p,"ist dran"
else:
print "bitte anders setzen"
p=2
do(wi,p)
while True:
rate(1)
if scene.mouse.events:
sme=scene.mouse.getclick()
if clear(sme)==True:
wi=False
else:
wi=True
do(wi,p)