2016-03-19 30 views
-1

Zaferler/kayıplar için bir nokta sistemi uygulamaya çalışırken python'da bir taş kağıt makas oyunu yapmaya çalışıyorum. Kodu çalıştırdığımda, kaya kağıt veya makas seçmem istenir, cevabımı seçerim ama sonra tekrar sorulur, birileri bana yardım edebilir mi? size sorar ve sonra tekrar diyoruz ve sonucu atamak Python kodu iki kez çalıştırılıyor

genUserMove() 
UserMove = genUserMove() 

İlk çağrı genUserMove: Bu dizelerde

from random import randint 
def RPS(): 
    UserPts = 0 
    AIPts = 0 
    def Game(): 
     moves = ["Rock","Paper","Scissors"] 
     def genAImove(): 
      genai = moves[randint(0,2)] 
      return genai 
     genAImove() 
     AImove = genAImove() 
     def genUserMove(): 
      genu = raw_input("Choose your move ('Rock','Paper' or 'Scissors')\n") 
      return genu 
     genUserMove() 
     UserMove = genUserMove()   
     if UserMove == "Rock" and AImove == "Rock": 
      print "The AI chose rock too.\nDraw." 
      def cont(): 
       cnt = raw_input("Do you want to continue? (Y\N)") 
       if cnt == "Y": 
        Game() 
       elif cnt == "N": 
        exit 
       else: 
        print "Pick Y or N" 
        cont() 
      cont() 
     if UserMove == "Rock" and AImove == "Paper": 
      print "The AI chose paper.\nLoss." 

      def cont(): 
       cnt = raw_input("Do you want to continue? (Y\N)") 
       if cnt == "Y": 
        Game() 
       elif cnt == "N": 
        exit 
       else: 
        print "Pick Y or N" 
        cont() 
      cont() 
     if UserMove == "Rock" and AImove == "Scissors": 
      print "The AI chose scissors.\nWin." 

      def cont(): 
       cnt = raw_input("Do you want to continue? (Y\N)") 
       if cnt == "Y": 
        Game() 
       elif cnt == "N": 
        exit 
       else: 
        print "Pick Y or N" 
        cont() 
      cont() 
     if UserMove == "Paper" and AImove == "Rock": 
      print "The AI chose rock.\nWin." 

      def cont(): 
       cnt = raw_input("Do you want to continue? (Y\N)") 
       if cnt == "Y": 
        Game() 
       elif cnt == "N": 
        exit 
       else: 
        print "Pick Y or N" 
        cont() 
      cont() 
     if UserMove == "Paper" and AImove == "Paper": 
      print "The AI chose paper.\nDraw." 

      def cont(): 
       cnt = raw_input("Do you want to continue? (Y\N)") 
       if cnt == "Y": 
        Game() 
       elif cnt == "N": 
        exit 
       else: 
        print "Pick Y or N" 
        cont() 
      cont() 
     if UserMove == "Paper" and AImove == "Scissors": 
      print "The AI chose scissors.\nLoss." 

      def cont(): 
       cnt = raw_input("Do you want to continue? (Y\N)") 
       if cnt == "Y": 
        Game() 
       elif cnt == "N": 
        exit 
       else: 
        print "Pick Y or N" 
        cont() 
      cont() 
     if UserMove == "Scissors" and AImove == "Rock": 
      print "The AI chose rock.\nLoss." 

      def cont(): 
       cnt = raw_input("Do you want to continue? (Y\N)") 
       if cnt == "Y": 
        Game() 
       elif cnt == "N": 
        exit 
       else: 
        print "Pick Y or N" 
        cont() 
      cont() 
     if UserMove == "Scissors" and AImove == "Paper": 
      print "The AI chose paper.\nWin." 

      def cont(): 
       cnt = raw_input("Do you want to continue? (Y\N)") 
       if cnt == "Y": 
        Game() 
       elif cnt == "N": 
        exit 
       else: 
        print "Pick Y or N" 
        cont() 
      cont() 
     if UserMove == "Scissors" and AImove == "Scissors": 
      print "The AI chose scissors.\nDraw." 

      def cont(): 
       cnt = raw_input("Do you want to continue? (Y\N)") 
       if cnt == "Y": 
        Game() 
       elif cnt == "N": 
        exit 
       else: 
        print "Pick Y or N" 
        cont() 
      cont() 
    Game() 
RPS() 

cevap

2

(hemen hemen bir acemi değilim).

Sadece ilk satırı kaldırın.

+0

Hızlı yanıt için çok teşekkür ederim, sorunumu çözdü. Aşırı karmaşıklık yaptım çünkü küresel değişkenlerin gerçekten nasıl çalıştığını bilmiyordum, bu yüzden bir fonksiyonda bir işlev yaptım ama aynı küresel değişken problemi ile karşılaştım, biraz daha araştırdım ve hatalarımı gerçekleştirdim ve şimdi oyunum işlevsel Gerekirse çok daha fazla kod ile, aynı zamanda puan ile. – dragoljub