编程知识 购物 网址 新闻 笑话 | 软件 日历 阅读 图书馆 China
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
vbs/VBScript DOS/BAT hta htc python perl 游戏相关 VBA 远程脚本 ColdFusion ruby专题 autoit seraphzone PowerShell linux shell Lua Golang Erlang 其它教程 CSS/HTML/Xhtml html5 CSS XML/XSLT Dreamweaver教程 经验交流
站长资讯 .NET新手 ASP.NET C# WinForm Silverlight WCF CLR WPF XNA VisualStudio ASP.NET-MVC .NET控件开发 EntityFramework WinRT-Metro Java C++ PHP Delphi Python Ruby C语言 Erlang Go Swift Scala R语言 Verilog 其它语言 架构设计 面向对象 设计模式 领域驱动 Html-Css JavaScript jQuery HTML5 SharePoint GIS技术 SAP OracleERP DynamicsCRM K2 BPM 信息安全 企业信息 Android开发 iOS开发 WindowsPhone WindowsMobile 其他手机 敏捷开发 项目管理 软件工程 SQLServer Oracle MySQL NoSQL 其它数据库 Windows7 WindowsServer Linux
   -> 领域驱动设计 -> 斗地主3 -> 正文阅读

[领域驱动设计]斗地主3


#coding=utf8
import random,time
endcards=[]
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 randDZ():
global player1,player2,player3
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

#判断牌型
def cardtype(delplayer):
cardnums=len(delplayer)
while cardnums<=4:
if cardnums == 1:
print "玩家出的单牌是:%s" % delplayer[0]
break
elif cardnums == 2:
if cardlist2[delplayer[0]] == cardlist2[delplayer[1]]:
print "玩家出的对%s" %delplayer[0]
break
elif cardnums == 3:
if cardlist2[delplayer[0]] == cardlist2[delplayer[1]] == cardlist2[delplayer[2]]:
print "玩家出的三张%s" %delplayer[0]
break
elif cardnums == 4:
if cardlist2[delplayer[0]] == cardlist2[delplayer[1]] == cardlist2[delplayer[2]]==cardlist2[delplayer[3]]:
print "玩家出了炸%s" %delplayer[0]
break
else:
raw_input()

