【游戏开发】初二时候一个人用pygame四个通宵写的万智牌

在这里插入图片描述

初二时候用pygame做的万智牌

现在高二了成了个蒟蒻的OIer,四天肝不出一道黑题。这是初二时候写的一个万智牌,那时候上网课,四个通宵搞定了,也许那是我一生中代码技术最好的时候吧。 深夜开e。下面是代码,三年多没看了,注释很少,而且经常会卡死,见谅了。(游戏包含对战,图鉴,互动性UI),上面展示的图片是图鉴,其他界面实在画的太丑了,毕竟是一个人四个通宵肝出来的。

import pygame
import tkinter
import time
import os
import sys
import random
import threading
def add_card(tar,num,*args):
	if tar=="o":
		if len(hand_card)>=7:
			message("Your hand card is full",0.5,"red")
			return 0
	else:
		if len(p_hand_card)>=7:
			message("Your hand card is full",0.5,"red")
			return 0
	add_card=[]
	if len(args)==0:
		for i in range(0,num):
			if tar=="o":
				add_card.append(random.choice(o_card))
				o_card.remove(add_card[i])
			else:
				add_card.append(random.choice(p_card))
				p_card.remove(add_card[i])
	else:
		for arg in args:
			if tar=="o":
				add_card.append(arg)
				o_card.remove(arg)
			else:
				add_card.append(arg)
				p_card.remove(arg)
	if tar=="o":
		for card in add_card:
			hand_card.append(card)
	else:
		for card in add_card:
			p_hand_card.append(card)
def remove_card(tar,num,*args):
	if tar=="o":
		if len(hand_card)<num:
			message("The target have not enough card to remove",0.5,"red")
			num=len(hand_card)
	else:
		if len(p_hand_card)<num:
			message("The target have not enough card to remove",0.5,"red")
			num=len(p_hand_card)
	remove_card=[]
	if len(args)==0:
		for i in range(0,num):
			if tar=="o":
				hand_card.remove(random.choice(hand_card))
			else:
				p_hand_card.remove(random.choice(p_card))
	else:
		for arg in args:
			if tar=="o":
				hand_card.remove(arg)
			else:
				p_hand_card.remove(arg)
def dic_make(card):
    lis=[]
    if card=="n":
    	for i in range(1,50):
    		w="a"
    		s=w+str(i)
    		s={
    		1:abyssal_bone_dragon(),
    		2:shadow_assassin(),
    		3:eye_of_void(),
    		5:werid_face_metchant(),
    		6:six_arm_demon(),
    		7:step_evil_spirit(),
    		8:church_of_darkness(),
    		9:swamp(),
    		10:night_lord(),
    		11:golden_fly(),
    		12:temple_war_dragon(),
    		13:hallowed_spiritkeeper(),
    		14:sheep_head_warrior(),
    		15:atonement_angel(),
    		17:archon_of_coronation(),
    		18:dawn_warrior(),
    		21:horseface_flying_fish(),
    		22:snow_mountain_flying_dragon(),
    		23:ice_cone_deformity_body(),
    		24:id_24(),
    		25:id_25(),
    		26:id_26()
    		}
    		lis.append(s[1])
    	return s
    else:
    	for i in range(1,50):
    		w="a"
    		s=w+str(i)
    		s={
    		1:swamp(),
    		2:church_of_darkness(),
    		3:field(),
    		4:sunshine_plain()
    		}
    		lis.append(s[1])
    	return s
class living:
	def __init__(self):
		self.block=0
		self.attack_num=0
		self.id=0
		self.sleep=1
		self.create=0
		self.energy=0
		self.side=""
		self.pos=0
		self.shadow=0
		self.hide=0
		self.m_n=0
		self.gaze=0
		self.temp_block=0
		self.temp_attack=0
		self.fly=0
		self.obstruct=0
		self.back_num=0
		self.shield=0
		self.king=0
		self.skill_ed_list=[]
		self.type="living"
		self.frozen=0
		self.freezing=0
		self.disappear=0
	def injured(self,a_m,tar):
		if self.shadow==0:
			if self.shield>0:
				self.shield-=1
				return 0
			if self.fly==1 and pos_dic[tar].put.fly==0:
				a_m=int(a_m/2)
		self.block-=a_m
	def big_show(self):
		img_id=self.id
		img=pygame.image.load(os.path.join(card_dir,str(img_id)+".jpg"))
		img=pygame.transform.scale(img,((int(height*8/15)),int(height*4/5)))
		screen.blit(img,(int(width/2)-int(height/5),int(height/12)))
		pygame.display.update()
		
	def attack(self,tar=0,attack_num=-1):
		self.attack_k()
		fresh()
		text=font.render("please chose the card you want to attack",0,(0,0,0))
		screen.blit(text,(0,0))
		pygame.display.update()
		if tar==0:
			if self.side=="o":
				i=opp_pos_c()
				for p in range(1,9):
					if pos_dic[p].put!=0:
						if pos_dic[p].put.obstruct==1 and pos_dic[i].put.shadow==0:
							i=p
							break
				if i=="controller":
					self.attack_controller(self.attack_num)
			elif self.side=="p":
				i=our_pos_c()
				for p in p_pos:
					if pos_dic[p].put!=0:
						if pos_dic[p].put.obstruct==1 and pos_dic[i].put.shadow==0:
							i=p
							break
				if i=="controller":
					self.attack_controller(self.attack_num)
		else:
			i=tar
		self.s_attack(i)
		if pos_dic[i].put.disappear==1:
			hand_card.append(pos_dic[i].put.id)
			pos_dic[i].put=0
		else:
			pos_dic[i].put.s_attacked(self.pos)
		if attack_num==-1:
			a_m=self.attack_num
		else:
			a_m=attack_num
		pos_dic[i].put.temp_block=pos_dic[i].put.block
		if (pos_dic[i].put.attacked_c()==0 or pos_dic[i].put.shadow==1) and pos_dic[i].put.attacked_c()!=2:
			pos_dic[i].put.injured(a_m,self.pos)
			pos_dic[i].put.counterattack(self.pos)
			fresh()
			if pos_dic[i].put.block<=0:
				self.kill()
				pos_dic[i].put.die()
			else:
				pos_dic[i].put.attacked_end(self.pos)
				self.s_attack_end(i)
			if self.block<=0:
				self.die()
		else:
			pos_dic[i].put.attacked(a_m,self.pos)
			pos_dic[i].put.counterattack(self.pos)
			if pos_dic[i].put.block<=0:
				self.kill()
				pos_dic[i].put.die()
			else:
				pos_dic[i].put.attacked_end(self.pos)
				self.s_attack_end(i)
			if self.block<=0:
				self.die()
		if self.get_id()==13:
			if self.charge_13==1:
				return 0
			else:
				call_back()
		else:
			call_back()
	def attack_k(self):
		pass
	def operation(self):
		self.big_show()
		button_img=pygame.image.load(os.path.join(img_dir,"attack_button.png"))
		button_img=pygame.transform.scale(button_img,(int(height/3),int(height/4)))
		screen.blit(button_img,(int(width/2)-int(height/5)+int(height*8/15),int(height/12)+int(height*2/5)-int(height/24)))
		cancel_img=pygame.image.load(os.path.join(img_dir,"cancel.png"))
		cancel_img=pygame.transform.scale(cancel_img,(int(height/12),int(height/12)))
		screen.blit(cancel_img,(int(width/2)-int(height/5)+int(height*8/15),0))
		if self.m_n>0:
			k_button_img=pygame.image.load(os.path.join(img_dir,"k_button.png"))
			k_button_img=pygame.transform.scale(k_button_img,(int(height/3),int(height/4)))
			screen.blit(k_button_img,(int(width/2)-int(height/5)+int(height*8/15),int(height/12)+int(height*2/5)-int(height/24)-int(height/4)))
		if self.m_n>1:
			kk_button_img=pygame.image.load(os.path.join(img_dir,"k_button.png"))
			kk_button_img=pygame.transform.scale(kk_button_img,(int(height/3),int(height/4)))
			screen.blit(kk_button_img,(int(width/2)-int(height/5)+int(height*8/15),int(height/12)+int(height*2/5)-int(height/24)+int(height/4)))
		pygame.display.update()
		while True:
			if event.type==pygame.MOUSEBUTTONDOWN :
				x,y=pygame.mouse.get_pos()
				if (x>=int(width/2)-int(height/5)+int(height*8/15)) and (x<=int(width/2)-int(height/5)+int(height*8/15)+int(height/3)) and (y>=int(height/12)+int(height*2/5)-int(height/24)) and (y<=int(height/12)+int(height*2/5)-int(height/24)+int(height/4)):
					if self.create==1:
						message("this living is creating,you can not operate it",1,"red")
						call_back()
					elif self.freezing==1:
						message("this living is freezing,you can not operate it",1,"red")
						call_back()
					elif self.sleep==1:
						message("this living is sleeping,you can not operate it",1,"red")
						call_back()
					else:
						self.sleep=1
						self.attack()
				if (x>=int(width/2)-int(height/5)+int(height*8/15)) and (x<=int(width/2)-int(height/5)+int(height*8/15)+int(height/3)) and (y>=int(height/12)+int(height*2/5)-int(height/24)-int(height/4)) and (y<=int(height/12)+int(height*2/5)-int(height/24)) and self.m_n>0:
					if self.create==1:
						message("this living is creating,you can not operate it",1,"red")
						call_back()
					elif self.freezing==1:
						message("this living is freezing,you can not operate it",1,"red")
						call_back()
					elif self.sleep==1:
						message("this living is sleeping,you can not operate it",1,"red")
						call_back()
					else:
						self.m_1()
				if (x>=int(width/2)-int(height/5)+int(height*8/15)) and (x<=int(width/2)-int(height/5)+int(height*8/15)+int(height/3)) and (y>=int(height/12)+int(height*2/5)-int(height/24)+int(height/4)) and (y<=int(height/12)+int(height*2/5)-int(height/24)+int(height/2)) and self.m_n>1:
					if self.create==1:
						message("this living is creating,you can not operate it",1,"red")
						call_back()
					elif self.freezing==1:
						message("this living is freezing,you can not operate it",1,"red")
						call_back()
					elif self.sleep==1:
						message("this living is sleeping,you can not operate it",1,"red")
						call_back()
					else:
						self.m_2()
				if (x>=int(width/2)-int(height/5)+int(height*8/15)) and (x<=int(width/2)-int(height/5)+int(height*8/15)+int(height/12)) and (y<=int(height/12)):
									call_back()
	def died_c(self):
		return 0
	def die(self):
		if (self.died_c()==1 and self.shadow==0) or self.died_c()==2:
			self.died()
		pos_list=[]
		if self.gaze==1:
			if self.side=="our":
				for i in p_pos:
					if pos_dic[i].put==0:
						pos_list.append(i)
			else:
				for i in range(1,9):
					if pos_dic[i].put==0:
						pos_list.append(i)
			pos=random.choice(pos_list)
			pos_dic[pos].set(self.id)
			pos_dic[pos].put.gaze=3
			self.m_n=1
		die_font=pygame.font.SysFont("Comic Sans MS",int(width*3/50))
		t=die_font.render("die",0,(255,0,0))
		if self.pos<6:
			screen.blit(t,((self.pos-1)*(int(width/40)+int(width*9/50))+int(width*9/150),int(height*23/80)-int(width*3/100)))
		else:
			screen.blit(t,((self.pos-6)*(int(width/40)+int(width*9/50))+int(width*9/150),int(height*57/80)-int(width*3/100)))
		pygame.display.update()
		time.sleep(1)
		if self.side=="o":
			die_list.append(self.get_id())
		else:
			p_die_list.append(self.get_id())
		pos=self.pos
		side=self.side
		pos_dic[self.pos].put=0
		if side=="o":
			if our_15_charge==1:
				pos_dic[pos].set(15)
		else:
			if opp_15_charge==1:
				pos_dic[pos].set(15)
	def get_id(self):
		return self.id
	def round_start(self):
		self.create=0
		self.sleep=0
	def round_end(self):
		pass
	def attacked_c(self):
		return 0
	def charge(self):
		pass
	def m_c(self):
		fresh()
		text=small_font.render("press X to use the excutable skill X,A to attack,C to cancel",0,(0,0,0))
		screen.blit(text,(0,0))
		pygame.display.update()
		while True:
			for event in pygame.event.get():
				if event.type==pygame.KEYDOWN:
					if event.key==pygame.K_1:
						self.m_1()
					elif event.key==pygame.K_2 and self.m_n>=2:
						self.m_2()
					elif event.key==pygame.K_c:
						call_back()
					elif event.key==pygame.K_a:
						self.attack()
	def attack_controller(self,a_m,tar=0):
		global o_health
		global p_health
		if tar==0:
			if self.side=="o":
				tar="p"
			else:
				tar="o"
		if tar=="o":
			o_health-=a_m
			if o_health<=0:
				screen.fill((0,0,0))
				message("opp win",0,"red")
				time.sleep(4)
				play_again()
		else:
			p_health-=a_m
			if p_health<=0:
				screen.fill((0,0,0))
				message("our win",0,"red")
				time.sleep(4)
				play_again()
		call_back()
	def m(self,e_m,x=0):
		global energy
		global p_energy
		if x==0:
			x=self.side
		if x =="o":
			if energy>=e_m:
				energy-=e_m
			else:
				fresh()
				text=font.render("you do not have enough energy to use this skill",0,(255,0,0))
				screen.blit(text,(0,0))
				pygame.display.update()
				self.sleep=0
				time.sleep(1.5)
				call_back()
		else:
			if p_energy>=e_m:
				p_energy-=e_m
			else:
				fresh()
				message("You do not have enough energy to use this skill",0,"red")
				self.sleep=0
				time.sleep(1.5)
				call_back()
	def add(self,b_m,a_m):
		self.block+=b_m
		self.attack_num+=a_m
	def sub(self,b_m,a_m):
		self.block-=b_m
		self.attack_num-=a_m
	def exile(self):
		pos_dic[self.pos].put=0
		exile_font=pygame.font.SysFont("Comic Sans MS",int(width*3/50))
		t=exile_font.render("exile",0,(255,0,0))
		if self.pos<6:
			screen.blit(t,((self.pos-1)*(int(width/40)+int(width*9/50))+int(width*9/150),int(height*23/80)-int(width*3/100)))
		else:
			screen.blit(t,((self.pos-6)*(int(width/40)+int(width*9/50))+int(width*9/150),int(height*57/80)-int(width*3/100)))
		pygame.display.update()
		time.sleep(1)
	def back_c(self,x):
		if self.back_num>0:
			message("press s to see the card clearly,press X to use the X skill you can use now",0)
			while True:
				for event in pygame.event.get():
					if event.type==pygame.KEYDOWN:
						if event.key==pygame.K_1:
							if self.back_num==1:
								self.back(x)
						elif event.key==pygame.K_s:
							self.big_show()
						elif event.key==pygame.K_c:
							call_back()
		else:
			self.big_show()
	def n_e_g(self,t,i):
		if t=="gaze":
			pos_dic[i].put.gaze=1
		elif t=="shadow":
			pos_dic[i].put.shadow=1
		elif t=="frozen":
			pos_dic[i].put.frozen=1
		elif t=="disappear":
			pos_dic[i].put.disappear=1
	def purify(self):
		self.gaze=0
		self.shadow=0
	def s_attacked(self,tar):
		pass
	def attacked_end(self,tar):
		pass
	def s_attack(self,tar):
		pass
	def s_attack_end(self,tar):
		pass
	def set(self):
		pass
	def kill(self):
		pass
	def counterattacked(self,a_m,tar):
		self.injured(a_m,tar)
	def counterattack(self,tar):
		pos_dic[tar].put.injured(self.attack_num,self.pos)
