#coding=utf8import random,sys,time# def randDZ():# DZ=random.randint(1,3)# if DZ==1:# print "玩家1是地主"# player1=player1+sancards# for i in range(0, 20):# for j in range(i + 1, 20):# if cardlist2[player1[i]] < cardlist2[player1[j]]:# player1[i], player1[j] = player1[j], player1[i]# print "地主的牌是:%s"%player1# elif DZ==2:# print "玩家2是地主"# player2 = player2 + sancards# for i in range(0, 20):# for j in range(i + 1, 20):# if cardlist2[player2[i]] < cardlist2[player2[j]]:# player2[i], player2[j] = player2[j], player2[i]# print "地主的牌是:%s" % player2# else:# print "玩家3是地主"# player3 = player3 + sancards# for i in range(0, 20):# for j in range(i + 1, 20):# if cardlist2[player3[i]] < cardlist2[player3[j]]:# player3[i], player3[j] = player3[j], player3[i]# print "地主的牌是:%s" % player3 cardlist1=[ "spade1", "club1", "heart1", "diamond1", "spade2","club2","heart2","diamond2","spade3","club3","heart3","diamond3", "spade4", "club4", "heart4", "diamond4", "spade5","club5","heart5","diamond5","spade6","club6","heart6","diamond6", "spade7", "club7", "heart7", "diamond7", "spade8","club8","heart8","diamond8","spade9","club9","heart9","diamond9", "spade10","club10","heart10","diamond10","spadeJ","clubJ","heartJ","diamondJ","spadeQ","clubQ","heartQ","diamondQ", "spadeK", "clubK", "heartK", "diamondK", "queen","king" ] cardlist2={ "spade3":3, "club3":3, "heart3":3, "diamond3":3, "spade4":4, "club4":4, "heart4":4, "diamond4":4, "spade5":5, "club5":5, "heart5":5, "diamond5":5, "spade6":6, "club6":6, "heart6":6, "diamond6":6, "spade7":7, "club7":7, "heart7":7, "diamond7":7, "spade8":8, "club8":8, "heart8":8, "diamond8":8, "spade9":9, "club9":9, "heart9":9, "diamond9":9, "spade10":10,"club10":10,"heart10":10,"diamond10":10, "spadeJ":11,"clubJ":11,"heartJ":11,"diamondJ":11,"spadeQ":12, "clubQ":12, "heartQ":12,"diamondQ":12, "spadeK":13,"clubK":13,"heartK":13,"diamondK":13,"spade1":14, "club1":14, "heart1":14, "diamond1":14, "spade2":15,"club2":15,"heart2":15,"diamond2":15,"queen":16,"king":17 } def myshuffle(): random.shuffle(cardlist1) # def JDZ():# DZ = input("你是否要叫地主?y/n")# if DZ == ‘y‘:# DZcards = player1 + sancards# print "你现在是地主了,玩家2和3是农民"# print "三张底牌是:%s"%sancards# print "你的牌是:%s" % DZcards# print "玩家2的牌是:%s"%player2# print "玩家3的牌是:%s" %player3# else:# a = random.randint(0, 1)# if a == 0:# DZcards = player2 + sancards# print "三张底牌是:%s" % sancards# print "你的牌是:%s" % player1# print "玩家2叫地主,你和玩家3是农民"# print "玩家3的牌是:%s" % player3# print "地主家的牌是:%s"%DZcards# else:# DZcards = player3 + sancards# print "玩家3叫地主,你和玩家2是农民"# print "三张底牌是:%s" % sancards# print "你的牌是:%s" % player1# print "玩家2的牌是:%s" % player2# print "地主家的牌是:%s" % DZcards def deal(): print " 开始洗牌!" myshuffle() print "loading..............." time.sleep(3) print " 洗牌完毕" print print " 开始发牌!" global sancards sancards=random.sample(cardlist1,3) print "三张底牌是:%s"%sancards cardlist1.remove(sancards[0]),cardlist1.remove(sancards[1]),cardlist1.remove(sancards[2]) global player1 player1=random.sample(cardlist1,17)#将玩家1的牌重新按降序排列 for i in range(0,17): for j in range(i+1,17): if cardlist2[player1[i]]<cardlist2[player1[j]]: player1[i],player1[j]=player1[j],player1[i] print "玩家1的牌是:%s"%player1 for i in range(0,17): cardlist1.remove(player1[i]) global player2 player2=random.sample(cardlist1,17)# 将玩家2的牌重新按降序排列 for i in range(0,17): for j in range(i+1,17): if cardlist2[player2[i]]<cardlist2[player2[j]]: player2[i],player2[j]=player2[j],player2[i] print "玩家2的牌是:%s"%player2 for i in range(0,17): cardlist1.remove(player2[i]) global player3 player3=random.sample(cardlist1,17)# 将玩家3的牌重新按降序排列 for i in range(0, 17): for j in range(i + 1, 17): if cardlist2[player3[i]] < cardlist2[player3[j]]: player3[i], player3[j] = player3[j], player3[i] print "玩家3的牌是:%s"%player3 print "loading................" time.sleep(5) print " 发牌完毕,开始随机地主。" #开始随机地主, print "三张底牌是:%s"%sancards DZ = random.randint(1, 3) if DZ == 1: print "玩家1是地主,玩家2是农民,玩家3是农民" player1 = player1 + sancards for i in range(0, 20): for j in range(i + 1, 20): if cardlist2[player1[i]] < cardlist2[player1[j]]: player1[i], player1[j] = player1[j], player1[i] print "地主的牌是:%s" % player1 print "玩家2的牌是:%s" % player2 print "玩家3的牌是:%s" % player3 elif DZ == 2: print "玩家2是地主,玩家1是农民,玩家3是农民" player2 = player2 + sancards for i in range(0, 20): for j in range(i + 1, 20): if cardlist2[player2[i]] < cardlist2[player2[j]]: player2[i], player2[j] = player2[j], player2[i] print "地主的牌是:%s" % player2 print "玩家1的牌是:%s" % player1 print "玩家3的牌是:%s" % player3 elif DZ == 3: print "玩家3是地主,玩家1是农民,玩家2是农民" player3 = player3 + sancards for i in range(0, 20): for j in range(i + 1, 20): if cardlist2[player3[i]] < cardlist2[player3[j]]: player3[i], player3[j] = player3[j], player3[i] print "地主的牌是:%s" % player3 print "玩家1的牌是:%s" % player1 print "玩家2的牌是:%s" % player2 print "开始打牌,打牌顺序为玩家1>玩家2>玩家3轮流" while len(player1) > 0 and len(player2) > 0 and len(player3) > 0: if len(player1) > 0: print "玩家1开始打牌" print "玩家1的牌是:%s" % player1 delcards = raw_input("请选择玩家1要出的牌:").split(" ") # 每次出的牌从原先的牌删除 for i in range(len(delcards)): player1.remove(delcards[i]) del delcards[:] if (len(player1) == 0): print "玩家1为赢家,游戏结束" break print "玩家2开始出牌" print "玩家2的牌是:%s" % player2 delcards = raw_input("请选择玩家2要出的牌:").split(" ") for i in range(len(delcards)): player2.remove(delcards[i]) del delcards[:] if (len(player1) == 0): print "玩家2为赢家,游戏结束" break print "玩家3开始出牌" print "玩家3的牌是:%s" % player2 delcards = raw_input("请选择玩家3要出的牌:").split(" ") for i in range(len(delcards)): player3.remove(delcards[i]) del delcards[:] if (len(player1) == 0): print "玩家3为赢家,游戏结束" continue else: print "game over" deal()
时间: 2024-10-10 17:21:56