Links und Funktionen
Sprachumschaltung

Navigationspfad


Inhaltsbereich

main_Klick

schach3.py — text/python-source, 6 KB (6729 bytes)

Dateiinhalt

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

scene.userzoom=False
scene.userspin=False
scene.forward=(0,-1,-1)
scene.autoscale = False
scene.range = 62
scene.center = (40,0,40)
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=[]
DameS=[]
KoenigW=[]
KoenigS=[]
Sboxen=[]

pick=None

#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]
    def get_x(self, objekt):
        f=0
        for i in self.feld:
            if objekt.pos==i.pos:
                a=f
                a=a%8
                return a
            f=f+1
    def get_y(self,objekt):
        f=0
        for i in self.feld:
            if objekt.pos==i.pos:
                a= f - self.get_x(objekt)
                a= a/8
                return a
            f=f+1
    def r_color(self, objekt):
        Farbe=False
        f=0
        for i in self.feld:
            if Farbe:
                Farbe=False
            else:
                Farbe = True
            if i==objekt:
                if Farbe:
                    objekt.color=(.8,.6,.5)
                else:
                    objekt.color=(.6,.4,.3)
            if (f+1)%8==0:
                if Farbe:
                    Farbe=False
                else:
                    Farbe = True
            f=f+1
    def check(self, objekt):
        a=True
        for i in BauerW:
            if i.pos==objekt.pos + (0,.01,0):
                a=False
                return i
        for i in BauerS:
            if i.pos==objekt.pos + (0,.01,0):
                a=False
                return i
        for i in TurmW:
            if i.pos==objekt.pos + (0,.01,0):
                a=False
                return i
        for i in TurmS:
            if i.pos==objekt.pos + (0,.01,0):
                a=False
                return i
        for i in LaeuferW:
            if i.pos==objekt.pos + (0,.01,0):
                a=False
                return i
        for i in LaeuferS:
            if i.pos==objekt.pos + (0,.01,0):
                a=False
                return i
        for i in SpringerW:
            if i.pos==objekt.pos + (0,.01,0):
                a=False
                return i
        for i in SpringerS:
            if i.pos==objekt.pos + (0,.01,0):
                a=False
                return i
        for i in DameW:
            if i.pos==objekt.pos + (0,.01,0):
                a=False
                return i
        for i in DameS:
            if i.pos==objekt.pos + (0,.01,0):
                a=False
                return i
        for i in KoenigW:
            if i.pos==objekt.pos + (0,.01,0):
                a=False
                return i
        for i in KoenigS:
            if i.pos==objekt.pos + (0,.01,0):
                a=False
                return i
        if a:
            return None
        
        

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

    #Turm
    TurmW.append(Turm(pos=sfeld.get_pos(0,0)))
    TurmW.append(Turm(pos=sfeld.get_pos(7,0)))
    TurmS.append(Turm2(pos=sfeld.get_pos(0,7)))
    TurmS.append(Turm2(pos=sfeld.get_pos(7,7)))

    #Springer

    SpringerW.append(Pferdchen(pos=sfeld.get_pos(2,0)))
    SpringerW.append(Pferdchen(pos=sfeld.get_pos(5,0)))
    SpringerS.append(Pferdchen2(pos=sfeld.get_pos(2,7)))
    SpringerS.append(Pferdchen2(pos=sfeld.get_pos(5,7)))

    #Läufer

    LaeuferW.append(Laeufer(pos=sfeld.get_pos(1,0)))
    LaeuferW.append(Laeufer(pos=sfeld.get_pos(6,0)))
    LaeuferS.append(Laeufer2(pos=sfeld.get_pos(1,7)))
    LaeuferS.append(Laeufer2(pos=sfeld.get_pos(6,7)))

    #Dame

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

    #Koenig

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

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

class Active(Thread):
    "Das Aktive Objekt handeln)"
    def __init__(self, pick):
        Thread.__init__(self)
        self.pick=pick
        self.active=None

        Thread.start(self)
    def run(self):
        while true:
            if self.active == None:
                self.active = self.pick
            else:
                self.active.color = color.white
                c = s.check(self.active)
                if c != None and self.pick != self.active and self.pick!=None:
                    if s.check(self.pick):
                        s.check(self.pick).pos=(-1,0,-1)
                    c.pos=s.get_pos(s.get_x(self.pick),s.get_y(self.pick))
                    s.r_color(self.active)
                    self.pick=None
                if c==None:
                    self.pick=None
                if self.pick == None:
                    s.r_color(self.active)
                    self.active=self.pick

def set_pick():
    pick = None

if __name__ == "__main__":
    s=Spielfeld()
    spielfiguren(s)
    thread = Active(pick)
    while True:
        rate(50)
        if scene.mouse.events:
            m1 = scene.mouse.getevent()
            if m1.click=='left':
                a=True
                for i in s.feld:
                    if m1.pick == i:
                        thread.pick=i
                        a=False
                        print pick
                if a:
                    pick=None
                    print pick

                        

Funktionsleiste