#诡面商人
class werid_face_metchant(living):
		def __init__(self):
			super(werid_face_metchant,self).__init__()
			self.block=2
			self.attack_num=2
			self.m_n=1
			self.id=5
			self.energy=2
		def attacked(self,a_m,tar):
			global energy
			global p_energy
			if self.side=="o":
				if energy>0:
					if energy<=a_m:
						energy=0
						a_m-=energy
					else:
						energy-=a_m
						a_m=0
			else:
				if p_energy>0:
					if p_energy<=a_m:
						p_energy=0
						a_m-=p_energy
					else:
						p_energy-=a_m
						a_m=0
			self.injured(a_m,tar)
		def attacked_c(self):
			return 1
		def m_1(self):
			global energy
			global p_energy
			self.m(4)
			if self.side=="o":
				a=our_pos_c()
			else:
				a=opp_pos_c()
			fresh()
			text=font.render("select a living of opp",0,(0,0,0))
			screen.blit(text,(0,0))
			pygame.display.update()
			if self.side=="o":
				b=opp_pos_c()
				energy+=abs(pos_dic[a].put.energy-pos_dic[b].put.energy)
				a_id=pos_dic[a].put.get_id()
				b_id=pos_dic[b].put.get_id()
				pos_dic[b].set(a_id)
				pos_dic[a].set(b_id)
			else:
				b=our_pos_c()
				p_energy+=abs(pos_dic[a].put.energy-pos_dic[b].put.energy)
				a_id=pos_dic[a].put.get_id()
				b_id=pos_dic[b].put.get_id()
				pos_dic[a].set(b_id)
				pos_dic[b].set(a_id)
			call_back()
#幻影刺客
class shadow_assassin(living):
	def __init__(self):
		super(shadow_assassin,self).__init__()
		self.block=1
		self.attack_num=2
		self.energy=2
		self.m_n=0
		self.id=2
		self.hide=1
	def attack_k(self):
		if self.side=="o":
			card_list=[]
			for i in p_pos:
				card_list.append(pos_dic[i].put)
			for card in card_list:
				if card!=0:
					self.n_e_g("shadow",card.pos)
		else:
			card_list=[]
			for i in range (1,9):
				card_list.append(pos_dic[i].put)
			for card in card_list:
				if card!=0:
					self.n_e_g("shadow",card.pos)
	def s_attack_end(self,tar):
		if tar>0:
			for i in range(1,9):
				if pos_dic[i].put!=0:
					pos_dic[i].shadow=0
		else:
			for i in p_pos:
				if pos_dic[i].put!=0:
					pos_dic[i].shadow=0
#虚空之眼
class eye_of_void(living):
	def __init__(self):
		super(eye_of_void,self).__init__()
		self.block=1
		self.attack_num=0
		self.energy=3
		self.m_n=1
		self.id=3
	def m_1(self):
		self.m(3)
		if self.side=="o":
			i=opp_pos_c()
		else:
			i=our_pos_c()
		self.n_e_g("gaze",i)
		self.m_n=0
		call_back()
	def attacked_c(self):
		return 1
	def attacked(self,a_m,tar):
		card_list=[]
		if self.side=="o":
			for i in p_pos:
				if pos_dic[i].put!=0:
					if pos_dic[i].put.side=="p":
						card_list.append(pos_dic[i].put)
		else:
			for i in range(1,9):
				if pos_dic[i].put!=0:
					if pos_dic[i].put.side=="o":
						card_list.append(pos_dic[i].put)
		for card in card_list:
			if card.gaze==1:
				self.attack(card.pos,a_m)
				return 0
		self.injured(a_m,tar)
	def died_c(self):
		return 2
	def died(self):
		card_list=[]
		if self.side=="o":
			for i in range(1,9):
				card_list.append(pos_dic[i].put)
		else:
			for i in p_pos:
				card_list.append(pos_dic[i].put)
		for card in card_list:
			if card!=0:
				if card.gaze==3:
					pos_dic[card.pos].put.exile()
					self.block=self.temp_block
					call_back()
#夜空领主
class night_lord(living):
	def __init__(self):
		super(night_lord,self).__init__()
		self.block=3
		self.attack_num=3
		self.fly=1
		self.m_n=2
		self.energy=3
		self.id=10
	def m_1(self):
		global energy
		global p_energy
		self.m(1)
		if self.side=="o":
			i=our_pos_c()
			if pos_dic[i].put.block>5:
				message("you can not use this skill to the living that block>5",1.5,"red")
				energy+=1
				call_back()
		else:
			i=opp_pos_c()
			if pos_dic[i].put.block>5:
				message("you can not use this skill to the living that block>5",1.5,"red")
				p_energy+=1
				call_back()
		pos_dic[i].put.sub(1,0)
		pos_dic[i].put.fly=1
		call_back()
	def m_2(self):
		global energy
		global p_energy
		self.m(1)
		if self.side=="o":
			i=our_pos_c()
			if pos_dic[i].put.fly==0:
				self.sleep=0
				fresh()
				text=font.render("this living do not have power of flying",0,(255,0,0))
				screen.blit(text,(0,0))
				pygame.display.update()
				time.sleep(1.5)
				call_back()
			pos_dic[i].put.exile()
			energy+=3
		else:
			i=opp_pos_c()
			if pos_dic[i].put.fly==0:
				self.sleep=0
				fresh()
				text=font.render("this living do not have power of flying",0,(255,0,0))
				screen.blit(text,(0,0))
				pygame.display.update()
				time.sleep(1.5)
				call_back()
			pos_dic[i].put.exile()
			p_energy+=3
		call_back()
#六臂魔灵

class six_arm_demon(living):
	def __init__(self):
		super(six_arm_demon,self).__init__()
		self.block=1
		self.attack_num=1
		self.m_n=1
		self.energy=2
		self.practice_end=0
		self.id=6
	def m_1(self):
		self.m(1)
		self.attack_num+=1
		call_back()
	def attack_k(self):
		if self.practice_end==0:
			self.block=2*self.attack_num
			self.attack_num=0
			self.obstruct=1
			self.m_n=0
			self.practice_end=1
	def attacked_c(self):
		if self.practice_end==0:
			return 2
		else:
			return 0
	def attacked(self,a_m):
		pass
	def add(self,a,b):
		pass
#深渊骨龙
class abyssal_bone_dragon(living):
	def __init__(self):
		super(abyssal_bone_dragon,self).__init__()
		self.block=5
		self.attack_num=3
		self.energy=5
		self.id=1
		self.m_n=1
		self.back_num=1
	def m_1(self,s=0):
		if s!="back":
			self.m(2)
		else:
			self.block-=2
			self.attack_num-=1
		if self.side=="o":
			i=opp_pos_c()
		else:
			i=our_pos_c()
		pos_dic[i].put.block-=4
		pos_dic[i].put.attack_num-=4
		call_back()
	def back(self,x):
		self.m(2,x)
		if x=="o":
			for i in range(1,9):
				if pos_dic[i].put==0:
					pos_dic[i].set(1)
		else:
			for i in p_pos:
				if pos_dic[i].put==0:
					pos_dic[i].set(1)
#黄金圣蝇
class golden_fly(living):
	def __init__(self):
		super(golden_fly,self).__init__()
		self.block=3
		self.attack_num=2
		self.fly=1
		self.energy=2
		self.id=11
	def s_attack(self,i):
		img=pygame.image.load(os.path.join(img_dir,"golden_fly_ask.png"))
		img=pygame.transform.scale(img,(int(width/5),int(width*17/182)))
		screen.blit(img,(int(width*2/5),int(height/2)-int(width*17/364)))
		pygame.display.update()
		while True:
			for event in pygame.event.get():
				if event.type==pygame.MOUSEBUTTONDOWN :
					x,y=pygame.mouse.get_pos()
					if (x>=int(width*194/455)) and (x<=int(width*224/455)) and (y>=int(height/2)-int(width*54145/2881788)) and (y<=int(height/2)+int(width*28985/130894)):
						if self.side=="o":
							i=our_pos_c()
						else:
							i=opp_pos_c()
						if pos_dic[i].put.get_id()==11:
							message("You can not select the golden fly to be this skill's aim",1.5,"red")
							call_back()
						else:
							pos_dic[i].put.add(self.attack_num,self.attack_num)
							call_back()
					if (x>=int(width*453/910)) and (x<=int(width*245/385)) and (y>=int(height/2)-int(width*54145/2881788)) and (y<=int(height/2)+int(width*28985/130894)):
						return 0
