bossfunktion (iA)
Spiel.py — Python Source, 7 KB (8141 bytes)
Dateiinhalt
# -*- coding: utf-8 -*- from visual import * from random import choice import time # Die Spielfiguren: class Spielfigur_Lena(frame): def __init__(self, mat=materials.silver, col=color.hsv_to_rgb((0.84,0.65,0.65))): frame.__init__(self) self.head=ellipsoid(frame=self, pos=(0,0.4,0), length=1.1, height=0.7, width=0.6, material=mat,color=col) self.body=cylinder(frame=self, pos=(0,0.4,0), axis=(0,-0.9,0), radius=0.25, material=mat, color=col) self.beinl=box(frame=self, pos=(-0.1,-0.2,0),length=0.08, width=0.08, height=1.2, material=mat, color=col) self.beinr=box(frame=self, pos=(0.1,-0.2,0),length=0.08, width=0.08, height=1.2, material=mat, color=col) self.antenl=helix(frame=self, pos=(-0.18,0.7,0), axis=(-0.1,0.3,0), radius=0.02, thickness=0.01/2, material=materials.chrome) self.antenr=helix(frame=self, pos=(0.18,0.7,0), axis=(0.1,0.3,0), radius=0.02, thickness=0.01/2, material=materials.chrome) self.eye=sphere(frame=self, pos=(0,0.44,0.27), radius=0.12, color=color.hsv_to_rgb((0.2,0.5,1)),material=materials.chrome) self.eyering=sphere(frame=self, pos=(0,0.44,0.23), radius=0.14,color=color.black, material=materials.shiny) self.name= label(pos=(0, 1.3, 0), linecolor=col, frame= self, text= "Player3") class Spielfigur_Mario (frame): def __init__(self, farbeCube=color.red, farbeSpikes=(0/255.0, 255/255.0, 0/255.0), stoffCube= materials.wood, stoffSpikes= materials.blazed, farbeFace= (255/255.0, 68/255.0, 0/255.0), stoffFace= materials.rough, farbeOthers= (0/255.0, 255/255.0, 0/255.0), stoffOthers= materials.chrome, spielerfarbe1= color.green): frame.__init__(self) self.cube= box(pos=(0.5,0.5,0.5), length=1, heigh=1, width=1,color=farbeCube, material=stoffCube, frame=self) self.spike1= cone (axis=(-0.5,0,0), pos=(0, 0.5,0.5), frame=self, radius= 0.2, color=farbeSpikes, material= stoffSpikes) self.spike2= cone (axis=(0,0,-0.5), pos=(0.5, 0.5, 0), frame=self,radius= 0.2, color=farbeSpikes, material= stoffSpikes) self.spike3= cone (axis=(0.5, 0, 0), pos=(1,0.5,0.5), frame=self,radius= 0.2, color=farbeSpikes, material= stoffSpikes) self.spike4= cone (axis=(0, 0.5, 0), pos=(0.5,1,0.5), frame=self,radius= 0.2, color=farbeSpikes, material= stoffSpikes) self.spikeDown= cone (axis=(0, -1, 0), pos=(0.5,0,0.5), frame=self,radius= 0.2, color=farbeSpikes, material= stoffSpikes) self.eye1= sphere(radius=0.1, pos=(0.25, 0.75, 1), frame=self, color= farbeFace, material= stoffFace) self.eye2= sphere(radius=0.1, pos=(0.75, 0.75, 1), frame=self, color= farbeFace, material= stoffFace) self.nose= cone (axis=(0, 0, 0.25), pos=(0.5,0.5,1), frame=self,radius= 0.1, color=farbeSpikes, material= stoffSpikes) self.mouth= ellipsoid (axis=(0.5,0,0), pos=(0.5,0.2,1), width=0.1, height= 0.22, length= 0.2, frame=self,radius= 0.2, color= farbeFace, material= stoffFace) #self.mouth= box(pos=(0.5, 0.2, 1), axis=(1, 0, 0), width=0.2, height=0.1, length= 0.5, frame=self, color= farbeFace, material= stoffFace) self.plate= cylinder (pos=(0.5, -1, 0.5), axis= (0,0.05,0),radius=0.75, frame= self,color= farbeOthers, material= stoffOthers) self.ring= ring (pos=(0.5, -0.75, 0.5), axis= (0,0.02,0),radius=0.5, frame= self, color= farbeOthers, material= stoffOthers) self.ring2= ring (pos=(0.5, -0.5, 0.5), axis= (0,0.02,0),radius=0.3, frame= self, color= farbeOthers, material= stoffOthers) self.name= label(pos=(0.5, 1.6, 0.5), linecolor= spielerfarbe1, frame= self, text= "Player1") class Spielfigur_Kjell(frame): def __init__(self,): frame.__init__(self) self.koerper = ellipsoid(frame = self,height = 1,length = 0.5, width = 0.5,pos = (0,0,0),color = color.red,material = materials.wood) self.hitbox = box(frame = self, pos = (0,0,0),height = 3, width = 2, length = 2, opacity = 0.001) self.gesicht = pyramid(frame = self ,pos= (-0.1,0.7,0),size = (0.75,0.3,0.5),color = color.red,material = materials.wood, axis = (1,-1,0)) self.beinlinks = curve(frame = self ,pos=[(0,-0.2,0),(0.2,-0.8,0.1),(-0.25,-1.1,0.25)],radius = 0.08,color = color.red, material = materials.wood) self.beinrechts = curve(frame = self ,pos=[(0,-0.2,0),(0.25,-0.8,-0.25),(0.25,-1.1,-0.25)],radius = 0.08,color = color.red, material = materials.wood) self.armlinks = curve(frame = self ,pos=[(0,0.45,0),(0,0,0.3),(0.25,-0.3,0.25)],radius = 0.08,color = color.red, material = materials.wood) self.armlinks = curve(frame = self ,pos=[(0,0.45,0),(0,0,-0.3),(0.25,-0.3,-0.25)],radius = 0.08,color = color.red,material = materials.wood) self.augelinks = sphere(frame = self, pos = (0.1,0.7,0.1),radius = 0.05, material = materials.chrome,color = color.orange) self.augerechts = sphere(frame = self, pos = (0.1,0.7,-0.1),radius = 0.05, material = materials.chrome,color = color.orange) self.ohrlinks = pyramid(frame = self, pos = (-0.05,0.75,0.1),size = (0.35,0.1,0.1),axis = (-0.5,1,0), color = color.red,material = materials.wood) self.ohrrechts = pyramid(frame = self, pos = (-0.05,0.75,-0.1),size = (0.35,0.1,0.1),axis = (-0.5,1,0), color = color.red,material = materials.wood) self.name= label(pos=(0, 1.2, 0.5), linecolor=color.red, frame= self, text= "Player2") # Das Feld: # Der Würfel: zufallszahl=(1,2,3,4,5,6) class wuerfel(frame): def __init__(self): frame.__init__(self) bowurfel=box(frame=self, pos=(20,20,0), height=4,width=4,length=4, color=color.green) lab=label(pos=(20,20,0), color=color.green, text="Wurfel", opacity=0.5) def wuerfeln(): aus=label(pos=(-20,30,0), color=color.green, text="Du darfst " + str(choice(zufallszahl))+ " Schritte gehen.") time.sleep(5) aus.visible=False # Das Spiel: class spiel: def __init__(self, pos=(-20,20,0), color=color.green,): #f=field() self.bowurfel=wuerfel() ausgabe=label(text="Willkommen zu Snakes'n'ladders XTREME!") time.sleep(3) ausgabe.visible=False del ausgabe ausgabe=label(text="Wie viele Spieler wollen spielen?") time.sleep(3) ausgabe.visible=False del ausgabe def wuerfeln(self): aus=label(pos=(-10,10,0), color=color.green, text="Du darfst " + str(choice(zufallszahl))+ " Schritte gehen.") time.sleep(2) aus.visible=False def run(self): while True: rate(50) if scene.mouse.events: m1=scene.mouse.getevent() if m1.pick in self.bowurfel.objects: self.wuerfeln() if scene.kb.keys: zeichen=scene.kb.getkey() if zeichen=="2": ausgabe=label(text="Es spielen 2 Spieler!") spielerzahl=2 elif zeichen=="3": ausgabe=label(text="Es spielen 3 Spieler!") spielerzahl=3 else: ausgabe=label(text="Diese Spielerzahl is ungültig!") time.sleep(3) ausgabe.visible=False del ausgabe figur1=Spielfigur_Mario() figur1.visible=False figur2=Spielfigur_Kjell() figur2.visible=False figur3=Spielfigur_Lena() figur3.visible=False if spielerzahl==2: figur1.pos=(-1,0.5,-1) figur1.visible=True figur2.pos=(-1,0.5,1) figur2.visible=True elif spielerzahl==3: figur1.pos=(-1,0.5,-1) figur1.visible=True figur2.pos=(-1,0.5,1) figur2.visible=True figur3.pos=(1,0.5,-1) figur3.visible=True time.sleep(2) ausgabe=label(text="Player1 beginnt!") time.sleep(3) ausgabe.visible=False del ausgabe x=spiel() x.run()