Ejemplo n.º 1
0
def event1():
	global new_m,m,fps, next_block
	next_block=copy.deepcopy(next_block_blank)
	orient=0
	fps=10
	num=pieces_order.pop(0)
	pieces_order.append(random.randint(1,7))
	running=True
	p=[-1,5]
	if m[0][5]!=0 or m[0][6]!=0:
		running=False
		return False
	c=random.randint(1,len(colors))
	preset(module.new_piece(str(pieces_order[0]),1,1,0),next_block,5)
	while running:
		
		new_m=copy.deepcopy(m)
		p[0]+=1
		
		a = piece(p,num,orient,c)
		if a == -1:
			p[0]-=1
			a=piece(p,num,orient,c)
			m=copy.deepcopy(new_m)
			return True
			break
		display(new_m)
		if p[0]==n_r-1:
			m=copy.deepcopy(new_m)
			return True
			break
		keystate = pygame.key.get_pressed()
		if keystate[pygame.K_DOWN]:
			fps=30
		if keystate[pygame.K_UP]:
			orient+=1
			if orient>3:
				orient-=4
		'''
		if keystate[pygame.K_RIGHT] and p[1]<n_c-1:
			if new_m[p[0]+1][p[1]+2]==0:
				p[1]+=1
		if keystate[pygame.K_LEFT] and p[1]>0:
			if new_m[p[0]+1][p[1]-2]==0:
				p[1]-=1

		'''
		for event in pygame.event.get():
			if event.type==pygame.QUIT:
				quit()
			if event.type == pygame.KEYDOWN:
				if event.key == pygame.K_RIGHT and p[1]<n_c-1:
					if new_m[p[0]+1][p[1]+2]==0:
						p[1]+=1
				if event.key == pygame.K_LEFT and p[1]>0:
					if new_m[p[0]+1][p[1]-2]==0:
						p[1]-=1
Ejemplo n.º 2
0
def event2():
	global new_m2,m2,fps, next_block2
	next_block2=copy.deepcopy(next_block_blank)
	orient=0
	fps=10
	num=pieces_order2.pop(0)
	pieces_order2.append(random.randint(1,7))
	running=True
	p=[-1,5]
	if m2[0][5]!=0 or m2[0][6]!=0:
		running=False
		return False
	c=random.randint(1,len(colors))
	preset2(module.new_piece(str(pieces_order2[0]),1,1,0),next_block2,5)
	while running:
		
		new_m2=copy.deepcopy(m2)
		p[0]+=1
		
		a = piece2(p,num,orient,c)
		if a == -1:
			p[0]-=1
			a=piece2(p,num,orient,c)
			m2=copy.deepcopy(new_m2)
			return True
			break
		display2(new_m2)
		if p[0]==n_r-1:
			m2=copy.deepcopy(new_m2)
			return True
			break
		
		keystate = pygame.key.get_pressed()
		if keystate[pygame.K_s]:
			fps=30
		if keystate[pygame.K_w]:
			orient+=1
			if orient>3:
				orient-=4
		for event in pygame.event.get():
			if event.type==pygame.QUIT:
				quit()
			if event.type == pygame.KEYDOWN:
				if event.key == pygame.K_d and p[1]<n_c-1:
					if new_m2[p[0]+1][p[1]+2]==0:
						p[1]+=1
				if event.key == pygame.K_a and p[1]>0:
					if new_m2[p[0]+1][p[1]-2]==0:
						p[1]-=1
Ejemplo n.º 3
0
def piece2(point, num, orient,color):
	d=module.new_piece(str(num),point[1],point[0],orient)
	a=preset2(d,new_m2,color)
	if a == -1:
		return -1
Ejemplo n.º 4
0
def event1():
	
	global new_m,m,fps, next_block1,next_block2,orient,a,b,score_b

	score_b+=10

	next_block1=copy.deepcopy(next_block_blank)
	next_block2=copy.deepcopy(next_block_blank)
	orient1=0
	orient2=0
	fps=10
	num1=pieces_order1.pop(0)
	pieces_order1.append(random.randint(1,7))
	num2=pieces_order2.pop(0)
	pieces_order2.append(random.randint(1,7))
	running1=True
	running2=True
	p1=[-1,3]
	p2=[-1,11]
	if m[0][3]!=0 or m[0][11]!=0:
		running1=False
		running2=False
	c1=random.randint(1,len(colors))
	c2=random.randint(1,len(colors))
	preset(module.new_piece(str(pieces_order1[0]),1,1,0),next_block1,5)
	preset(module.new_piece(str(pieces_order2[0]),1,1,0),next_block2,5)
	while running1 or running2:
		a=0
		b=0

		new_m=copy.deepcopy(m)
		if a!=-1:
			p1[0]+=1
			a = piece(p1,num1,orient1,c1)

		if b!=-1:
			p2[0]+=1
			b = piece(p2,num2,orient2,c2)
		if a == -1:
			p1[0]-=1
			a=piece(p1,num1,orient1,c1)
			running1=False
			
			#p1[1]=n_r
		if b == -1:
			p2[0]-=1
			b=piece(p2,num2,orient2,c2)
			running2=False

			#p2[1]=n_r
		

		display(new_m)
		if p1[0]==n_r-1:
			a=-1
		if p2[0]==n_r-1:
			b=-1
		if p1[0]==n_r-1 and p2[0]==n_r-1:
			break
		keystate = pygame.key.get_pressed()
		if keystate[pygame.K_DOWN] or keystate[pygame.K_s]:
			fps=30
		'''
		if keystate[pygame.K_RIGHT] and p[1]<n_c-1:
			if new_m[p[0]+1][p[1]+2]==0:
				p[1]+=1
		if keystate[pygame.K_LEFT] and p[1]>0:
			if new_m[p[0]+1][p[1]-2]==0:
				p[1]-=1
		'''
		for event in pygame.event.get():
			if event.type==pygame.QUIT:
				quit()
			if event.type == pygame.KEYDOWN:
				if event.key == pygame.K_d and p1[1]<n_c-1 and a!=-1:
					if new_m[p1[0]+1][p1[1]+2]==0:
						p1[1]+=1
				if event.key == pygame.K_a and p1[1]>0  and a!=-1:
					if new_m[p1[0]+1][p1[1]-2]==0:
						p1[1]-=1
				if event.key == pygame.K_RIGHT and p2[1]<n_c-1 and b!=-1:
					if new_m[p2[0]+1][p2[1]+2]==0:
						p2[1]+=1
				if event.key == pygame.K_LEFT and p2[1]>0  and b!=-1:
					if new_m[p2[0]+1][p2[1]-2]==0:
						p2[1]-=1
				if event.key == pygame.K_w and a!=-1:
					orient1+=1
					if orient1>3:
						orient1-=4
				if event.key == pygame.K_UP and b!=-1:
					orient2+=1
					if orient2>3:
						orient2-=4
	else:
		m=copy.deepcopy(new_m)