#圣殿战龙
class temple_war_dragon(living):
	def __init__(self):
		super(temple_war_dragon,self).__init__()
		self.block=4
		self.attack_num=6
		self.fly=1
		self.energy=6
		self.id=12
		self.n=0
		self.m_n=1
	def operation(self):
		self.big_show()
		button_img=pygame.image.load(os.path.join(img_dir,"attack_button.png"))
		button_img=pygame.transform.scale(button_img,(int(height/3),int(height/4)))
		screen.blit(button_img,(int(width/2)-int(height/5)+int(height*8/15),int(height/12)+int(height*2/5)-int(height/24)))
		cancel_img=pygame.image.load(os.path.join(img_dir,"cancel.png"))
		cancel_img=pygame.transform.scale(cancel_img,(int(height/12),int(height/12)))
		screen.blit(cancel_img,(int(width/2)-int(height/5)+int(height*8/15),0))
		if self.m_n>0:
			k_button_img=pygame.image.load(os.path.join(img_dir,"k_button.png"))
			k_button_img=pygame.transform.scale(k_button_img,(int(height/3),int(height/4)))
			screen.blit(k_button_img,(int(width/2)-int(height/5)+int(height*8/15),int(height/12)+int(height*2/5)-int(height/24)-int(height/4)))
		pygame.display.update()
		while True:
			if event.type==pygame.MOUSEBUTTONDOWN :
				x,y=pygame.mouse.get_pos()
				if (x>=int(width/2)-int(height/5)+int(height*8/15)) and (x<=int(width/2)-int(height/5)+int(height*8/15)+int(height/3)) and (y>=int(height/12)+int(height*2/5)-int(height/24)) and (y<=int(height/12)+int(height*2/5)-int(height/24)+int(height/4)):
					if self.create==1:
						message("this living is creating,you can not operate it",1,"red")
						call_back()
					elif self.sleep==1:
						message("this living is creating,you can not operate it",1,"red")
						call_back()
					else:
						self.sleep=1
						self.attack()
				if (x>=int(width/2)-int(height/5)+int(height*8/15)) and (x<=int(width/2)-int(height/5)+int(height*8/15)+int(height/3)) and (y>=int(height/12)+int(height*2/5)-int(height/24)-int(height/4)) and (y<=int(height/12)+int(height*2/5)-int(height/24)) and self.m_n>0:
					if self.create==1:
						message("this living is creating,you can not operate it",1,"red")
						call_back()
					elif self.sleep==1 and self.n==0:
						self.m(2)
						self.attack()
						self.n=0
					elif self.n==1:
						message("You can not operate the temple war dragon in this turn any more",1,"red")
						call_back()
					else:
						message("You can not this skill at now",1,"red")
				if (x>=int(width/2)-int(height/5)+int(height*8/15)) and (x<=int(width/2)-int(height/5)+int(height*8/15)+int(height/12)) and (y<=int(height/12)):
					call_back()
	def round_end(self):
		self.n=0
#圣洁灵卫
class hallowed_spiritkeeper(living):
	def __init__(self):
		super(hallowed_spiritkeeper,self).__init__()
		self.block=2
		self.attack_num=2
		self.shield=1
		self.sanctity=1
		self.m_n=1
		self.energy=2
		self.id=13
	def m_1(self):
		self.m(3)
		if self.side=="o":
			i=our_pos_c()
		else:
			i=opp_pos_c()
		pos_dic[i].put.purify()
		self.shield+=1
		call_back()
#阶下邪灵
class step_evil_spirit(living):
	def __init__(self):
		super(step_evil_spirit,self).__init__()
		self.block=3
		self.attack_num=2
		self.energy=2
		self.id=7
		self.s_charge=0
		self.step=1
	def s_attacked(self,tar):
		self.s_charge=0
		block_temp=pos_dic[tar].put.block
		attack_num_temp=pos_dic[tar].put.attack_num
		font=pygame.font.SysFont("Comic Sans MS",int(width*3/50))
		t=font.render("Triller",0,(255,0,0))
		if tar<6:
			screen.blit(t,((tar-1)*(int(width/40)+int(width*9/50))+int(width/50),int(height*23/80)-int(width*3/100)))
		else:
			screen.blit(t,((tar-6)*(int(width/40)+int(width*9/50))+int(width/50),int(height*57/80)-int(width*3/100)))
		pygame.display.update()
		time.sleep(1)
		pos_dic[tar].put.sub(2,2)
		fresh()
		time.sleep(0.5)
		if pos_dic[tar].put.block<=block_temp-2 and pos_dic[tar].put.attack_num<=attack_num_temp:
			self.s_charge=1
		else:
			self.s_charge=0
	def attacked_end(self,tar):
		if self.s_charge==1:
			pos_dic[tar].put.block+=2
			pos_dic[tar].put.attack_num+=2
	def s_attack(self,tar):
		self.s_charge=0
		block_temp=pos_dic[tar].put.block
		attack_num_temp=pos_dic[tar].put.attack_num
		font=pygame.font.SysFont("Comic Sans MS",int(width*3/50))
		t=font.render("Triller",0,(255,0,0))
		if tar<6:
			screen.blit(t,((tar-1)*(int(width/40)+int(width*9/50))+int(width/50),int(height*23/80)-int(width*3/100)))
		else:
			screen.blit(t,((tar-6)*(int(width/40)+int(width*9/50))+int(width/50),int(height*57/80)-int(width*3/100)))
		pygame.display.update()
		time.sleep(1)
		pos_dic[tar].put.sub(2,2)
		fresh()
		time.sleep(0.5)
		if pos_dic[tar].put.block<=block_temp-2 and pos_dic[tar].put.attack_num<=attack_num_temp:
			self.s_charge=1
	def s_attack_end(self,tar):
		if self.s_charge==1:
			pos_dic[tar].put.block+=2
			pos_dic[tar].put.attack_num+=2
#羊头人战士
class sheep_head_warrior(living):
	def __init__(self):
		super(sheep_head_warrior,self).__init__()
		self.block=3
		self.attack_num=3
		self.energy=3
		self.m_n=1
		self.id=14
		self.charge_13=0
	def s_attack_end(self,tar):
		self.n_e_g("shadow",tar,)
	def m_1(self):
		global energy
		global p_energy
		self.m(2)
		if self.side=="o":
			i=our_pos_c()
			if ((i!=6 and i!=10 and (i==self.pos+1 or i==self.pos-1)) or (i==6 and self.pos==7) or (i==10 and self.pos==9)) and pos_dic[i].put!=0:
				self.charge_13=1
				temp=pos_dic[self.pos].put
				pos_dic[self.pos].put=pos_dic[i].put
				pos_dic[i].put=temp
				temp_pos=self.pos
				self.pos=i
				fresh()
				if pos_dic[self.pos-5].put!=0:
					self.attack(self.pos-5)
				self.pos=temp_pos
				temp=pos_dic[self.pos].put
				pos_dic[self.pos].put=pos_dic[i].put
				pos_dic[i].put=temp
				fresh()
				if pos_dic[self.pos-5].put!=0:
					self.charge_13=0
					self.attack(self.pos-5)
			else:
				message("invalid pos",1.5,"red")
				energy+=2
				call_back()
		else:
			i=opp_pos_c()
			if ((i!=1 and i!=5 and (i==self.pos+1 or i==self.pos-1)) or (i==1 and self.pos==2) or (i==5 and self.pos==4)) and pos_dic[i].put!=0:
				self.charge_13=1
				temp=pos_dic[self.pos].put
				pos_dic[self.pos].put=pos_dic[i].put
				pos_dic[i].put=temp
				fresh()
				if pos_dic[self.pos+5].put!=0:
					self.attack(self.pos+5)
				temp=pos_dic[self.pos].put
				pos_dic[self.pos].put=pos_dic[i].put
				pos_dic[i].put=temp
				fresh()
				if pos_dic[self.pos+5].put!=0:
					self.charge_13=0
					self.attack(self.pos+5)
			else:
				message("invalid pos",1.5,"red")
				p_energy+=2
				call_back()
			self.charge_13=0
			call_back()
#赎罪天使
class atonement_angel(living):
	def __init__(self):
		global our_15_charge
		global opp_15_charge
		super(atonement_angel,self).__init__()
		self.block=1
		self.attack_num=1
		self.energy=4
		our_15_charge=0
		opp_15_charge=0
		self.id=15
	def died_c(self):
		return 2
	def died(self):
		global our_15_charge
		global opp_15_charge
		if self.side=="o":
			our_15_charge=1
		else:
			opp_15_charge=1
		self.exile()
		call_back()
	def set(self):
		global energy
		global p_energy
		self.m(-2)
	def m_1(self):
		if self.side=="o":
			i=opp_pos_c()
		else:
			i=our_pos_c()
		self.m(pos_dic[i].put.energy)
		pos_dic[i].put.exile()
#冠冕统领
class archon_of_coronation(living):
	def __init__(self):
		super(archon_of_coronation,self).__init__()
		self.block=3
		self.attack_num=2
		self.energy=4
		self.fly=1
		self.id=17
	def set(self):
		if self.side=="o":
			i=our_pos_c()
			for p in range(1,9):
				if pos_dic[p].put!=0:
					if pos_dic[p].put.king==1:
						return 0
			pos_dic[i].put.king=1
		else:
			i=opp_pos_c()
			for p in p_pos:
				if pos_dic[p].put!=0:
					if pos_dic[p].put.king==1:
						return 0
			pos_dic[i].put.king=1
#破晓勇士
class dawn_warrior(living):
	def __init__(self):
		super(dawn_warrior,self).__init__()
		self.block=3
		self.attack_num=2
		self.energy=2
		self.m_n=1
		self.id=18
	def m_1(self):
		if self.side=="o":
			for i in range(1,9):
				if pos_dic[i].put!=0:
					pos_dic[i].put.add(1,1)
		else:
			for i in p_pos:
				if pos_dic[i].put!=0:
					pos_dic[i].put.add(1,1)
		call_back()
	def kill(self):
		self.add(2,2)
#马面飞鱼
class horseface_flying_fish(living):
	def __init__(self):
		super(horseface_flying_fish,self).__init__()
		self.block=2
		self.attack_num=2
		self.fly=1
		self.energy=2
		self.m_n=1
		self.id=21
	def set(self):
		if self.side=="o":
			add_card("o",1)
		else:
			add_card("p",1)
		self.sleep=0
	def m_1(self):
		pos_list=[]
		if self.side=="o":
			for i in range(1,9):
				if pos_dic[i].put==0:
					pos_list.append(i)
		else:
			for i in p_pos:
				if pos_dic[i].put==0:
					pos_list.append(i)
		pos_dic[self.pos].put=0
		pos_dic[random.choice(pos_list)].set(self.id)
		call_back()
#雪山飞龙
class snow_mountain_flying_dragon(living):
	def __init__(self):
		super(snow_mountain_flying_dragon,self).__init__()
		self.block=4
		self.attack_num=5
		self.energy=5
		self.fly=1
		self.id=22
	def s_attack(self,i):
		self.put.n_e_g("frozen",i)
