0.45 +Clearfunktion
Funktion zum neu Anfangen
Projekt3D4G-0.45x1.py — text/python-source, 7 KB (7186 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)
c=False
unbox = box (frame=f,pos=(0,6,0))
cLabel = label(pos=cbox.pos, text="Clear")
unLabel = label(frame=f,pos=unbox.pos, text="NoClear")
for obj in f.objects:
obj.set_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):
if(p==1):
r=1
print p,"Spieler1"
else:
r=2
print p,"Spieler2"
w=1
#nach "hinten"
if (max(x-1)):
if matrix[x-1][y][z]==r:
print 1
w=w+1
if (max(x-2)):
print 2
if matrix[x-2][y][z]==r:
w=w+1
if (max(x-3)):
print 3
if matrix[x-3][y][z]==r:
if(r==1):
print 4
print "Spieler 1 hat gewonnen"
return False
else:
print 42
print "Spieler 2 hat gewonnen"
return False
else:
return True
else:
return True
else:
return True
else:
return True
else:
return True
else:
return True
#nch links/rechts
#if (max(z-1
while wi:
rate(50)
wi=True
if scene.mouse.events:
sme=scene.mouse.getclick()
if sme.pick==cbox:
print "lol"
if c==True:
for i in range (64):
kugel[i].set_visible(False)
#kugel[i].del
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]]]
else:
cbox.color=color.red
cLabel.text="Are you sure?"
for obj in f.objects:
obj.set_visible(True)
elif sme.pick==unbox:
print "lol2"
cBox.color=color.white
cLabel.text="Clear"
print "Clear undone"
for obj in f.objects:
obj.set_visible(False)
for i in range(16):
if sme.pick==block[i+48]:
print i,getZ(i)
print i,getY(i)
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))
print wi
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))
print wi
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))
print wi
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))
print wi
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))
print wi
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))
print wi
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))
print wi
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))
print wi
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