Browse Source

上传文件至 'Programmierung1_PVL'

stcgche2 5 years ago
parent
commit
8c1b4c43a9
3 changed files with 121 additions and 0 deletions
  1. BIN
      Programmierung1_PVL/high_score.txt
  2. 121 0
      Programmierung1_PVL/spiel.py
  3. BIN
      Programmierung1_PVL/spieler.txt

BIN
Programmierung1_PVL/high_score.txt


+ 121 - 0
Programmierung1_PVL/spiel.py

@@ -0,0 +1,121 @@
+#Programmieren_I
+#Autor1:Tang,Lizhong(4068443) 
+#Autor2:Chen,Cheng(4068922) 
+#Autor3:Song,Zhaorui(4068539)
+#Fachbereich:EIT 1
+#Gruppe:3
+#Datum:19.12.2018
+#Version 4.2
+
+#Module Time
+import time as t
+#Menue zur Auswahl
+while True:
+    print'''
+A -------> High Scroe
+B -------> New Game
+C -------> Bereits extierende Spieler
+D -------> Spiel Verlassen
+    '''
+    antwort = raw_input('Waehlen Sie Ihre Option:')
+    #Antwort vergleichen
+    
+    if antwort == 'b'or antwort =='B':
+        print'''
+Geben Sie ihr Name ein!
+Und Druecken Sie "Enter" um Spiel zu Starten
+        '''
+        while True:
+              player = str(raw_input("Name:"))
+              #Fehler Eingabe melden
+              if player.isalpha():
+                 break
+              else:
+                 print"Unguetige Name!"
+        #setzen Name des Spielers in "spieler.txt"
+        file1 = open("spieler.txt","a")
+        file1.write(player+"\n\t")
+        file1.close()
+        #Startzeit
+        start = t.time()
+        #Module random
+        import random as r
+        #5-maliges Abfragen einer Rechenaufgabe mit Zufallszahlen
+        n = 0
+        m = 0
+        while True:
+            if n == 5 and m == 5:
+                print"Sie haben alle Aufgaben recht!"
+                #Endzeit
+                end = t.time()
+                #Zeit rechnen
+                d = int(end - start)
+                print"Zeit dauert:%d"%d+"s"
+                #Setzen Zeit in "high_score.txt"
+                file2 = open("high_score.txt","a")
+                file2.write(player+"\t"+str(d)+"s"+"\n")
+                file2.close()
+                break
+            elif n != 5 and m != 5:
+                a = r.randint(0,10)
+                print"a=%d"%a
+                b = r.randint(1,10)
+                print"b=%d"%b
+                #Zufallszahlen 1--Add,2--Sub,3--Mul
+                R=r.randint(1,3)
+                if R==1:
+                    print"a + b ="
+                    c = a + b
+                elif R==2:
+                    print"a - b ="
+                    c=a-b
+                else:
+                    print"a * b ="
+                    c=a*b
+                e = int(raw_input("Ergbnis ist "))
+                n = n + 1
+                #Validierung,ob das Egebnis richtig ist
+                if e == c:
+                    print"Gut!Sie haben recht!"
+                    m = m + 1
+                else:
+                    print"falsches Ergenis!"
+            elif n == 5 and m != 5:
+                print'''
+Sie haben alle Aufgaben fertig!
+Aber nicht alle recht!
+Y -------> Try again
+N -------> Give up and no high-score'''
+                waehlen = str(raw_input())
+                if waehlen == 'y'or waehlen == 'Y':
+                    n = 0
+                    m = 0
+                elif waehlen == 'n'or waehlen == 'N':
+                    break
+        antwort = None   
+    
+    elif antwort == 'a'or antwort == 'A':
+        #High Score anzeigen
+        file3 = open("high_score.txt","r")
+        read1 = file3.read()
+        print read1
+        antwort = None
+    
+    elif antwort == 'c'or antwort == 'C':
+        #Bereits exitierende Spieler anzeigen
+        file4 = open("spieler.txt","r")
+        read2 = file4.read()
+        print read2
+        antwort = None
+    
+    elif antwort == 'd'or antwort == 'D':
+        #Spieler verlassen
+        break
+    
+    else:
+        #Fehler Eingabe melden
+        print'''
+Ungueltige Eingabe!
+Waehlen Sie Ihre Option!'''
+#Programme Ende
+exit()

BIN
Programmierung1_PVL/spieler.txt