#冰锥畸形体
class ice_cone_deformity_body(living):
	def __init__(self):
		super(ice_cone_deformity_body,self).__init__()
		self.block=4
		self.attack_num=3
		self.energy=3
		self.id=23
	def round_end(self):
		self.sub(1,0)
		if self.side=="o":
			for i in p_pos:
				if pos_dic[i].put!=0:
					pos_dic[i].put.sub(1,1)
		else:
			for i in range(1,9):
				if pos_dic[i].put!=0:
					pos_dic[i].put.sub(1,1)
		if self.block==0:
			if self.side=="o":
				remove_card("p",1)
				add_card("o",1)
			else:
				remove_card("o",1)
				add_card("p",1)
#霜影幻鹰
class id_24(living):
	def __init__(self):
		super(id_24,self).__init__()
		self.block=3
		self.attack_num=2
		self.fly=1
		self.m_n=2
		self.energy=2
		self.id=24
	def m_1(self):
		self.m(2)
		pos=[]
		if self.side=="o":
			for i in range(1,9):
				if pos_dic[i].put==0:
					pos.append(i)
		else:
			for i in p_pos:
				if pos_dic[i].put==0:
					pos.append(i)
		pos_dic[random.choice(pos)].set(24)
		pos_dic[self.pos].put=0
		pos_dic[self.pos].set(25)
		call_back()
	def m_2(self):
		self.m(1)
		n=0
		if self.side=="o":
			for i in range(1,9):
				if pos_dic[i].put!=0:
					if pos_dic[i].put.id==25:
						n+=1
			for i in range(1,9):
				if pos_dic[i].put!=0:
					if pos_dic[i].put.id==25 or pos_dic[i].put.id==24:
						pos_dic[i].add(n,n)
		else:
			for i in p_pos:
				if pos_dic[i].put!=0:
					if pos_dic[i].put.id==25:
						n+=1
			for i in p_pos:
				if pos_dic[i].put!=0:
					if pos_dic[i].put.id==25 or pos_dic[i].put.id==24:
						pos_dic[i].add(n,n)
		call_back()
#霜影幻鹰虚影
class id_25(living):
	def __init__(self):
		super(id_25,self).__init__()
		self.attack_num=1
		self.block=1
		self.id=25
	def died_c(self):
		return 1
	def died(self):
		pos=[]
		if self.side=="o":
			for i in p_pos:
				if pos_dic[i].put!=0:
					pos.append(i)
		else:
			for i in range(1,9):
				if pos_dic[i].put!=0:
					pos.append(i)
		self.put.n_e_g("frozen",random.choice(pos))
#云间翱翔鲸
class id_26(living):
	def __init__(self):
		super(id_26,self).__init__()
		self.attack_num=3
		self.block=6
		self.id=26
		self.energy=3
		self.m_n=1
	def s_attack(self,i):
		pos_dic[i].put.disappear=1
	def m_1(self):
		self.side=side
		self.exile()
		if side=="o":
			add_card("o",1)
		else:
			add_card("p",1)
		call_back()
#巨鳍龙兽
class id_27(living):
	def __init__(self):
		super(id_27,self).__init__()
		self.block=3
		self.attack_num=1
		self.m_n=1
		self.energy=1
		self.id=27
	def m_1(self):
		self.block+=2
		self.obstruct=1
		call_back()
#冰晶魔主
class id_28(living):
	def __init__(self):
		super(id_28,self).__init__()
		self.block=4
		self.attack_num=4
		self.energy=3
		self.m_n=1
		self.id=28
	def m_1(self):
		self.m(3)
		if self.side=="o":
			i=opp_pos_c()
			self.n_e_g("frozen",i)
		else:
			i=our_pos_c()
			self.n_e_g("frozen",i)
		call_back()
	def round_end(self):
		global energy
		global p_energy
		n=0
		if self.side=="o":
			for i in p_pos:
				if pos_dic[i].put.frozen==1:
					n+=1
			energy+=n
			add_card("o",n)
		else:
			for i in range(1,9):
				if pos_dic[i].put.frozen==1:
					n+=1
			p_energy+=n
			add_card("p",n)
#极北之狐
class id_29(living):
	def __init__(self):
		super(id_29,self).__init__()
		self.attack_num=2
		self.block=2
		self.energy=3
		self.hide=1
		self.id=29
	def round_end(self):
		global energy
		global p_energy
		if self.side=="o":
			if len(hand_card)>4:
				energy+=len(hand_card-4)
		else:
			if len(p_hand_card)>4:
				p_energy+=len(p_hand_card-4)
#永久物
class permanent:
	def __init__(self):
		self.id=0
		self.energy=1
		self.side=""
		self.type="s"
	def big_show(self):
		img_id=self.id
		img=pygame.image.load(os.path.join(s_card_dir,str(img_id)+".jpg"))
		img=pygame.transform.scale(img,((int(height*8/15)),int(height*4/5)))
		screen.blit(img,(int(width/2)-int(height/5),int(height/12)))
		pygame.display.update()
		while True:
			for eevent in pygame.event.get():
					if eevent.type==pygame.MOUSEBUTTONDOWN :
						call_back()
	def round_start(self):
		pass
	def round_end(self):
		pass
	def get_id(self):
		return self.id
#沼泽
class swamp(permanent):
	def __init__(self):
			super(swamp,self).__init__()
			self.id=9
			self.energy=1
	def round_end(self):
		global energy
		global p_energy
		if self.side=="o":
			energy+=1
		elif self.side=="p":
			p_energy+=1
#黑暗教堂
class church_of_darkness(permanent):
	def __init__(self):
			super(church_of_darkness,self).__init__()
			self.id=8
			self.energy=2
	def round_start(self):
		global energy
		global p_energy
		if self.side=="o":
			energy+=1
		elif self.side=="p":
			p_energy+=1
	def round_end(self):
		global energy
		global p_energy
		n=0
		if self.side=="o":
			for i in range(1,9):
				if pos_dic[i].put!=0:
					n+=0
			energy+=int(n/2)
		elif self.side=="p":
			for i in p_pos:
				if pos_dic[i].put!=0:
					n+=0
			p_energy+=int(n/2)
#田野
class field(living):
	def __init__(self):
		super(field,self).__init__()
		self.id=1
		self.energy=1
	def round_end(self):
		global energy
		global p_energy
		if self.side=="o":
			energy+=1
		elif self.side=="p":
			p_energy+=1
#旭光平原
class sunshine_plain(living):
	def __init__(self):
			super(sunshine_plain,self).__init__()
			self.id=3
			self.energy=2
	def round_start(self):
		global energy
		global p_energy
		if self.side=="o":
			for i in range(1,9):
				if pos_dic[i].block>3 and pos_dic[i].attack_num>3:
					energy+=1
		else:
			for i in p_pos:
				if pos_dic[i].block>3 and pos_dic[i].attack_num>3:
					p_energy+=1
def message(t,x,c=""):
	fresh()
	if c=="black":
		color=(0,0,0)
	elif c=="red":
		color=(255,0,0)
	else:
		color=(0,0,255)
	text=font.render(t,0,color)
	screen.blit(text,(0,0))
	pygame.display.update()
	time.sleep(x)
def game():
	global s1
	global s2
	global s3
	global s4
	global s5
	global s6
	global s7
	global s8
	global s_1
	global s_2
	global s_3
	global s_4
	global s_5
	global s_6
	global s_7
	global s_8
	global pos_dic
	global state
	global card_put
	global put_pos
	global dic
	global s_pos_dic
	global s_dic
	global energy
	global round
	global p_energy
	global die_list
	global p_die_list
	global our_15_charge
	global opp_15_charge
	our_15_charge=0
	opp_15_charge=0
	global o_health
	global p_health
	o_health=50
	p_health=50
	global s_list
	s_list=[]
	global p_s_list
	p_s_list=[]
	s1=space(1)
	s2=space(2)
	s3=space(3)
	s4=space(4)
	s5=space(5)
	s6=space(6)
	s7=space(7)
	s8=space(8)
	s_1=space(-1)
	s_2=space(-2)
	s_3=space(-3)
	s_4=space(-4)
	s_5=space(-5)
	s_6=space(-6)
	s_7=space(-7)
	s_8=space(-8)
	s_s1=s_space(1)
	s_s2=s_space(2)
	s_s3=s_space(3)
	s_s4=s_space(4)
	s_s5=s_space(5)
	s_s6=s_space(6)
	s_s7=s_space(7)
	s_s8=s_space(8)
	pos_dic={
	1:s1,
	2:s2,
	3:s3,
	4:s4,
	5:s5,
	6:s6,
	7:s7,
	8:s8,
	-1:s_1,
	-2:s_2,
	-3:s_3,
	-4:s_4,
	-5:s_5,
	-6:s_6,
	-7:s_7,
	-8:s_8
	}
	dic={
	1:abyssal_bone_dragon(),
    2:shadow_assassin(),
    3:eye_of_void(),
    5:werid_face_metchant(),
    6:six_arm_demon(),
    7:step_evil_spirit(),
    8:church_of_darkness(),
    9:swamp(),
    10:night_lord(),
    11:golden_fly(),
    12:temple_war_dragon(),
    13:hallowed_spiritkeeper(),
    14:sheep_head_warrior(),
    15:atonement_angel(),
    17:archon_of_coronation(),
    18:dawn_warrior(),
    21:horseface_flying_fish(),
    22:snow_mountain_flying_dragon(),
    23:ice_cone_deformity_body(),
    24:id_24(),
    25:id_25(),
    26:id_26()
	}
	s_dic={
	1:swamp(),
	2:church_of_darkness(),
	3:field(),
	4:sunshine_plain()
	}
	s_pos_dic={
	1:s_s1,
	2:s_s2,
	3:s_s3,
	4:s_s4,
	5:s_s5,
	6:s_s6,
	7:s_s7,
	8:s_s8
	}
	global card_list
	card_list=[]
	global s_card_list
	s_card_list=[]
	die_list=[]
	p_die_list=[]
	energy=99
	p_energy=99
	global o_card
	global hand_card
	o_card=[]
	hand_card=[]
	global p_card
	global p_hand_card
	p_card=[]
	p_hand_card=[]
	global p_pos
	p_pos=[-1,-2,-3,-4,-5,-6,-7,-8]
	for i in range(1,18):
		o_card.append(i)
		p_card.append(i)
	hand_card=[24,23,22,26]
	for p in range(1,5):
		d=random.choice(p_card)
		p_hand_card.append(d)
		p_card.remove(d)
	while True:
		round_start()
def show_hand_card():
	i=0
	for p in hand_card:
		img=pygame.image.load(os.path.join(card_dir,(str(p)+".jpg")))
		img=pygame.transform.scale(img,(int(width*233/2000),int(height*21/80)))
		screen.blit(img,(int(width*167/800)+int(width*233/2000)*i,int(height*59/80)))
		i+=1
	i=0
	for p in p_hand_card:
		img=pygame.image.load(os.path.join(card_dir,(str(p)+".jpg")))
		img=pygame.transform.scale(img,(int(width*233/2000),int(height*21/80)))
		screen.blit(img,(int(width*167/800)+int(width*233/2000)*i,0))
		i+=1
	pygame.display.update()
def call_back():
	if round=="o":
		round_operate_chose()
	else:
		p_round_operate_chose()
