|
发表于 2023-10-25 20:42:33
From FishC Mobile
|
显示全部楼层
|阅读模式
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#我定义一个更新精灵位置的函数updatp,但是鼠标点击后#不会变,一直搞不懂
import pygame
import random
class Nm():
def __init__(self):
self.pa=[None]*17
class Dz(Nm):
def __init__(self):
self.pa=[None]*20
def funa():
num1=["黑桃","梅花","红心","方块"]
num2=['3','4','5','6','7','8','9','10','J','Q','K','A','2']
nums=[None]*54
kls=0
for i in num1:
for j in num2:
nums[kls]=i+j
kls+=1
nums[52]="大鬼"
nums[53]="小鬼"
return nums
def funb(nm1,nm2,dz,nums):
kls=0
while kls<17:
card1 = random.choice(nums)
if card1 in nums:
nm1.pa[kls]=card1
nums.remove(card1)
card2 = random.choice(nums)
if card2 in nums:
nm2.pa[kls]=card2
nums.remove(card2)
card3 = random.choice(nums)
if card3 in nums:
dz.pa[kls]=card3
nums.remove(card3)
kls += 1
kls = 17
while kls < 20:
card4 = random.choice(nums)
if card4 in nums:
dz.pa[kls]=card4
nums.remove(card4)
kls += 1
class Zhipai(pygame.sprite.Sprite):
def __init__(self,name,x_l,y_l=440):
super().__init__()
self.image=pygame.image.load(name)
self.rect=self.image.get_rect()
self.rect.x=x_l*240
self.rect.y=y_l
def updatp(self):
self.rect.y-=100
def main():
nums=funa() #定义总牌
nm1=Nm()
nm2=Nm()
dz=Dz()
funb(nm1,nm2,dz,nums) #随机给三个人发牌
pygame.init()
clock=pygame.time.Clock()
screen = pygame.display.set_mode((960,640))
pg=pygame.image.load("C:/Users/86184/Desktop/新建文件夹/doul.png")
pl_1=Zhipai("C:/Users/86184/Desktop/新建文件夹/dour.png",1)
pl_2=Zhipai("C:/Users/86184/Desktop/新建文件夹/dour.png",2)
pl_3=Zhipai("C:/Users/86184/Desktop/新建文件夹/dour.png",3)
screen.blit(pg,(0,0))
enemy_group=pygame.sprite.Group(pl_1,pl_2,pl_3)
running=True
while running:
clock.tick(60)
for event_ in pygame.event.get():
if event_.type==pygame.QUIT:
running=False
elif event_!=None:
print(event_)
elif event_.type==pygame.MOUSEBUTTONDOWN:
pos=pygame.mouse.get_pos()
if pos[0]>=480 and pos[0]<=480+60 and pos[1]>=440 and pos[1]<=440+78:
pl_2.updatp()
screen.blit(pg,(0,0))
enemy_group.draw(screen)
pygame.display.update()
pygame.quit()
print(nm1.pa)
print(nm2.pa)
print(dz.pa)
exit()
if __name__=="__main__":
mgs=main() |
|