第一次给老婆写个脚本游戏,这要是在上学的时候该有多好:)
1 #!/usr/bin/python 2 # -*- coding: utf-8 -*- 3 from random import choice 4 import time 5 6 ua = [] 7 ub = [] 8 l = [] 9 10 def main(): 11 fapai() 12 print ua 13 print ub 14 run() 15 16 def run(): 17 print '游戏开始' 18 while True: 19 r = uaGO() 20 while r: 21 r = uaGO() 22 #pass 23 r2 = ubGO() 24 while r2: 25 r2 = ubGO() 26 #pass 27 if len(ua) == 0: 28 print '老公赢了,媳妇哭了' 29 break 30 if len(ub) == 0: 31 print '媳妇赢了,老公哭了T_T' 32 break 33 print '当前拖拉机', l 34 print '老公手牌', ua 35 print '媳妇手牌', ub 36 time.sleep(1) 37 38 def uaGO(): 39 global l 40 val = ua[0] 41 ua.remove(val) 42 try: 43 n = l.index(val) 44 l.append(val) 45 line = l[n:] 46 l = l[:n] 47 print '老公拿到 ', line 48 ua.extend(line) 49 return True 50 except: 51 print l 52 l.append(val) 53 print '老公出牌', val 54 return False 55 56 def ubGO(): 57 global l 58 val = ub[0] 59 ub.remove(val) 60 try: 61 n = l.index(val) 62 l.append(val) 63 line = l[n:] 64 l = l[:n] 65 print '媳妇拿牌 ', line 66 ub.extend(line) 67 return True 68 except: 69 l.append(val) 70 print '媳妇出牌', val 71 return False 72 73 def fapai(): 74 puke = [] 75 puke = range(1, 14) * 4 76 77 while puke: 78 v = choice(puke) 79 if len(puke) % 2 == 0: 80 ua.append(v) 81 else: 82 ub.append(v) 83 puke.remove(v) 84 85 if __name__ == '__main__': 86 main()
[4, 7, 1]
老公出牌 8
媳妇出牌 13
当前拖拉机 [4, 7, 1, 8, 13]
老公手牌 [8, 5, 5, 4, 6, 13, 11, 10, 2, 12, 8, 5, 4, 1, 3, 2, 1, 7, 6, 8, 11, 12, 7, 10, 3, 5, 10, 2, 7, 6, 9, 3, 12, 1, 2, 9, 13, 12, 6, 9]
媳妇手牌 [11, 10, 9, 3, 4, 13, 11]
老公拿到 [8, 13, 8]
[4, 7, 1]
老公出牌 5
媳妇出牌 11
当前拖拉机 [4, 7, 1, 5, 11]
老公手牌 [5, 4, 6, 13, 11, 10, 2, 12, 8, 5, 4, 1, 3, 2, 1, 7, 6, 8, 11, 12, 7, 10, 3, 5, 10, 2, 7, 6, 9, 3, 12, 1, 2, 9, 13, 12, 6, 9, 8, 13, 8]
媳妇手牌 [10, 9, 3, 4, 13, 11]
老公拿到 [5, 11, 5]
老公拿到 [4, 7, 1, 4]
[]
老公出牌 6
媳妇出牌 10
当前拖拉机 [6, 10]
老公手牌 [13, 11, 10, 2, 12, 8, 5, 4, 1, 3, 2, 1, 7, 6, 8, 11, 12, 7, 10, 3, 5, 10, 2, 7, 6, 9, 3, 12, 1, 2, 9, 13, 12, 6, 9, 8, 13, 8, 5, 11, 5, 4, 7, 1, 4]
媳妇手牌 [9, 3, 4, 13, 11]
[6, 10]
老公出牌 13
媳妇出牌 9
当前拖拉机 [6, 10, 13, 9]
老公手牌 [11, 10, 2, 12, 8, 5, 4, 1, 3, 2, 1, 7, 6, 8, 11, 12, 7, 10, 3, 5, 10, 2, 7, 6, 9, 3, 12, 1, 2, 9, 13, 12, 6, 9, 8, 13, 8, 5, 11, 5, 4, 7, 1, 4]
媳妇手牌 [3, 4, 13, 11]
[6, 10, 13, 9]
老公出牌 11
媳妇出牌 3
当前拖拉机 [6, 10, 13, 9, 11, 3]
老公手牌 [10, 2, 12, 8, 5, 4, 1, 3, 2, 1, 7, 6, 8, 11, 12, 7, 10, 3, 5, 10, 2, 7, 6, 9, 3, 12, 1, 2, 9, 13, 12, 6, 9, 8, 13, 8, 5, 11, 5, 4, 7, 1, 4]
媳妇手牌 [4, 13, 11]
老公拿到 [10, 13, 9, 11, 3, 10]
[6]
老公出牌 2
媳妇出牌 4
当前拖拉机 [6, 2, 4]
老公手牌 [12, 8, 5, 4, 1, 3, 2, 1, 7, 6, 8, 11, 12, 7, 10, 3, 5, 10, 2, 7, 6, 9, 3, 12, 1, 2, 9, 13, 12, 6, 9, 8, 13, 8, 5, 11, 5, 4, 7, 1, 4, 10, 13, 9, 11, 3, 10]
媳妇手牌 [13, 11]
[6, 2, 4]
老公出牌 12
媳妇出牌 13
当前拖拉机 [6, 2, 4, 12, 13]
老公手牌 [8, 5, 4, 1, 3, 2, 1, 7, 6, 8, 11, 12, 7, 10, 3, 5, 10, 2, 7, 6, 9, 3, 12, 1, 2, 9, 13, 12, 6, 9, 8, 13, 8, 5, 11, 5, 4, 7, 1, 4, 10, 13, 9, 11, 3, 10]
媳妇手牌 [11]
[6, 2, 4, 12, 13]
老公出牌 8
媳妇出牌 11
媳妇赢了,老公哭了T_T