def opp_pos_c():
	fresh(1)
	message("select an opp",0)
	card_list=[]
	available_list=[-1,-2,-3,-4,-5,-6,-7,-8]
	for i in p_pos:
		card_list.append(pos_dic[i].put)
	for card in card_list:
		if card!=0:
			if card.create==1:
				available_list.remove(card.pos)
				sleep_txt=font.render("creating",0,(0,0,0))
				screen.blit(sleep_txt,(((card.pos-1)*(int(width/40)+int(width*9/50))+int(width*9/100)-40),int(height*23/80)-40))
				pygame.display.update()
	for i in available_list:
		if pos_dic[i].put!=0:
			if pos_dic[i].put.hide==1:
				if (i!=-1 and i!=-8 and pos_dic[i-1].put!=0 and pos_dic[i+1].put!=0) or (i==-1 and pos_dic[-2].put!=0) or (i==-8 and pos_dic[-7].put!=0):
					available_list.remove(i)
	while True:
		for event in pygame.event.get():
			if event.type==pygame.KEYDOWN:
				if event.key==pygame.K_ESCAPE:
					exit()
			if event.type==pygame.KEYDOWN:
				if event.key==pygame.K_c:
					call_back()
			if event.type==pygame.MOUSEBUTTONDOWN :
				for i in available_list:
					i=-i
					x,y=pygame.mouse.get_pos()
					if (x>=i*int(width/100)+int(width*71/800)*(i-1)+int(width/10)) and (x<=i*int(width/100)+int(width*71/800)*i+int(width/10)) and (y>=int(height*19/40)-int(height*3/16)) and (y<=int(height*19/40)) and pos_dic[i].put!=0:
							return -i
					if (x>=int(width*27/200)) and (x<=int(width*27/200)+int(height/12)) and (y<=int(height/10)):
						return "controller"
def our_pos_c():
	fresh()
	text=font.render("select a living of our",0,(0,0,0))
	screen.blit(text,(0,0))
	pygame.display.update()
	card_list=[]
	available_list=[1,2,3,4,5,6,7,8]
	for i in range(1,9):
		card_list.append(pos_dic[i].put)
	for card in card_list:
		if card!=0:
			if card.create==1:
				available_list.remove(card.pos)
				sleep_txt=font.render("creating",0,(0,0,0))
				screen.blit(sleep_txt,(((card.pos-6)*(int(width/40)+int(width*9/50))+int(width*9/100)-40),int(height*23/80)-40))
				pygame.display.update()
	for i in available_list:
		if pos_dic[i].put!=0:
			if pos_dic[i].put!=0:
				if pos_dic[i].put.hide==1:
					if (i!=1 and i!=8 and pos_dic[i-1].put!=0 and pos_dic[i+1].put!=0) or (i==1 and pos_dic[2].put!=0) or (i==8 and pos_dic[7].put!=0):
						available_list.remove(i)
	while True:
		for event in pygame.event.get():
			if event.type==pygame.KEYDOWN:
				if event.key==pygame.K_ESCAPE:
					exit()
			if event.type==pygame.KEYDOWN:
				if event.key==pygame.K_c:
					call_back()
			if event.type==pygame.MOUSEBUTTONDOWN :
				for i in available_list:
					x,y=pygame.mouse.get_pos()
					for i in range(1,9):
						if (x>=i*int(width/100)+int(width*71/800)*(i-1)+int(width/10)) and (x<=i*int(width/100)+int(width*71/800)*i+int(width/10)) and (y>=int(height*21/40)) and (y<=int(height*21/40)+int(height*3/16)) and pos_dic[i].put!=0:
							return i
					if (x>=int(width*9/100)) and (x<=int(width*9/100)+int(height/12)) and (y>=int(height*9/10)):
						return "controller"
def round_start():
	global card_list
	global s_card_list
	global round
	global card
	global hand_card
	global energy
	global p_energy
	round="o"
	card_list=[]
	s_card_list=[]

	for i in range(1,9):
		card_list.append(pos_dic[i].put)
	r_s_img=pygame.image.load(os.path.join(img_dir,"round_start.jpg"))
	r_s_img=pygame.transform.scale(r_s_img,(width,height))
	screen.blit(r_s_img,(0,0))
	pygame.display.update()
	add_card("o",1)
	for card in card_list:
		if card!=0:
			card.round_start()
	for card in card_list:
		if card!=0:
			if card.king==1:
				temp=[6,7,8,9,10]
				temp.remove(card.pos)
				n=0
				for i in temp:
					if pos_dic[i].put!=0:
						if pos_dic[i].put.block>0 and pos_dic[i].put.attack_num>0:
							block_temp=pos_dic[i].put.block
							attack_num_temp=pos_dic[i].put.attack_num
							pos_dic[i].put.sub(1,1)
							if pos_dic[i].put.block<block_temp and pos_dic[i].put.attack_num<attack_num_temp:
								n+=1
				pos_dic[card.pos].put.add(n,n)
				break
	for i in range(1,9):
		if pos_dic[i].put!=0:
			pos_dic[i].put.create=0
	for i in range(1,9):
		if pos_dic[i].put!=0:
			if pos_dic[i].put.frozen==1:
				if p_energy<2:
					break
				else:
					p_energy-=2
					pos_dic[i].put.freezing=1
	for i in range(1,5):
		s_card_list.append(s_pos_dic[i].put)
	for s_card in s_card_list:
		if s_card!=0 and s_card.side=="o":
			s_card.round_start()
	time.sleep(3)
	fresh()
	round_operate_chose()
def p_round_start():
	global state
	global s_card_list
	global card_list
	global round
	global p_card
	global card
	global energy
	global p_energy
	round="p"
	s_card_list=[]
	card_list=[]
	add_card("p",1)
	for i in p_pos:
		card_list.append(pos_dic[i].put)
	r_s_img=pygame.image.load(os.path.join(img_dir,"p_round_start.jpg"))
	r_s_img=pygame.transform.scale(r_s_img,(width,height))
	screen.blit(r_s_img,(0,0))
	pygame.display.update()
	for card in card_list:
		if card!=0:
			card.round_start()
	for card in card_list:
		if card!=0:
			if card.king==1:
				temp=[1,2,3,4,5]
				temp.remove(card.pos)
				n=0
				for i in temp:
					if pos_dic[i].put!=0:
						if pos_dic[i].put.block>0 and pos_dic[i].put.attack_num>0:
							block_temp=pos_dic[i].put.block
							attack_num_temp=pos_dic[i].put.attack_num
							pos_dic[i].put.sub(1,1)
							if pos_dic[i].put.block<block_temp and pos_dic[i].put.attack_num<attack_num_temp:
								n+=1
				pos_dic[card.pos].put.add(n,n)
				break
	for i in p_pos:
		if pos_dic[i].put!=0:
			pos_dic[i].put.create=0
	for i in p_pos:
		if pos_dic[i].put!=0:
			if pos_dic[i].put.frozen==1:
				if energy<2:
					break
				else:
					energy-=2
					pos_dic[i].put.freezing=1
	for i in range(5,9):
		s_card_list.append(s_pos_dic[i].put)
	for s_card in s_card_list:
		if s_card!=0 and s_card.side=="p":
			s_card.round_start()
	time.sleep(3)
	fresh()
	p_round_operate_chose()
def round_end():
	global s_card_list
	card_list=[]
	s_card_list=[]
	for i in range(1,9):
		if pos_dic[i].put!=0:
			pos_dic[i].put.sleep=0
			pos_dic[i].put.round_end()
	for i in range(1,9):
		if pos_dic[i].put!=0:
			pos_dic[i].put.freezing=0
	img=pygame.image.load(os.path.join(img_dir,"finish_round.jpg"))
	img=pygame.transform.scale(img,(width,height))
	screen.blit(img,(0,0))
	pygame.display.update()
	time.sleep(3)
def p_round_end():
	global s_card_list
	card_list=[]
	s_card_list=[]
	for i in p_pos:
		card_list.append(pos_dic[i].put)
	for i in range(1,9):
		s_card_list.append(s_pos_dic[i].put)
	for s_card in s_card_list:
		if s_card!=0 and s_card.side=="p":
			s_card.round_end()
	for i in p_pos:
		if pos_dic[i].put!=0:
			pos_dic[i].put.sleep=0
	for i in p_pos:
		if pos_dic[i].put!=0:
			pos_dic[i].put.freezing=0
	img=pygame.image.load(os.path.join(img_dir,"p_finish_round.jpg"))
	img=pygame.transform.scale(img,(width,height))
	screen.blit(img,(0,0))
	pygame.display.update()
	time.sleep(3)
def round_operate_chose():
	global put_pos
	global click_n
	global energy
	fresh(1)
	message("If you want to put card or operate card,click the space",0)
	while True:
		for event in pygame.event.get():
			if event.type==pygame.KEYDOWN:
				if event.key==pygame.K_ESCAPE:
					exit()
			if event.type==pygame.MOUSEBUTTONDOWN :
				for i in range(0,len(hand_card)):
					x,y=pygame.mouse.get_pos()
					if (x>=i*int(width*233/2000)+int(width*167/800)) and (x<=(i+1)*int(width*233/2000)+int(width*167/800)) and (y>=int(height*59/80)):
						img=pygame.image.load(os.path.join(card_dir,str(hand_card[i])+".jpg"))
						img=pygame.transform.scale(img,((int(height*8/15)),int(height*4/5)))
						screen.blit(img,(int(width/2)-int(height/5),int(height/12)))
						button_img=pygame.image.load(os.path.join(img_dir,"put_button.png"))
						button_img=pygame.transform.scale(button_img,(int(height/3),int(height/4)))
						screen.blit(button_img,(int(width/2)-int(height/5)+int(height*8/15),int(height/12)+int(height*2/5)-int(height/24)))
						cancel_img=pygame.image.load(os.path.join(img_dir,"cancel.png"))
						cancel_img=pygame.transform.scale(cancel_img,(int(height/12),int(height/12)))
						screen.blit(cancel_img,(int(width/2)-int(height/5)+int(height*8/15),0))
						e=e_font.render(str(dic[hand_card[i]].energy),0,(255,255,255))
						screen.blit(e,(int(width/2)-int(height/5)+int(height*8/15)+int(height/20),int(height/12)+int(height*2/5)))
						pygame.display.update()
						while True:
							if event.type==pygame.MOUSEBUTTONDOWN :
								x,y=pygame.mouse.get_pos()
								if (x>=int(width/2)-int(height/5)+int(height*8/15)) and (x<=int(width/2)-int(height/5)+int(height*8/15)+int(height/3)) and (y>=int(height/12)+int(height*2/5)-int(height/24)) and (y<=int(height/12)+int(height*2/5)-int(height/24)+int(height/4)):
									if energy>=dic[hand_card[i]].energy:
										for p in range(1,9):
											if pos_dic[p].put==0:
												if dic[hand_card[i]].type=="s":
													s_list.append(hand_card[i])
												else:
													pos_dic[p].set(hand_card[i],"put")
													hand_card.pop(i)
													energy-=pos_dic[p].put.energy
												call_back()
									else:
										message("You do not have enough energy!",0,"red")
								if (x>=int(width/2)-int(height/5)+int(height*8/15)) and (x<=int(width/2)-int(height/5)+int(height*8/15)+int(height/12)) and (y<=int(height/12)):
									call_back()
				for i in range(1,9):
					x,y=pygame.mouse.get_pos()
					if (x>=i*int(width/100)+int(width*71/800)*(i-1)+int(width/10)) and (x<=i*int(width/100)+int(width*71/800)*i+int(width/10)) and (y>=int(height*21/40)) and (y<=int(height*21/40)+int(height*3/16)) and pos_dic[i].put!=0:
							click_n=0
							pos_dic[i].put.operation()
					elif (x>=int(width*41/50)) and (y>=int(height*9/20)) and (y<=int(height*11/20)) :
						click_n=1
						round_end()
						p_round_start()
					elif (x>=int(width*59/200)) and (x<=int(width*59/200)+int(height/8)) and (y>=int(height*9/10)) and (y<=int(height*59/60)):
						put_charge_card("d")
