ich hab oben die ganzen definitionen von funktionen usw, dazwischen immer mal wieder variablen zuweisungen und eigentlich alles relativ unordentlich, weil ich das immer wieder verändert hab (Dos eingabe + ausgabe => dos eingabe, windows ausgabe...)
ich hoffe das geht in ordnung hier jetz mal den code zu posten, aber wie gesagt: unordnung pur

Code: Alles auswählen
# -*- coding: cp1252 -*-
import random
import sys
from Tkinter import *
from tkSimpleDialog import *
##def Ausgab(event):
## lb["text"] = 'Ausgab: ' + eingabe.get()
## eingabe.set(0)
x1=50
y1=-30
x2=80
y2=0
x3=y3=250
x4=y4=280
y1 = y1+ 120
y2 = y2+ 120
Rundenzahl = 6
Liste = []
def Mainprog():
#while Rundenzahl > 0:
for g in range(1):
#Eingabe
## print "1 : red, 2: green 3: magenta, 4: blue, 5: yellow, 6: gray"
for i in range(0,4):
## Eingabe = raw_input("Bitte Zahl eingeben ")
## Eingabe = askstring("Farbe eingeben", "farbe hier")
Liste.append(Eingabe)
#Umwandlung
print Liste
z = {"rot" : 1, "gruen": 2, "lila": 3, "blau": 4, "gelb": 5, "grau": 6}
z1 = {"rot" : "red", "gruen": "green", "lila": "magenta", "blau": "blue", "gelb": "yellow", "grau": "gray"}
Farben = map(lambda x: z1[x], Liste)
Liste = map(lambda x: z[x], Liste)
Richtig = []
# Vergleich
for element in Liste[:1]:
a1 = element
for element in Liste[1:2]:
b1 = element
for element in Liste[2:3]:
c1 = element
for element in Liste[3:4]:
d1 = element
if a1 == a : #a1 hat die richtige position
Richtig.append(1)
if b1 == b : #b1 hat die richtige position
Richtig.append(1)
if c1 == c : #c1 hat die richtige position
Richtig.append(1)
if d1 == d : #d1 hat die richtige position
Richtig.append(1)
if a1 == b or a1 == c or a1 == d and schwarz != 4: #a1 passt
Richtig.append(2)
if b1 == a or b1 == c or b1 == d and schwarz != 4: #b1 passt
Richtig.append(2)
if c1 == a or c1 == b or c1 == d and schwarz != 4: #c1 passt
Richtig.append(2)
if d1 == a or d1 == b or d1 == c and schwarz != 4: #d1 passt
Richtig.append(2)
v = {1 : "black", 2: "white"}
Richtig = map(lambda x: v[x], Richtig)
if Richtig == ["black", "black", "black", "black"]: #alles richtig!!!
Rundenzahl = 0
Farbe1 = "white" #farbe kreise in reihe
Farbe2 = "black" #farbe kreise rechts
Ausgabe()
y1 = y1 +120
y2 = y2 + 120
Liste=[]
Farben= []
#Richtig= []
Rundenzahl = Rundenzahl -1
for element in Farben:
print element
def Zuweisen(event):
test = eingabe.get()
Liste.append(test)
eingabe.set(0)
if len(Liste) == 4:
Mainprog()
def Beenden():
sys.exit(0)
def Grundstellung():
x1=50
y1=-30
x2=80
y2=0
x3=y3=250
x4=y4=280
canvas.create_text(50,10, text="Mastermind 0.7b")
for v in range(6):
x1 = 50
y1 = y1 +120
x2 = 80
y2 = y2 + 120
x4=280
canvas.create_rectangle(x1-10,y1-40,x4+35,y2+40,fill="brown")
for i in range(4):
canvas.create_oval(x1,y1,x2,y2,fill="brown") #kreise
x1= x1+ 40
x2= x2+ 40
z= 25 #Abstand zw. den Kreisen
canvas.create_oval(x3-28,y1 - 28,x4 +28 ,y2 +28, fill = "brown") #großer kreis
canvas.create_oval(x3,y1 - z, x4, y2 - z, fill="brown") #kreis oben
canvas.create_oval(x3,y1 + z, x4, y2 + z, fill="brown") #kreis unten
canvas.create_oval(x3 - z,y1, x4 - z, y2, fill="brown")#kreis links
canvas.create_oval(x3 + z,y1, x4 + z, y2, fill="brown")#kreis rechts
def Ausgabe():
for v in range(1):
x1=50
#y1=y1 + 120
x2=80
#y2=y2 + 120
x3=y3=250
x4=y4=280
canvas.create_text(50,10, text="Mastermind 0.7b")
canvas.create_rectangle(x1-10,y1-40,x4+35,y2+40, fill = "brown") #aussenrahmen
for i in range(1):
for element in Farben[:1]:
Farbe1 = element
for element in Farben[1:2]:
Farbe2 = element
for element in Farben[2:3]:
Farbe3 = element
for element in Farben[3:4]:
Farbe4 = element
canvas.create_oval(x1,y1,x2,y2,fill=Farbe1) #kreise
x1= x1+ 40
x2= x2+ 40
canvas.create_oval(x1,y1,x2,y2,fill=Farbe2) #kreise
x1= x1+ 40
x2= x2+ 40
canvas.create_oval(x1,y1,x2,y2,fill=Farbe3) #kreise
x1= x1+ 40
x2= x2+ 40
canvas.create_oval(x1,y1,x2,y2,fill=Farbe4) #kreise
x1= x1+ 40
x2= x2+ 40
z= 25
canvas.create_oval(x3-28,y1 - 28,x4 +28 ,y2 +28, fill = "brown") #großer kreis
Farbe1 = Farbe2 = Farbe3 = Farbe4 = "brown"
for element in Richtig[:1]:
Farbe1 = element
for element in Richtig[1:2]:
Farbe2 = element
for element in Richtig[2:3]:
Farbe3 = element
for element in Richtig[3:4]:
Farbe4 = element
canvas.create_oval(x3,y1 - z, x4, y2 - z, fill=Farbe1) #kreis oben
canvas.create_oval(x3,y1 + z, x4, y2 + z, fill=Farbe2) #kreis unten
canvas.create_oval(x3 - z,y1, x4 - z, y2 , fill=Farbe3)#kreis links
canvas.create_oval(x3 + z,y1, x4 + z, y2 , fill=Farbe4)#kreis rechts
#PROGRAMMBEGINN!!!!!!!!!!!!!!!!!!!!!!!!!!!
Fenster = Tk()
frame1 = Frame(Fenster, relief = RIDGE, borderwidth =2)
frame1.pack(fill=NONE, side = LEFT)
frame2 = Frame(Fenster, relief = RIDGE, borderwidth = 2)
frame2.pack(fill="y", side = RIGHT)
canvas = Canvas(frame1 ,height = 800)
canvas.pack()
canvas2 = Canvas(frame2, height = 300, width = 150)
canvas2.pack()
for i in range(1):
eingabe = StringVar()
eingabe.set(0)
# Eingabefeld
e = Entry(frame2,textvariable=eingabe,bg='white')
e.pack()
# Ausgabe mit Enter-Taste
e.bind("<Return>",Zuweisen)
Grundstellung()
#Liste = []
##lb = Label(frame1,
## fg='blue',
## text = 'Ausgabe: ' + eingabe.get(),
## font = font,
## )
##lb.pack(pady = 10)
#t = t + 1
bende = Button(frame1, text = "Ende", command = Beenden)
bende.pack(side= 'bottom')
if t == 4:
Beenden
Fenster.mainloop()
Farben = []
schwarz = weiss = 0
g = 0
#Zahlen Bestimmen
while g == 0:
a = random.randint(1, 6)
b = random.randint(1, 6)
c = random.randint(1, 6)
d = random.randint(1, 6)
g = 1
if a == b or a == c or a == d:
g = 0
if b == c or b == d:
g = 0
if c == d:
g = 0
print a , b , c , d #Testausgabe
also denk mal das gescheites wär das ganze neu zu schreiben :/