pythonシンプルなゲームを実現

8092 ワード

pythonシンプルなゲームを実現
import random  #       
import sys  #                    

"""
1.     :  4*9   ,4*9  ,4*9   ,4*7  
                 ,       * 4     
          。
2.  :  for     ,               
       
3.  :  for  ,    52     ,      
         
4.  :            tablet[0]       
         ,         ,    ,    
            del play_5[   - 1]       
      ;        3      ,       
           ,      ,          
       ,     ,    ,          
      del play_5[   - 1]       。
      ;        2      ,       
           ,      ,     ,    ,
                del play_5[   - 1]     
      。
             。
"""
#          
play_1 = []
play_2 = []
play_3 = []
play_4 = []
play_1_need = []
play_2_need = []
play_3_need = []
play_4_need = []
poke = []
need_poke = []


class PlayGame:

    def initialize(self): #    
        bobbin = ['1 ', '2 ', '3 ', '4 ', '5 ', '6 ', '7 ', '8 ', '9 ']
        miriade = ['1 ', '2 ', '3 ', '4 ', '5 ', '6 ', '7 ', '8 ', '9 ']
        strip = ['1 ', '2 ', '3 ', '4 ', '5 ', '6 ', '7 ', '8 ', '9 ']
        wind = [' ', ' ', ' ', ' ', ' ', ' ',' ']
        tablet = bobbin * 4 + miriade * 4 + strip * 4 + wind * 4
        return tablet


    def shuffle(self,tablet):  #   
        for i in range(0,20000): #       ,    20000 
            x = random.randint(0, 135) #       
            y = random.randint(0, 135)
            #         
            t = tablet[x]
            tablet[x] = tablet[y]
            tablet[y] = t
        return tablet

    def deal(self, tablet):  #   
        global play_1
        global play_2
        global play_3
        global play_4
        for i in range(0, 52, 4): #    13  
             play_1.append(tablet[i])
             play_2.append(tablet[i+1])
             play_3.append(tablet[i+2])
             play_4.append(tablet[i+3])
            #           
        def my_key2(x):
            return x[-1]
        play_1.sort()  #      
        play_1.sort(key=my_key2) #      
        play_2.sort()
        play_2.sort(key=my_key2)
        play_3.sort()
        play_3.sort(key=my_key2)
        play_4.sort()
        play_4.sort(key=my_key2)
        #     52    
        del tablet[0:52]
        return tablet

    def draw(self,tablet):
        global play_1
        global play_2
        global play_3
        global play_4
        i = []
        while len(tablet) > 0: #        0,      
            for x in range(1, 5): #                  
                if x == 1:
                    play_5 = play_1
                    play_5_need = play_1_need
                if x == 2:
                    play_5 = play_2
                    play_5_need = play_2_need
                if x == 3:
                    play_5 = play_3
                    play_5_need = play_3_need
                if x == 4:
                    play_5 = play_4
                    play_5_need = play_4_need
                play_5.append(tablet[0])  #                
                # play_5 = [' ', ' ', ' ',' ', ' ', ' ', ' ',' ', ' ', ' ', ' ',' ', ' ', ' ']
                # def my_key2(x):
                #     return x[-1]
                # play_5.sort()
                # play_5.sort(key=my_key2)
                play_5_need = i  #            

                def my_key2(x):  #         ,    
                    return x[-1]
                play_5.sort()
                play_5.sort(key=my_key2)
                print("  %d   :%s   %s" %(x, play_5,play_5_need))  #       
                success = input("    ?(“*”    )")   #           
                if success == "*":
                    def my_key2(x):  #         ,    
                        return x[-1]
                    play_5.sort()
                    play_5.sort(key=my_key2)
                    print(play_5,play_5_need)
                    print("     ,    ")
                    tablet.clear()
                    sys.exit(0)  #     ,       
                play_poker = int(input("         :"))
                while play_poker > len(play_5):   #                  ,     ,      
                    play_poker = int(input("        ,     :"))
                poke = play_5[play_poker - 1]  #          ,          
                del play_5[play_poker - 1] #      
                for x in range(1, 5):
                    if x == 1:
                        play_6 = play_1
                    if x == 2:
                        play_6 = play_2
                    if x == 3:
                        play_6 = play_3
                    if x == 4:
                        play_6 = play_4
                    if play_6.count(poke) == 3:  #       3     ,           
                        print("%s,%s   ?" %(poke,str(play_6)))
                        i_need = int(input("(1 ,0  ):"))
                        if i_need == 1:
                            play_6.append(tablet[-1])  #          
                            play_6.remove(poke)  #      3    
                            play_6.remove(poke)
                            play_6.remove(poke)
                            print(play_6)
                            play_5_need.append(poke * 4)  #  4      ,       
                            success = input("    ?(“*”    )")  #           
                            if success == "*":
                                def my_key2(x):  #         ,    
                                    return x[-1]

                                play_5.sort()
                                play_5.sort(key=my_key2)
                                print(play_5, play_5_need)
                                print("     ,    ")
                                sys.exit(0)
                            i_disneed = int(input("          :"))
                            while i_disneed > len(play_6):
                                i_disneed = int(input("        ,     "))
                            del play_6[i_disneed-1]
                    if play_6.count(poke) >= 2: #       2     ,           
                        print("%s,%s   ?" %(poke,str(play_6)))
                        i_need = int(input("(1 ,0  ):"))
                        if i_need == 1:  #     
                            play_6.remove(poke)  #         
                            play_6.remove(poke)
                            play_5_need.append(poke * 3)  #  3              
                            print(play_5_need)
                            print(play_6)
                            success = input("    ?(“*”    )")  #           
                            if success == "*":
                                def my_key2(x):  #         ,    
                                    return x[-1]

                                play_5.sort()
                                play_5.sort(key=my_key2)
                                print(play_5, play_5_need)
                                print("     ,    ")
                                sys.exit(0)
                            i_disneed = int(input("          :"))
                            while i_disneed > len(play_6):
                                i_disneed = int(input("        ,     "))
                            del play_6[i_disneed-1]
                del tablet[0]

                def my_key2(x):
                    return x[-1]
                play_5.sort()
                play_5.sort(key=my_key2)
        print("game over")


def main():
    playgame = PlayGame()  #        
    tablet = playgame.initialize()  #      
    playgame.shuffle(tablet)  #    
    playgame.deal(tablet)  #    
    playgame.draw(tablet)
main()