def p_round_operate_chose():
	global put_pos
	global click_n
	global p_energy
	fresh()
	message("If you want to put card or operate card,click the space",0)
	while True:
		for event in pygame.event.get():
			if event.type==pygame.KEYDOWN:
				if event.key==pygame.K_ESCAPE:
					exit()
			if event.type==pygame.MOUSEBUTTONDOWN :
				for i in range(0,len(p_hand_card)):
					x,y=pygame.mouse.get_pos()
					if (x>=i*int(width*233/2000)+int(width*167/800)) and (x<=(i+1)*int(width*233/2000)+int(width*167/800)) and (y<=int(height*3/16)):
						img=pygame.image.load(os.path.join(card_dir,str(p_hand_card[i])+".jpg"))
						img=pygame.transform.scale(img,((int(height*8/15)),int(height*4/5)))
						screen.blit(img,(int(width/2)-int(height/5),int(height/12)))
						button_img=pygame.image.load(os.path.join(img_dir,"put_button.png"))
						button_img=pygame.transform.scale(button_img,(int(height/3),int(height/4)))
						screen.blit(button_img,(int(width/2)-int(height/5)+int(height*8/15),int(height/12)+int(height*2/5)-int(height/24)))
						cancel_img=pygame.image.load(os.path.join(img_dir,"cancel.png"))
						cancel_img=pygame.transform.scale(cancel_img,(int(height/12),int(height/12)))
						screen.blit(cancel_img,(int(width/2)-int(height/5)+int(height*8/15),0))
						e=e_font.render(str(dic[p_hand_card[i]].energy),0,(255,255,255))
						screen.blit(e,(int(width/2)-int(height/5)+int(height*8/15)+int(height/20),int(height/12)+int(height*2/5)))
						pygame.display.update()
						while True:
							if event.type==pygame.MOUSEBUTTONDOWN :
								x,y=pygame.mouse.get_pos()
								if (x>=int(width/2)-int(height/5)+int(height*8/15)) and (x<=int(width/2)-int(height/5)+int(height*8/15)+int(height/3)) and (y>=int(height/12)+int(height*2/5)-int(height/24)) and (y<=int(height/12)+int(height*2/5)-int(height/24)+int(height/4)):
									if p_energy>=dic[p_hand_card[i]].energy:
										for p in p_pos:
											if pos_dic[p].put==0:
												if dic[p_hand_card[i]].type=="s":
													p_s_list.append(p_hand_card[i])
												else:
													pos_dic[p].set(p_hand_card[i],"put")
													p_hand_card.pop(i)
													p_energy-=pos_dic[p].put.energy
												call_back()
									else:
										message("You do not have enough energy!",0,"red")
								if (x>=int(width/2)-int(height/5)+int(height*8/15)) and (x<=int(width/2)-int(height/5)+int(height*8/15)+int(height/12)) and (y<=int(height/12)):
									call_back()
				for i in range(1,9):
					if (x>=i*int(width/100)+int(width*71/800)*(i-1)+int(width/10)) and (x<=i*int(width/100)+int(width*71/800)*i+int(width/10)) and (y>=int(height*19/40)-int(height*3/16)) and (y<=int(height*21/40)) and pos_dic[-i].put!=0:
							click_n=0
							pos_dic[-i].put.operation()
					elif (x>=int(width*41/50)) and (y>=int(height*9/20)) and (y<=int(height*11/20)) :
						click_n=1
						p_round_end()
						round_start()
					elif (x>=int(width*59/200)) and (x<=int(width*59/200)+int(height/8)) and (y<=int(height/12)):
						put_charge_card("p_d")
def put_charge_card(x):
	time.sleep(1)
	screen.fill((225,225,225))
	if x!="d" and x!="p_d":
		text=font.render("Please click the card that you want to put",0,(0,0,0))
	else:
		text=little_font.render("the dead area of living.If you want to use the executives skill of the living here,click them.",0,(0,0,0))
	screen.blit(text,(0,0))
	player=card_chose()
	player.show(x)
def fresh(n=0):
	bg_img=pygame.image.load(os.path.join(img_dir,"background.jpg"))
	bg_img=pygame.transform.scale(bg_img,(width,height))
	screen.blit(bg_img,(0,0))
	end_round_img=pygame.image.load(os.path.join(img_dir,"end_round.png"))
	end_round_img=pygame.transform.scale(end_round_img,(int(width/50*9),int(height/10)))
	screen.blit(end_round_img,((int(width/50*41)),int(height*9/20)))
	energy_img=pygame.image.load(os.path.join(img_dir,"death.png"))
	energy_img=pygame.transform.scale(energy_img,(int(height/12),int(height/12)))
	screen.blit(energy_img,(int(height/15),int(height*9/10)))
	energy_text=energy_font.render(str(energy),0,(0,0,0))
	if energy<10:
		screen.blit(energy_text,(int(height/40),int(height*9/10)))
	else:
		screen.blit(energy_text,(0,int(height*9/10)))
	p_energy_img=pygame.image.load(os.path.join(img_dir,"death.png"))
	p_energy_img=pygame.transform.scale(energy_img,(int(height/12),int(height/12)))
	screen.blit(energy_img,(int(height/15),0))
	p_energy_text=energy_font.render(str(p_energy),0,(0,0,0))
	if p_energy<10:
		screen.blit(p_energy_text,(int(height/40),0))
	else:
		screen.blit(p_energy_text,(0,0))
	d_a_img=pygame.image.load(os.path.join(img_dir,"die_area.png"))
	d_a_img=pygame.transform.scale(d_a_img,(int(width*49/800),int(width*49/800)))
	screen.blit(d_a_img,(int(width*751/800),int(height)-int(width*49/800)))
	controller_img=pygame.image.load(os.path.join(img_dir,"dark_controller.jpg"))
	controller_img=pygame.transform.scale(controller_img,(int(width*49/800),int(width*49/800)))
	screen.blit(controller_img,(0,int(height*59/80)))
	screen.blit(controller_img,(int(width*27/200),0))
	txt=energy_font.render(str(o_health),0,(255,0,0))
	screen.blit(txt,(int(width*49/800),int(height*59/80)))
	p_txt=energy_font.render(str(p_health),0,(255,0,0))
	screen.blit(p_txt,(int(width*27/200)+int(height/12),0))
	show_hand_card()
	s1.p()
	s2.p()
	s3.p()
	s4.p()
	s5.p()
	s6.p()
	s7.p()
	s8.p()
	s_1.p()
	s_2.p()
	s_3.p()
	s_4.p()
	s_5.p()
	s_6.p()
	s_7.p()
	s_8.p()
	n=0
	for s in s_list:
		img=pygame.image.load(os.path.join(card_dir,str(s)+".jpg"))
		img=pygame.transform.scale(img,(int(width/25),int(height*3/16)))
		screen.blit(img,(int(width*n/25),int(height*21/40)))
		n+=1
	n=0
	for s in p_s_list:
		img=pygame.image.load(os.path.join(card_dir,str(s)+".jpg"))
		img=pygame.transform.scale(img,(int(width/25),int(height*3/16)))
		screen.blit(img,(int(width*n/25),int(height/40)))
		n+=1
	for i in range(1,9):
		if pos_dic[i].put!=0:
			pos_dic[i].draw=0
			if pos_dic[i].put.fly==1:
				t=m_font.render("fly",0,(126,13,93))
				if i<6:
					screen.blit(t,((i-1)*(int(width/40)+int(width*9/50))+int(width*9/150),int(height/10)+pos_dic[i].draw*int(height*3/40)))
				else:
					screen.blit(t,((i-6)*(int(width/40)+int(width*9/50))+int(width*9/150),int(height*21/40)+pos_dic[i].draw*int(height*3/40)))
					
			if pos_dic[i].put.gaze==1:
				t=m_font.render("gaze",0,(255,0,0))
				if i<6:
					screen.blit(t,((i-1)*(int(width/40)+int(width*9/50)),int(height/10)+pos_dic[i].draw*int(height*3/40)))
					for p in range(6,11):
						if pos_dic[p].put!=0:
							if pos_dic[p].put.get_id()==3:
								pygame.draw.line(screen,(128,0,128),((i-1)*(int(width/40)+int(width*9/50))+int(width*9/100),int(height/10)),((p-6)*(int(width/40)+int(width*9/50))+int(width*9/100),int(height*21/40)),3)
				else:
					screen.blit(t,((i-6)*(int(width/40)+int(width*9/50)),int(height*21/40)+pos_dic[i].draw*int(height*3/40)))
					for p in range(1,6):
						if pos_dic[p].put!=0:
							if pos_dic[p].put.get_id()==3:
								pygame.draw.line(screen,(128,0,128),((i-6)*(int(width/40)+int(width*9/50))+int(width*9/100),int(height*21/40)),((p-1)*(int(width/40)+int(width*9/50))+int(width*9/100),int(height/10)),3)
			if pos_dic[i].put.shadow==1:
				t=m_font.render("shadow",0,(255,0,0))
				if i<6:
					screen.blit(t,((i-1)*(int(width/40)+int(width*9/50))+int(width*9/150),int(height/10)+pos_dic[i].draw*int(height*3/40)))
				else:
					screen.blit(t,((i-6)*(int(width/40)+int(width*9/50))+int(width*9/150),int(height*21/40)+pos_dic[i].draw*int(height*3/40)))
			if pos_dic[i].put.shield>0:
				if pos_dic[i].put.shield==1:
					text="shield"
				else:
					text="shiled"+str(pos_dic[i].put.shield)
				t=m_font.render(text,0,(126,13,93))
				if i<6:
					screen.blit(t,((i-1)*(int(width/40)+int(width*9/50))+int(width*9/150),int(height/10)+pos_dic[i].draw*int(height*3/40)))
				else:
					screen.blit(t,((i-6)*(int(width/40)+int(width*9/50))+int(width*9/150),int(height*21/40)+pos_dic[i].draw*int(height*3/40)))
			if pos_dic[i].put.king==1:
				t=m_font.render("king",0,(126,13,93))
				if i<6:
					screen.blit(t,((i-1)*(int(width/40)+int(width*9/50))+int(width*9/150),int(height/10)+pos_dic[i].draw*int(height*3/40)))
				else:
					screen.blit(t,((i-6)*(int(width/40)+int(width*9/50))+int(width*9/150),int(height*21/40)+pos_dic[i].draw*int(height*3/40)))
			if pos_dic[i].put.obstruct==1:
				t=m_font.render("obstruct",0,(126,13,93))
				if i<6:
					screen.blit(t,((i-1)*(int(width/40)+int(width*9/50))+int(width*9/150),int(height/10)+pos_dic[i].draw*int(height*3/40)))
				else:
					screen.blit(t,((i-6)*(int(width/40)+int(width*9/50))+int(width*9/150),int(height*21/40)+pos_dic[i].draw*int(height*3/40)))
	if n==0:
		pygame.display.update()
