|
@@ -0,0 +1,145 @@
|
|
|
+# -*- coding: utf-8 -*-
|
|
|
+#Mastermind
|
|
|
+#work by Python 2.7.10
|
|
|
+#Editor:Zhong Yunhao
|
|
|
+#ver alpha.0.6
|
|
|
+
|
|
|
+import random
|
|
|
+a = 'Willkommen bei Mastermind.Hinweis:Alle eingabe ist kleinbuchstabe\n'
|
|
|
+b = 'Es gibt 6 verschiedende Farben(rot,orange,gelb,gruen.blau,lila).Und nehmt der Computer 4 Farben in eine Reihe(koennen gleich sein)\n'
|
|
|
+c = 'Sie haben 9 Chancen\n'
|
|
|
+print(a+b+c)
|
|
|
+while True:
|
|
|
+ colour_list=[]
|
|
|
+ print'a.Starten','b.Spiel Schliessen'
|
|
|
+ entscheiden=raw_input("Entscheiden Sie\n")
|
|
|
+ if(entscheiden=='a'):
|
|
|
+ colour1=random.randint(1,6)
|
|
|
+ position=1
|
|
|
+ if position==1:
|
|
|
+ if colour1==1:
|
|
|
+ colour_list.insert(0,'rot')
|
|
|
+ elif colour1==2:
|
|
|
+ colour_list.insert(0,'orange')
|
|
|
+ elif colour1==3:
|
|
|
+ colour_list.insert(0,'gelb')
|
|
|
+ elif colour1==4:
|
|
|
+ colour_list.insert(0,'gruen')
|
|
|
+ elif colour1==5:
|
|
|
+ colour_list.insert(0,'blau')
|
|
|
+ elif colour1==6:
|
|
|
+ colour_list.insert(0,'lila')
|
|
|
+ colour2=random.randint(1,6)
|
|
|
+ p2=2
|
|
|
+ if p2==2:
|
|
|
+ if colour2==1:
|
|
|
+ colour_list.insert(1,'rot')
|
|
|
+ elif colour2==2:
|
|
|
+ colour_list.insert(1,'orange')
|
|
|
+ elif colour2==3:
|
|
|
+ colour_list.insert(1,'gelb')
|
|
|
+ elif colour2==4:
|
|
|
+ colour_list.insert(1,'gruen')
|
|
|
+ elif colour2==5:
|
|
|
+ colour_list.insert(1,'blau')
|
|
|
+ elif colour2==6:
|
|
|
+ colour_list.insert(1,'lila')
|
|
|
+ colour3=random.randint(1,6)
|
|
|
+ p3=3
|
|
|
+ if p3==3:
|
|
|
+ if colour3==1:
|
|
|
+ colour_list.insert(2,'rot')
|
|
|
+ elif colour3==2:
|
|
|
+ colour_list.insert(2,'orange')
|
|
|
+ elif colour3==3:
|
|
|
+ colour_list.insert(2,'gelb')
|
|
|
+ elif colour3==4:
|
|
|
+ colour_list.insert(2,'gruen')
|
|
|
+ elif colour3==5:
|
|
|
+ colour_list.insert(2,'blau')
|
|
|
+ elif colour3==6:
|
|
|
+ colour_list.insert(2,'lila')
|
|
|
+ colour4=random.randint(1,6)
|
|
|
+ p4=4
|
|
|
+ if p4==4:
|
|
|
+ if colour4==1:
|
|
|
+ colour_list.insert(3,'rot')
|
|
|
+ elif colour4==2:
|
|
|
+ colour_list.insert(3,'orange')
|
|
|
+ elif colour4==3:
|
|
|
+ colour_list.insert(3,'gelb')
|
|
|
+ elif colour4==4:
|
|
|
+ colour_list.insert(3,'gruen')
|
|
|
+ elif colour4==5:
|
|
|
+ colour_list.insert(3,'blau')
|
|
|
+ elif colour4==6:
|
|
|
+ colour_list.insert(3,'lila')
|
|
|
+ print'Hinweis:O bedeutet richtig position u. richtig Farb.X bedeutet richtig Farbe aber false position. [] bedeutet ,es inhaltet diese Farbe nicht\n'
|
|
|
+ print'Sie muessen diese Form eingeben:lila orange gelb blau'
|
|
|
+ i=0
|
|
|
+ for i in range(1,10):
|
|
|
+ try:
|
|
|
+ antwort=raw_input('Bitte geben Sie die Farben\n')
|
|
|
+ antwort=antwort.split(' ')#eingabe form list
|
|
|
+ resualt=[]
|
|
|
+ if antwort!=colour_list:
|
|
|
+ if antwort[0]in colour_list:
|
|
|
+ if antwort[0]==colour_list[0]:
|
|
|
+ a1='O'
|
|
|
+ else:
|
|
|
+ a1='X'
|
|
|
+ else:
|
|
|
+ a1='[]'
|
|
|
+ if antwort[1]in colour_list:
|
|
|
+ if antwort[1]==colour_list[1]:
|
|
|
+ a2='O'
|
|
|
+ else:
|
|
|
+ a2='X'
|
|
|
+ else:
|
|
|
+ a2='[]'
|
|
|
+ if antwort[2]in colour_list:
|
|
|
+ if antwort[2]==colour_list[2]:
|
|
|
+ a3='O'
|
|
|
+ else:
|
|
|
+ a3='X'
|
|
|
+ else:
|
|
|
+ a3='[]'
|
|
|
+ if antwort[3]in colour_list:
|
|
|
+ if antwort[3]==colour_list[3]:
|
|
|
+ a4='O'
|
|
|
+ else:
|
|
|
+ a4='X'
|
|
|
+ else:
|
|
|
+ a4='[]'
|
|
|
+ a5=' '
|
|
|
+ print(a1+a5+a2+a5+a3+a5+a4)
|
|
|
+ if i<=7:
|
|
|
+ s1='Sie haben noch'
|
|
|
+ s2='Chancen'
|
|
|
+ s4=' '
|
|
|
+ print(s1+s4+str(9-i)+s4+s2)
|
|
|
+ elif i==8:
|
|
|
+ s3='Chance'
|
|
|
+ s5=' '
|
|
|
+ print(s1+s5+str(9-i)+s5+s3)
|
|
|
+ elif i==9:
|
|
|
+ print('Verloren')
|
|
|
+ s8='Antwort ist: '
|
|
|
+ print(s8+str(colour_list))
|
|
|
+ break
|
|
|
+ else:
|
|
|
+ s5='Sie sind Mastermind!!!'
|
|
|
+ s6='Anzahl der Versuche:'
|
|
|
+ s7='\n'
|
|
|
+ print(s5+s7+s6+str(i))
|
|
|
+ break
|
|
|
+ except:
|
|
|
+ print'Bitte richtige Form eingeben'
|
|
|
+ elif(entscheiden=='b'):
|
|
|
+ break
|
|
|
+ else:
|
|
|
+ print('Bitte richtig eingeben')
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|