這篇文章主要講解了python如何實(shí)現(xiàn)撲克牌交互式界面發(fā)牌程序,內(nèi)容清晰明了,對(duì)此有興趣的小伙伴可以學(xué)習(xí)一下,相信大家閱讀完之后會(huì)有幫助。
站在用戶的角度思考問題,與客戶深入溝通,找到河曲網(wǎng)站設(shè)計(jì)與河曲網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:成都網(wǎng)站設(shè)計(jì)、網(wǎng)站制作、外貿(mào)營(yíng)銷網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、空間域名、網(wǎng)絡(luò)空間、企業(yè)郵箱。業(yè)務(wù)覆蓋河曲地區(qū)。注:圖片自行在網(wǎng)上下載、替換即可
#coding=utf-8 class Card(): #撲克牌類 points=['1','2','3','4','5','6','7','8','9','10','11','12','13'] suits=['1','2','3','4'] #花色 def __init__(self,points,suits): self.points=points self.suits=suits def __str__(self): rep=self.suits+'-'+self.points return rep class Hand(): def __init__(self): self.cards=[] def add(self,card): self.cards.append(card) def __str__(self): rep='' for card in self.cards: rep+=str(card)+'\t' return rep class Poke(Hand): def generate_poke(self): for point in Card.points: for suit in Card.suits: self.add(Card(point,suit)) def random_poke(self): import random random.shuffle(self.cards) def deal(self,hands,limit_hand=13): for rounds in range (limit_hand): for hand in hands: if self.cards: top=self.cards[0] self.cards.remove(top) hand.add(top) def print_poke(players): results=[player.__str__() for player in players] pk=[] for result in results: pk1=result.rstrip() pk2=pk1.split('\t') pk.append(pk2) image_name=[] for i in range(len(pk)): for j in pk[i]: str_name='D:\pukepai\images\\{}.gif'.format(j) image_name.append(str_name) wj=[image_name[i:i+13] for i in range(len(image_name)) if i%13==0] return wj def restart(): tk.messagebox.showinfo("hello python","sdfg") players=[Hand(),Hand(),Hand(),Hand()] pockers=Poke() pockers.generate_poke() pockers.random_poke() pockers.deal(players,13) wj=print_poke(players) import tkinter as tk win=tk.Tk() win.title("撲克牌程序") win.geometry('800x600') cv=tk.Canvas(win,bg='red',width=800,height=600) from PIL import Image,ImageTk imgs=[] (p1,p2,p3,p4)=([],[],[],[]) for i in range(4): for j in range(13): img=Image.open(wj[i][j]) imgs.insert(i*13+j,ImageTk.PhotoImage(img)) p1=imgs[0:13] p2=imgs[13:26] p3=imgs[26:39] p4=imgs[39:52] for x in range(0,13): cv.create_image((200+20*x,80),image=p1[x]) cv.create_image((100,150+20*x),image=p2[x]) cv.create_image((200+20*x,500),image=p3[x]) cv.create_image((560,150+20*x),image=p4[x]) #添加重新發(fā)牌按鈕 from tkinter.messagebox import * bt1=tk.Button(win,text='重新發(fā)牌',width=60,height=40,command=restart) bt1.place(x=290,y=380,width=60,height=40) cv.pack() win.mainloop()
網(wǎng)站名稱:python如何實(shí)現(xiàn)撲克牌交互式界面發(fā)牌程序-創(chuàng)新互聯(lián)
文章位置:http://jinyejixie.com/article44/ghohe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制開發(fā)、網(wǎng)站設(shè)計(jì)、App設(shè)計(jì)、動(dòng)態(tài)網(wǎng)站、微信公眾號(hào)、品牌網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容