class card_chose():
	def __init__(self):
		self.n=0
		self.nn=1
		self.n_available_list=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17]
		self.p_n_available_list=self.n_available_list
		self.s_available_list=[1,2,3,4]
		self.p_s_available_list=[1,2,3,4]
	def show(self,x):
			cancel_img=pygame.image.load(os.path.join(img_dir,"cancel.png"))
			cancel_img=pygame.transform.scale(cancel_img,(int(width/21),int(width/21)))
			screen.blit(cancel_img,((int(width/5)+int(width/4)*3),0))
			l_p_img=pygame.image.load(os.path.join(img_dir,"l_p.png"))
			l_p_img=pygame.transform.scale(l_p_img,(int(width/21),int(width/21)))
			n_p_img=pygame.image.load(os.path.join(img_dir,"n_p.png"))
			n_p_img=pygame.transform.scale(n_p_img,(int(width/21),int(width/21)))
			
			self.n=0
			if x=="n":
				list=self.n_available_list
			elif x=="p_n":
				list=self.p_n_available_list
			if x=="s":
				list=self.s_available_list
			elif x=="p_s":
				list=self.p_s_available_list
			elif x=="d":
				list=die_list
			elif x=="p_d":
				list=p_die_list
			if self.nn>1:
				screen.blit(l_p_img,(0,(int(height/20)+int(height*17/40))))
			if len(list)-self.nn*8>0:
				screen.blit(n_p_img,((int(width/5)+int(width/4)*3),(int(height/20)+int(height*17/40))))
			max=self.nn*8
			if max > len(list):
				max=len(list)
			min=(self.nn-1)*8
			for i in range(min,max):
				self.n+=1
				if x=="n" or x=="p_n":
					path=os.path.join(n_card_dir,(str(list[i])+".jpg"))
				elif x=="s" or x=="p_s":
					path=os.path.join(s_card_dir,(str(list[i])+".jpg"))
				elif x=="d" or x=="p_d":
					path=os.path.join(n_card_dir,(str(list[i])+".jpg"))
				pic=pygame.image.load(path)
				pic=pygame.transform.scale(pic,(int(width/16*3),int(height*17/40)))
				if self.n<=4:
					screen.blit(pic,(int(width/20)*self.n+int(width/16)*3*(self.n-1),int(height/20)))
				else:
					l=self.n-4
					screen.blit(pic,(int(width/20)*l+int(width/16)*3*(l-1),int(height/10+height*17/40)))
			pygame.display.update()
			self.click(x)
	def click(self,x):
		global card_put
		global state
		global energy
		global p_energy
		if x=="n":
			list=self.n_available_list
		elif x=="p_n":
			list=self.p_n_available_list
		elif x=="s":
			list=self.s_available_list
		elif x=="p_s":
			list=self.p_s_available_list
		elif x=="d":
			list=die_list
		elif x=="p_d":
			list=p_die_list
		while True:
			for event in pygame.event.get():
					if event.type==pygame.KEYDOWN:
						if event.key==pygame.K_ESCAPE:
							exit()
					if event.type==pygame.MOUSEBUTTONDOWN:
						if x=="n" or x=="p_n":
							for i in range(1,9):
								y,z=pygame.mouse.get_pos()
								if i>4:
									d=i-4
								else:
									d=i
								if (y>=int(width/5)+int(width/4)*3) and (y<=int(width/5)+int(width/4)*3+int(width/21)) and (z<=int(width/21)):
									call_back()
								elif (y>=int(width/5)+int(width*3/4)) and (y<=int(width/5)+int(width*3/4)+int(width/21)) and (z>=int(height/20)+int(height*17/40)) and (z<=int(height/20)+int(height*17/40)+int(height/21)) and (len(list)-self.nn*8>0):
									self.nn+=1
									screen.fill((225,225,225))
									self.show(x)
								elif (y>=0) and (y<=int(width/21)) and (z>=int(height/20)+int(height*17/40)) and (z<=int(height/20)+int(height*17/40)+int(height/21)) and self.nn>1:
									self.nn-=1
									screen.fill((225,225,225))
									self.show(x)
								if (y>=int(width/20*d)+int(width/16*3*(d-1))) and (y<=int(width/20*d)+int(width/16*3)*d) and (z>=int(height/20)*(int(i/5)+1)+int(height*17/40)*int(i/5)) and (z<=int(height/20)*(int(i/5)+1)+int(height*17/40)*(int(i/5)+1)) and ((self.nn-1)*8+i<=len(list)):
									card_put=list[(self.nn-1)*8+i-1]
									if x=="n":
										if energy>=dic[card_put].energy:
											pos_dic[put_pos].set(card_put)
											energy-=dic[card_put].energy
											round_operate_chose()
										else:
											fresh()
											text=font.render("you do not have enough energy to put the card",0,(255,0,0))
											screen.blit(text,(0,0))
											pygame.display.update()
											time.sleep(1.5)
											round_operate_chose()
									else:
										if p_energy>=dic[card_put].energy:
											pos_dic[put_pos].set(card_put)
											p_energy-=dic[card_put].energy
											p_round_operate_chose()
										else:
											fresh()
											text=font.render("you do not have enough energy to put the card",0,(255,0,0))
											screen.blit(text,(0,0))
											pygame.display.update()
											time.sleep(1.5)
											p_round_operate_chose()
						elif x=="s" or x=="p_s":
							for i in range(1,9):
								y,z=pygame.mouse.get_pos()
								if i>4:
									d=i-4
								else:
									d=i
								if (y>=int(width/5)+int(width/4)*3) and (y<=int(width/5)+int(width/4)*3+int(width/21)) and (z<=int(width/21)):
									if x=="s":
										round_operate_chose()
									else:
										p_round_operate_chose()
								if (y>=int(width/20*d)+int(width/16*3*(d-1))) and (y<=int(width/20*d)+int(width/16*3)*d) and (z>=int(height/20)*(int(i/5)+1)+int(height*17/40)*int(i/5)) and (z<=int(height/20)*(int(i/5)+1)+int(height*17/40)*(int(i/5)+1)) and ((self.nn-1)*8+i<=len(list)):
									card_put=list[(self.nn-1)*8+i-1]
									if x=="s":
										if energy>=s_dic[card_put].energy:
											s_pos_dic[put_pos].set(card_put)
											energy-=s_dic[card_put].energy
											round_operate_chose()
										else:
											fresh()
											text=font.render("you do not have enough energy to put the card",0,(225,0,0))
											screen.blit(text,(0,0))							
											pygame.display.update()
											time.sleep(1.5)
											round_operate_chose()
									else:
										if p_energy>=s_dic[card_put].energy:
											s_pos_dic[put_pos].set(card_put)
											p_energy-=s_dic[card_put].energy
											p_round_operate_chose()
										else:
											fresh()
											text=font.render("you do not have enough energy to put the card",0,(225,0,0))
											screen.blit(text,(0,0))										
											pygame.display.update()
											time.sleep(1.5)
											p_round_operate_chose()
						if x=="d" or x=="p_d":
							for i in range(1,9):
								y,z=pygame.mouse.get_pos()
								if i>4:
									d=i-4
								else:
									d=i
								if (y>=int(width/5)+int(width/4)*3) and (y<=int(width/5)+int(width/4)*3+int(width/21)) and (z<=int(width/21)):
									call_back()
								if (y>=int(width/20*d)+int(width/16*3*(d-1))) and (y<=int(width/20*d)+int(width/16*3)*d) and (z>=int(height/20)*(int(i/5)+1)+int(height*17/40)*int(i/5)) and (z<=int(height/20)*(int(i/5)+1)+int(height*17/40)*(int(i/5)+1)) and ((self.nn-1)*8+i<=len(list)):
									card_put=list[(self.nn-1)*8+i-1]
									if x=="d":
										dic[card_put].back_c("o")
									else:
										dic[card_put].back_c("p")
class space():
	global dic
	def __init__(self,n):
		self.n=n
		self.put=0
	def p(self):
		n=self.n
		n_temp=self.n
		if n>0:
			pos_y_f=int(height*21/40)
		else:
			pos_y_f=int(height*23/80)
			n=-n
		pos_x_f=int(width/100)*n+int(width*71/800)*(n-1)+int(width/10)
		pos_y_l=pos_y_f+int(height/8)*3
		if self.put!=0:
			img=pygame.image.load(os.path.join(card_dir,str(self.put.get_id())+".jpg"))
			img=pygame.transform.scale(img,(int(width/800*71),int(height/16*3)))
			screen.blit(img,(pos_x_f,pos_y_f))
			b_a=str(self.put.block)+"/"+str(self.put.attack_num)
			text=small_font.render(b_a,0,(0,0,0))
			if n_temp>0:
				screen.blit(text,((n-1)*(int(width*71/800))+n*int(width/100)+int(width/10)+int(width/800*71/3),int(height*21/40)+int(height*3/16)))
			else:
				n_temp=-n_temp
				screen.blit(text,((n_temp-1)*(int(width*71/800))+n_temp*int(width/100)+int(width/10)+int(width/800*71/3),int(height*19/40)-int(height*3/16)-int(height/20)))
	def set(self,put,s=""):
		self.put=dic_make("n")[put]
		fresh()
		self.put.pos=self.n
		if self.n<0:
			self.put.side="p"
		if self.n>0:
			self.put.side="o"
		if s=="put":
			self.put.create=1
		self.put.sleep=1
		self.put.set()
		if self.put.side=="o":
			for i in range(-8,0):
				if pos_dic[i].put!=0:
					if pos_dic[i].put.get_id()==9:
						if pos_dic[i].put.step==1 and pos_dic[i].put.create==0:
							pos_dic[i].put.step=0
							pos_dic[i].put.attack(self.n)
		else:
			for i in range(1,9):
				if pos_dic[i].put!=0:
					if pos_dic[i].put.get_id()==9:
						if pos_dic[i].put.step==1 and pos_dic[i].put.create==0:
							pos_dic[i].put.step=0
							pos_dic[i].put.attack(self.n)
	def test_set(self,put,side):
		self.put=dic_make("n")[put]
		self.put.side=side
		self.put.pos=self.n
class s_space():
	global dic
	def __init__(self,n):
		self.n=n
		self.put=0
	def p(self):
		n=self.n
		if n>5:
			d=n-5
		else:
			d=n
		if self.put!=0:
			img=pygame.image.load(os.path.join(s_card_dir,str(self.put.get_id())+".jpg"))
			img=pygame.transform.scale(img,(int(height/15),int(height/15)))
			if n<5:
				screen.blit(img,(int(width*16/25)+int(width*41/400)*(n-1),int(height*12/13)))
			else:
				screen.blit(img,(int(width*16/25)+int(width*41/400)*(n-5),int(height*1/60)))
		else:
			s_b_img=pygame.image.load(os.path.join(img_dir,("s_space.jpg")))
			s_b_img=pygame.transform.scale(s_b_img,(int(height/15),int(height/15)))
			if n<5:
				screen.blit(s_b_img,(int(width*16/25)+int(width*41/400)*(n-1),int(height*12/13)))
			else:
				screen.blit(s_b_img,(int(width*16/25)+int(width*41/400)*(n-5),int(height*1/60)))
		pygame.display.update()
	def set(self,put):
		self.put=dic_make("s")[put]
		if put_pos>4:
			self.put.side="p"
		else:
			self.put.side="o"