#打牌
def dapai():
global endcards
print " 开始打牌,打牌顺序为玩家1>玩家2>玩家3轮流"
while len(player1)>0 and len(player2)>0 and len(player3)>0:
if len(endcards) > 0:
print "玩家1开始打牌"
print "玩家1的牌是:%s" % player1
delplayer1 = raw_input("请选择玩家1要出的牌:").split(" ")
if len(endcards)==1 and len(delplayer1)==len(endcards) and cardlist2[delplayer1[0]]>cardlist2[endcards[0]]:
print "玩家出了单张%s"%delplayer1[0]
for i in range(len(delplayer1)): # 每次出的牌从原先的牌删除
player1.remove(delplayer1[i])
elif len(endcards)==2 and len(delplayer1)==len(endcards) and cardlist2[delplayer1[0]]>cardlist2[endcards[0]] and cardlist2[delplayer1[0]]==cardlist2[delplayer1[1]]:
print "玩家2出了对%s"%delplayer1[0]
for i in range(len(delplayer1)): # 每次出的牌从原先的牌删除
player1.remove(delplayer1[i])
elif len(endcards)==3 and len(delplayer1)==len(endcards) and cardlist2[delplayer1[0]]>cardlist2[endcards[0]] and cardlist2[delplayer1[0]] == cardlist2[delplayer1[1]] == cardlist2[delplayer1[2]]:
print "玩家2出了三张%s"%delplayer1[0]
for i in range(len(delplayer1)): # 每次出的牌从原先的牌删除
player1.remove(delplayer1[i])
elif len(endcards)==4 and len(delplayer1)==len(endcards) and cardlist2[delplayer1[0]]>cardlist2[endcards[0]] and cardlist2[delplayer1[0]] == cardlist2[delplayer1[1]] == cardlist2[delplayer1[2]]==cardlist2[delplayer1[3]]:
print "玩家2出了四张%s"%delplayer1[0]
for i in range(len(delplayer1)): # 每次出的牌从原先的牌删除
player1.remove(delplayer1[i])
else:
pass
del endcards[:]
if (len(player1) == 0):
print "玩家1为赢家,游戏结束"
break
print "玩家2开始出牌"
print "玩家2的牌是:%s" % player2
delplayer2= raw_input("请选择玩家2要出的牌:").split(" ")
if len(delplayer1)==1 and len(delplayer1)==len(delplayer2) and cardlist2[delplayer2[0]]>cardlist2[delplayer1[0]]:
print "玩家出了单张%s"%delplayer2[0]
for i in range(len(delplayer2)): # 每次出的牌从原先的牌删除
player2.remove(delplayer2[i])
elif len(delplayer1)==2 and len(delplayer1)==len(delplayer2) and cardlist2[delplayer2[0]]>cardlist2[delplayer1[0]] and cardlist2[delplayer2[0]]==cardlist2[delplayer2[1]]:
print "玩家2出了对%s"%delplayer2[0]
for i in range(len(delplayer2)): # 每次出的牌从原先的牌删除
player2.remove(delplayer2[i])
elif len(delplayer1)==3 and len(delplayer1)==len(delplayer2) and cardlist2[delplayer2[0]]>cardlist2[delplayer1[0]] and cardlist2[delplayer2[0]] == cardlist2[delplayer2[1]] == cardlist2[delplayer2[2]]:
print "玩家2出了三张%s"%delplayer2[0]
for i in range(len(delplayer2)): # 每次出的牌从原先的牌删除
player2.remove(delplayer2[i])
elif len(delplayer1)==4 and len(delplayer1)==len(delplayer2) and cardlist2[delplayer2[0]]>cardlist2[delplayer1[0]] and cardlist2[delplayer2[0]] == cardlist2[delplayer2[1]] == cardlist2[delplayer2[2]]==cardlist2[delplayer2[3]]:
print "玩家2出了四张%s"%delplayer2[0]
for i in range(len(delplayer2)): # 每次出的牌从原先的牌删除
player2.remove(delplayer2[i])
else:
pass
del delplayer2[:]
if (len(player2) == 0):
print "玩家2为赢家,游戏结束"
break
print "玩家3开始出牌"
print "玩家3的牌是:%s" % player3
delplayer3 = raw_input("请选择玩家3要出的牌:").split(" ")
if len(delplayer2)==1 and len(delplayer2)==len(delplayer3) and cardlist2[delplayer3[0]]>cardlist2[delplayer2[0]]:
print "玩家出了单张%s"%delplayer3[0]
for i in range(len(delplayer3)): # 每次出的牌从原先的牌删除
player3.remove(delplayer3[i])
elif len(delplayer2)==2 and len(delplayer2)==len(delplayer3) and cardlist2[delplayer3[0]]>cardlist2[delplayer2[0]] and cardlist2[delplayer3[0]]==cardlist2[delplayer3[1]]:
print "玩家2出了对%s"%delplayer3[0]
for i in range(len(delplayer3)): # 每次出的牌从原先的牌删除
player3.remove(delplayer3[i])
elif len(delplayer2)==3 and len(delplayer2)==len(delplayer3) and cardlist2[delplayer3[0]]>cardlist2[delplayer2[0]] and cardlist2[delplayer3[0]] == cardlist2[delplayer3[1]] == cardlist2[delplayer3[2]]:
print "玩家2出了三张%s"%delplayer3[0]
for i in range(len(delplayer3)): # 每次出的牌从原先的牌删除
player3.remove(delplayer3[i])
elif len(delplayer2)==4 and len(delplayer2)==len(delplayer3) and cardlist2[delplayer3[0]]>cardlist2[delplayer2[0]] and cardlist2[delplayer3[0]] == cardlist2[delplayer3[1]] == cardlist2[delplayer3[2]]==cardlist2[delplayer3[3]]:
print "玩家2出了四张%s"%delplayer3[0]
for i in range(len(delplayer3)): # 每次出的牌从原先的牌删除
player3.remove(delplayer3[i])
else:
pass
endcards=delplayer3
del delplayer3[:]
if (len(player3) == 0):
print "玩家3为赢家,游戏结束"
continue

#发牌,指定玩家1,玩家2,玩家3
def deal():
print " 开始洗牌!"
myshuffle()
print "loading..............."
time.sleep(3)
print " 洗牌完毕"
print
print " 开始发牌!"
print "loading................"
time.sleep(5)
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 " 发牌完毕,开始随机地主。"
randDZ()
dapai()


deal()

  领域驱动设计 最新文章
领域驱动设计的基础知识总结
海西 · 云交付 DevOps实践落地方案
多服务器终端交互利器
《静儿的服务治理私房菜》服务治理和架构
服务治理概述
美团.点评服务治理框架
ASP.NET Zero
1.领域驱动简介.2.领域.子域.限界上下文.3.
东麓庄园系统开发
东麓庄园系统开发
上一篇文章           查看所有文章
加:2017-09-08 23:24:43  更:2017-09-08 23:24:45 
 
360图书馆 软件开发资料 购物精选 新闻资讯 Chinese Culture 三丰软件 开发 中国文化 阅读网 日历 万年历 2019年12日历
2019-12-9 21:32:39
多播视频美女直播
↓电视,电影,美女直播,迅雷资源↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  编程知识