日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python写斗地主游戏_基于python的简单斗地主实现-Go语言中文社区

發(fā)布時間:2023/12/10 python 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python写斗地主游戏_基于python的简单斗地主实现-Go语言中文社区 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

import random

class Poke:

pokes=[] #初始牌堆

player1=[]#三個玩家的牌

player2=[]

player3=[]

last_poke=None #底牌

def __init__(self,flower,num):

self.flower=flower

self.num=num

def __str__(self):

return "%s%s"%(self.flower,self.num)

#1.初始化牌

@classmethod

def init_poke(cls):

flowers=("?","?","?","?") #四種花色

nums=("2","3","4","5","6","7","8","9","10","J","Q","K","A") #14個數字牌

kings={"big":"大王","small":"小王"} #大小王

for flower_ in flowers:#四種花色每一種分別與14個數字進行組合

for num_ in nums:

p=Poke(flower_,num_) #產生撲克牌對象

cls.pokes.append(p) #將撲克牌對象添加到撲克牌列表中

cls.pokes.append(Poke(kings["big"],"")) #將大小王添加到撲克牌列表中

cls.pokes.append(Poke(kings["small"],""))

#2.洗牌

@classmethod

def wash_poke(cls):

for idx in range(0,54): #54張牌,列表的索引從0到53

idxx=random.randint(0,53)#調用隨機函數,隨機產生0~53的數字

cls.pokes[idx],cls.pokes[idxx]=cls.pokes[idxx],cls.pokes[idx] #進行交換牌

#3.發(fā)牌

@classmethod

def send_poke(cls):

for _ in range(0,17): #產生三個玩家的牌

cls.player1.append(cls.pokes.pop(0)) #每個玩家獲得17張牌

cls.player2.append(cls.pokes.pop(0))

cls.player3.append(cls.pokes.pop(0))

cls.last_poke=tuple(cls.pokes) #三張底牌

#4.展示牌

@classmethod

def show(cls,i,p):

print(p,end=": ")

for poke in i: #遍歷撲克牌

print(poke,end="")

print()

#展示玩家的牌

@classmethod

def show_player(cls): #調用show()方法展示三個玩家和底牌

cls.show(cls.player1,"玩家1")

cls.show(cls.player2,"玩家2")

cls.show(cls.player3,"玩家3")

cls.show(cls.last_poke,"底牌")

Poke.init_poke()

Poke.wash_poke()

Poke.send_poke()

Poke.show_player()

代碼運行結果:

總結

以上是生活随笔為你收集整理的python写斗地主游戏_基于python的简单斗地主实现-Go语言中文社区的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。