class Dictionary():
	def __init__(self):
		self.n=0
		self.nn=1
	def show(self):
		bg_img=pygame.image.load(os.path.join(img_dir,"dy_bg_img.jpg"))
		bg_img=pygame.transform.scale(bg_img,(width,height))
		screen.blit(bg_img,(0,0))
		home_img=pygame.image.load(os.path.join(img_dir,"home.jpg"))
		home_img=pygame.transform.scale(home_img,(int(width/21),int(width/21)))
		screen.blit(home_img,((int(width/5)+int(width/4)*3),0))
		l_p_img=pygame.image.load(os.path.join(img_dir,"l_p.png"))
		l_p_img=pygame.transform.scale(l_p_img,(int(width/21),int(width/21)))
		n_p_img=pygame.image.load(os.path.join(img_dir,"n_p.png"))
		n_p_img=pygame.transform.scale(n_p_img,(int(width/21),int(width/21)))
		if self.nn>1:
			screen.blit(l_p_img,(0,(int(height/20)+int(height*17/40))))
		if len(os.listdir(card_dir))-self.nn*8>0:
			screen.blit(n_p_img,((int(width/5)+int(width/4)*3),(int(height/20)+int(height*17/40))))
		self.n=0
		pygame.display.update()
		max=self.nn*8
		if max>len(os.listdir(card_dir)):
			max=len(os.listdir(card_dir))
		min=(self.nn-1)*8
		for i in range(min,max):
			self.n+=1
			path=os.path.join(card_dir,(str(i+1)+".jpg"))
			pic=pygame.image.load(path)
			pic=pygame.transform.scale(pic,(int(width/16*3),int(height*17/40)))
			if self.n<=4:
				screen.blit(pic,(int(width/20)*self.n+int(width/16)*3*(self.n-1),int(height/20)))
			else:
				l=self.n-4
				screen.blit(pic,(int(width/20)*l+int(width/16)*3*(l-1),int(height/10+height*17/40)))
			pygame.display.update()
		self.click()
	def click(self):
		global e_n
		global state
		while state=="dictionary":
			for event in pygame.event.get():
				if event.type==pygame.MOUSEBUTTONDOWN and state=="dictionary":
					for i in range(1,9):
						x,y=pygame.mouse.get_pos()
						if i>4:
							d=i-4
						else:
							d=i
						if (x>=int(width/20*d)+int(width/16*3*(d-1))) and (x<=int(width/20*d)+int(width/16*3)*d) and (y>=int(height/20)*(int(i/5)+1)+int(height*17/40)*int(i/5)) and (y<=int(height/20)*(int(i/5)+1)+int(height*17/40)*(int(i/5)+1)) and ((self.nn-1)*8+i<=len(os.listdir(card_dir))):
							img_id=8*(self.nn-1)+i
							img=pygame.image.load(os.path.join(card_dir,str(img_id)+".jpg"))
							img=pygame.transform.scale(img,((int(height*8/15)),int(height*4/5)))
							screen.blit(img,(int(width/2)-int(height/5),int(height/12)))
							pygame.display.update()
							while True:
								for eevent in pygame.event.get():
									if eevent.type==pygame.MOUSEBUTTONDOWN and state=="dictionary":
										self.show()
										break
						elif (x>=int(width/5)+int(width*3/4)) and (x<=int(width/5)+int(width*3/4)+int(width/21)) and (y<=width/21):
							state="load"
							home_reload()
							break
						elif (x>=int(width/5)+int(width*3/4)) and (x<=int(width/5)+int(width*3/4)+int(width/21)) and (y>=int(height/20)+int(height*17/40)) and (y<=int(height/20)+int(height*17/40)+int(height/21)) and (len(os.listdir(card_dir))-self.nn*8>0):
							self.nn+=1
							self.show()
							break
						elif (x>=0) and (x<=int(width/21)) and (y>=int(height/20)+int(height*17/40)) and (y<=int(height/20)+int(height*17/40)+int(height/21)) and self.nn>1:
							self.nn-=1
							self.show()
							break
def exit():
	global exit_win
	exit_win=tkinter.Tk()
	exit_win.title("kindly reminder")
	size="300x300"+"+"+str(int((width-300)/2))+"-"+str(int((height-300)/2))
	exit_win.geometry(size)
	text=tkinter.Label(exit_win,text="exit or not?",bg="white",fg="black",font=('楷体', 20, 'bold italic'))
	text.pack()
	button1=tkinter.Button(exit_win,text="return",width=5,height=2,command=exit_win_cancel)
	button2=tkinter.Button(exit_win,text="exit",width=5,height=2,command=destroy)
	button1.pack(anchor="s",side=tkinter.LEFT)
	button2.pack(anchor="s",side=tkinter.RIGHT)
	exit_win.protocol("WM_DELETE_WINDOW",exit_win_cancel)
	exit_win.mainloop()
def play_again():
	global play_again
	play_again=tkinter.Tk()
	play_again.title("kindly reminder")
	size="300x300"+"+"+str(int((width-300)/2))+"-"+str(int((height-300)/2))
	play_again.geometry(size)
	text=tkinter.Label(play_again,text="play again or not?",bg="white",fg="black",font=('楷体', 20, 'bold italic'))
	text.pack()
	button1=tkinter.Button(play_again,text="play again",width=5,height=2,command=game)
	button2=tkinter.Button(play_again,text="exit",width=5,height=2,command=destroy)
	button1.pack(anchor="s",side=tkinter.LEFT)
	button2.pack(anchor="s",side=tkinter.RIGHT)
	play_again.protocol("WM_DELETE_WINDOW",play_again_cancel)
	play_again.mainloop()
def play_again_cancel():
	global exit_win
	global e_n
	global play_again
	play_again.destroy()
	e_n=0
def exit_win_cancel():
	global exit_win
	global e_n
	exit_win.destroy()
	e_n=0
def destroy():
	exit_win.quit()
	pygame.quit()
	sys.exit()
def home_reload():
	screen.blit(bg_img,(0,0))
	screen.blit(w_img,(per_width,int(height/6)))
	screen.blit(f_img,(per_width*2.5,int(height/6)))
	screen.blit(d_img,(per_width*4,int(height/6)))
	screen.blit(s_img,(per_width*5.5,int(height/6)))
	screen.blit(fi_img,(per_width*7,int(height/6)))
	screen.blit(start_img,(int(width/2)-int(height/4),int(height/2.5)))
	screen.blit(dy_img,(int(width/4)-int(height/6),int(height/2)))
	text=big_font.render("illustrated dictionnary",0,(0,0,0))
	screen.blit(text,(int(width/4)-int(height/3),int(height/2.2)))
	pygame.display.update()
sc=0
e_n=0
dir=os.getcwd()
img_dir=os.path.join(dir,"images")
card_dir=os.path.join(img_dir,"card")
data_dir=os.path.join(dir,"data")
n_card_dir=os.path.join(img_dir,"n_card")
s_card_dir=os.path.join(img_dir,"s_card")
put_pos=0
put_card=0
click_n=0
#主窗口
pygame.init()
clock=pygame.time.Clock()
clock.tick(10)
w_h=open(os.path.join(data_dir,"size.txt"),"r")
width=w_h.readline()
width=int(width.strip("\n"))
height=int(w_h.readline())
screen=pygame.display.set_mode((int(width),int(height)))
pygame.display.set_caption("ghost boat crossing holy fire")
font = pygame.font.Font("freesansbold.ttf", int(height/20))
energy_font=pygame.font.SysFont('Comic Sans MS', int(height/10))
big_font=pygame.font.SysFont('Comic Sans MS', 60)
small_font=pygame.font.SysFont("Comic Sans MS",int(height/12))
little_font=pygame.font.SysFont("Comic Sans MS",20)
m_font=pygame.font.SysFont("Comic Sans MS",int(height/40*3))
e_font=pygame.font.SysFont("Comic Sans MS",int(height/6))
while True:
	for event in pygame.event.get():
		if event.type ==pygame.QUIT:
			exit()
		if event.type == pygame.KEYDOWN:
			if event.key == pygame.K_ESCAPE:
				pygame.quit()
				sys.exit()
	bg_img = pygame.image.load(os.path.join(img_dir,"loading_pic.jpg"))
	bg_img = pygame.transform.scale(bg_img, (width,height))
	screen.blit(bg_img,(0,0))
	pygame.display.update()
	time.sleep(3)
	state="load"
	bg_img = pygame.image.load(os.path.join(img_dir,"home_pic.jpg"))
	bg_img = pygame.transform.scale(bg_img, (width,height))
	screen.blit(bg_img,(0,0))
	per_width=int(width/10)
	per_height=per_width
	w_img = pygame.image.load(os.path.join(img_dir,"water.png"))
	w_img = pygame.transform.scale(w_img, (per_width,per_height))
	f_img = pygame.image.load(os.path.join(img_dir,"forest.png"))
	f_img = pygame.transform.scale(f_img,(per_width,per_height))
	d_img = pygame.image.load(os.path.join(img_dir,"death.png"))
	d_img = pygame.transform.scale(d_img,(per_width,per_height))
	s_img = pygame.image.load(os.path.join(img_dir,"sun.png"))
	s_img = pygame.transform.scale(s_img,(per_width,per_height))
	fi_img = pygame.image.load(os.path.join(img_dir,"fire.png"))
	fi_img = pygame.transform.scale(fi_img,(per_width,per_height))
	screen.blit(w_img,(per_width,int(height/6)))
	screen.blit(f_img,(per_width*2.5,int(height/6)))
	screen.blit(d_img,(per_width*4,int(height/6)))
	screen.blit(s_img,(per_width*5.5,int(height/6)))
	screen.blit(fi_img,(per_width*7,int(height/6)))
	start_img=pygame.image.load(os.path.join(img_dir,"start.png"))
	start_img=pygame.transform.scale(start_img,(int(height/2.5),int(height/2.5)))
	screen.blit(start_img,(int(width/2)-int(height/4),int(height/2.5)))
	dy_img=pygame.image.load(os.path.join(img_dir,"dictionary.png"))
	dy_img=pygame.transform.scale(dy_img,(int(height/3),int(height/3)))
	screen.blit(dy_img,(int(width/4)-int(height/6),int(height/2)))
	text=big_font.render("illustrated dictionnary",0,(0,0,0))
	screen.blit(text,(int(width/4)-int(height/3),int(height/2.2)))
	pygame.display.update()
	while state=="load":
		for event in pygame.event.get():
			m_x,m_y=pygame.mouse.get_pos()
			if (m_x>=int(width/2)-int(height/4)) and (m_x<=int(width/2)-int(height/4)+int(height/2.5)) and (m_y>=int(height/2.5)) and (m_y<=int(height*2/2.5)):
				start_c_img=pygame.image.load(os.path.join(img_dir,("start_click.png")))
				start_c_img=pygame.transform.scale(start_c_img,(int(height/2.5),int(height/2.5)))
				screen.blit(start_c_img,(int(width/2)-int(height/4),int(height/2.5)))
				sc=1
				pygame.display.update()
				if event.type==pygame.MOUSEBUTTONDOWN and (m_x>=int(width/2)-int(height/4)) and (m_x<=int(width/2)-int(height/4)+int(height/2.5)) and (m_y>=int(height/2.5)) and (m_y<=int(height*2/2.5)):
					game()
					threads = []
			else:
				if sc==1:
					screen.blit(start_img,(int(width/2)-int(height/4),int(height/2.5)))
					sc=0
					pygame.display.update()
					if event.type==pygame.MOUSEBUTTONDOWN and (m_x>=int(width/2)-int(height/4)) and (m_x<=int(width/2)-int(height/4)+int(height/2.5)) and (m_y>=int(height/2.5)) and (m_y<=int(height*2/2.5)):
						game()
			if event.type==pygame.QUIT and e_n==0:
				exit()
			if event.type==pygame.MOUSEBUTTONDOWN and state=="load":
				x,y=event.pos
				if (x>=per_width) and (x<=per_width*2) and (y>=height/6) and (y<=height/6+per_height):
					home_reload()
					text = font.render("Water symbolizes life, wisdom and fraud",0,(0,0,0))
					screen.blit(text,(width/5,height/10))
					pygame.display.update()
				elif (x>=per_width*2.5) and (x<=per_width*3.5) and (y>=height/6) and (y<=height/6+per_height):
					home_reload()
					text = font.render("Forests symbolizes life, origin and growth",0,(0,0,0))
					screen.blit(text,(width/5,height/10))
					pygame.display.update()
				elif (x>=per_width*4) and (x<=per_width*5) and (y>=height/6) and (y<=height/6+per_height):
					home_reload()
					text = font.render("Skeletons symbolizes death, decay and evil",0,(0,0,0))
					screen.blit(text,(width/5,height/10))
					pygame.display.update()
				elif (x>=per_width*5.5) and (x<=per_width*6.5) and (y>=height/6) and (y<=height/6+per_height):
					home_reload()
					text = font.render("Fire symbolizes destruction, sin and power",0,(0,0,0))
					screen.blit(text,(width/5,height/10))
					pygame.display.update()
				elif (x>=per_width*7) and (x<=per_width*8) and (y>=height/6) and (y<=height/6+per_height):
					home_reload()
					text = font.render("Sun symbolizes light, justice and order",0,(0,0,0))
					screen.blit(text,(width/5,height/10))
					pygame.display.update()
				elif (x>=int(width/4)-int(height/6)) and (x<=int(width/4)-int(height/6)+int(height/3)) and (y>=int(height/2)) and (y<=int(height/2)+int(height/3)):
					state="dictionary"
					dictionary=Dictionary()
					dictionary.show()

后言

希望明年信奥能过省选吧()。

  • 6
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值