Links und Funktionen
Sprachumschaltung

Navigationspfad


Inhaltsbereich

main3

schach2.py — text/python-source, 5 KB (6035 bytes)

Dateiinhalt

# -*- coding: utf-8 -*-
from visual import *
from Figuren import *
from threading import Thread

scene.userzoom=True
scene.userzoom=True
scene.forward=(-1,-1,-1)
scene.autoscale = True
scene.range = 120
scene.center = (0,0,0)
scene.up = (0,1,0)
scene.background = color.black
scene.fov = 1
scene.fullscreen = False
scene.title = "Koordinaten"
scene.width = 610
scene.height = 700
scene.x = 0
scene.y = 0

pick=None
BauerW=[]
BauerS=[]
TurmW=[]
TurmS=[]
SpringerW=[]
SpringerS=[]
LaeuferW=[]
LaeuferS=[]
DameW=None
DameS=None
KoenigW=None
KoenigS=None
Sboxen=[]

#FeldListe
class Spielfeld(frame):
    def __init__(self, pos=(0,0,0)):
        self.feld=0
        frame.__init__(self, pos=pos)
        self.feld = []
        self.groesse=10
        i=0
        farbe=True
        while i<8:
            e=0
            while e<8:
                if farbe:
                    color=(.8,.6,.5)
                    farbe=False
                else:
                    color=(.6,.4,.3)
                    farbe=True
                g = self.groesse + 0.0
                self.feld.append(box( pos= (g/2 +g*e,0,g/2 + g*i), height=.1, width=g, length=g, color=color, material=materials.wood, frame=self))
                e=e+1
            i=i+1
            if farbe:
                    farbe=False
            else:
                    farbe=True
    def get_pos(self, x, y): 
        return self.feld[x+y*8].pos + (0,.01,0)
    def gfeld(self,x,y):
        return self.feld[x+y*8]

class Sbox(frame):
    "Thread"
    def __init__(self, pos, figur):
        frame.__init__(self, pos=pos)
        self.f = figur
        self.b = box(pos=(0,0,0), height=20, length=8, width=8, opacity=0, frame=self)

        
xAchse = arrow(axis=(100,0,0), shaftwidth=0.05, color=color.red)
yAchse = arrow(axis=(0,100,0), shaftwidth=0.05, color=(0,0,1))
zAchse = arrow(axis=(0,0,100), shaftwidth=0.05, color=color.green)

xAchse = label(pos=(100,0,0), text="X-Achse")
yAchse = label(pos=(0,100,0), text="Y-Achse")
zAchse = label(pos=(0,0,100), text="Z-Achse")

def spielfiguren(sfeld):
    i=0
         
    while i<8:
        BauerW.append(Bauer(pos=sfeld.get_pos(i,1)))
        Sboxen.append(Sbox(pos=sfeld.get_pos(i,1), figur=BauerW[i]))
        i = i+1
    i=0
    while i<8:
        BauerS.append(Bauer2(pos=sfeld.get_pos(i,6)))
        Sboxen.append(Sbox(pos=sfeld.get_pos(i,6), figur=BauerS[i]))
        i = i+1

    #Turm
    TurmW.append(Turm(pos=sfeld.get_pos(0,0)))
    Sboxen.append(Sbox(pos=sfeld.get_pos(0,0), figur=TurmW[0]))
    TurmW.append(Turm(pos=sfeld.get_pos(7,0)))
    Sboxen.append(Sbox(pos=sfeld.get_pos(7,0), figur=TurmW[1]))
    TurmS.append(Turm2(pos=sfeld.get_pos(0,7)))
    Sboxen.append(Sbox(pos=sfeld.get_pos(0,7), figur=TurmS[0]))
    TurmS.append(Turm2(pos=sfeld.get_pos(7,7)))
    Sboxen.append(Sbox(pos=sfeld.get_pos(i,6), figur=TurmS[1]))

    #Springer

    SpringerW.append(Pferdchen(pos=sfeld.get_pos(2,0)))
    Sboxen.append(Sbox(pos=sfeld.get_pos(2,0), figur=SpringerW[0]))
    SpringerW.append(Pferdchen(pos=sfeld.get_pos(5,0)))
    Sboxen.append(Sbox(pos=sfeld.get_pos(5,0), figur=SpringerW[1]))
    SpringerS.append(Pferdchen2(pos=sfeld.get_pos(2,7)))
    Sboxen.append(Sbox(pos=sfeld.get_pos(2,7), figur=SpringerS[0]))
    SpringerS.append(Pferdchen2(pos=sfeld.get_pos(5,7)))
    Sboxen.append(Sbox(pos=sfeld.get_pos(5,7), figur=SpringerS[1]))

    #Läufer

    LaeuferW.append(Laeufer(pos=sfeld.get_pos(1,0)))
    Sboxen.append(Sbox(pos=sfeld.get_pos(1,0), figur=LaeuferW[0]))
    LaeuferW.append(Laeufer(pos=sfeld.get_pos(6,0)))
    Sboxen.append(Sbox(pos=sfeld.get_pos(6,0), figur=LaeuferW[1]))
    LaeuferS.append(Laeufer2(pos=sfeld.get_pos(1,7)))
    Sboxen.append(Sbox(pos=sfeld.get_pos(1,7), figur=LaeuferS[0]))
    LaeuferS.append(Laeufer2(pos=sfeld.get_pos(6,7)))
    Sboxen.append(Sbox(pos=sfeld.get_pos(6,7), figur=LaeuferS[0]))

    #Dame

    DameW=Dame(pos=sfeld.get_pos(4,0))
    Sboxen.append(Sbox(pos=sfeld.get_pos(4,0), figur=DameW))
    DameS=Dame2(pos=sfeld.get_pos(4,7))
    Sboxen.append(Sbox(pos=sfeld.get_pos(4,0), figur=DameS))

    #Koenig

    KoenigW=Koenig(pos=sfeld.get_pos(3,0))
    Sboxen.append(Sbox(pos=sfeld.get_pos(3,0), figur=KoenigW))
    KoenigS=Koenig2(pos=sfeld.get_pos(3,7))
    Sboxen.append(Sbox(pos=sfeld.get_pos(3,7), figur=KoenigS))
                

def collisionSphere(obj1,obj2):
    m=mag(obj1.pos-obj2.pos)
    r=obj1.radius+obj2.radius
    if m<=r:
        return true
    else:
        return false

if __name__ == "__main__":
    s=Spielfeld()
    spielfiguren(s)

    while True:
            rate(50)
            if scene.mouse.events:                              # falls Maustaste gedrückt...
                m1 = scene.mouse.getevent()
                i = 0
                while i<len(Sboxen):                                            # event in m1 speichern
                    if m1.drag and m1.pick and m1.pick.opacity==0:                 # falls Mauskontakt mit Objekt
                        drag_pos = m1.pickpos                       # speichern der Kontaktkoordinaten in drag_pos
                        pick = m1.pick                              # pick gesetzt
                        
                    elif m1.drop:                                   # falls Maustaste losgelassen...
                        pick = None
                    i=i+1                               # Mauskontakt vorüber
            if pick:                                            # falls Mauskontakt...
                new_pos = scene.mouse.project(normal=(0,1,0), point=(0,.5,0))   # Neuposition immer in xy-Ebene..
                                                                # Kugel transparent
                if new_pos != drag_pos:                         # falls Neuposition ungleich Mauspos...
                    pick.pos += new_pos - drag_pos              # aktualisiert pickpos
                    drag_pos = new_pos                          # aktualisiert dragpos
                    m1.pick.frame.f.pos = new_pos
                    

Funktionsleiste