⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zllkview.cpp

📁 连连看小游戏
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	 
	     for(i=1;i<temp;i++)
		     if(llk_map[x1+i][y1].PicIndex!=0)
				 return false;
	   }
	   else
	   {
		  for(i=1;i<temp;i++)
		     if(llk_map[x1-i][y1].PicIndex!=0)
				 return false;
	   }
   }
   return true;
}
//   判断直线(射线)除起始点 图片是否为空
//   0 2 0 0 0 0 0
bool  CZLLKView::IsLinePicEmpty(int x1, int y1, int x2, int y2)
{
   int i,temp;
   if(x1==x2)   //同一行
   {   
	   temp=abs(y2-y1);
	   if(y2>y1)
	   {
	 
	     for(i=1;i<=temp;i++)
		     if(llk_map[x1][y1+i].PicIndex!=0)
				 return false;
	   }
	   else
	   {
		  for(i=1;i<=temp;i++)
		     if(llk_map[x1][y1-i].PicIndex!=0)
				 return false;
	   }
   }
   if(y1==y2) //同一列
   {
	   temp=abs(x2-x1);
	   if(x2>x1)
	   {
	 
	     for(i=1;i<=temp;i++)
		     if(llk_map[x1+i][y1].PicIndex!=0)
				 return false;
	   }
	   else
	   {
		  for(i=1;i<=temp;i++)
		     if(llk_map[x1-i][y1].PicIndex!=0)
				 return false;
	   }
   }
   return true;

}
//      情况二:经过一个折点相连(+号代表折点)
//               0 0 0 0 0 0        
//               0 2 0 0 0 +        * ------ +        
//               0 + 0 0 0 2        + ------ *
//           (两条路都可连通)
bool CZLLKView::IsNotLineConnection(int x1, int y1, int x2, int y2)
{
	if(IsLinePicEmpty(x1,y1,x1,y2))
	{
		if(IsLineConnection(x1,y2,x2,y2))
			return true;
	}
	if(IsLinePicEmpty(x1,y1,x2,y1))
	{
		if(IsLineConnection(x2,y1,x2,y2))
			return true;
	}
	return false;
}
//是否无解
bool CZLLKView::IsNoConnection()
{
	int i;
	ZYHLLK_PATH *pic=NULL;
    ZYHLLK_PATH *Nextpic = NULL;
	for(i=1;i<=15;i++)
	{
		pic=pic_place[i];
		while(pic!=NULL)//pic->next
		{
			Nextpic=pic;
	      	while(Nextpic->next!=NULL)
			{
		    	Nextpic=Nextpic->next;
		    	if(CheckConnection(pic->x,pic->y,Nextpic->x,Nextpic->y))
					return false;
			}
			pic=pic->next;
		}		
	}
	return true;
}
bool CZLLKView::IsPicEmpty()
{
	int i,j;
	for(i=1;i<=ROW_NUMBER;i++)
		for(j=1;j<=LINE_NUMBER;j++)
		{
			if(llk_map[i][j].PicIndex!=0)
				return false;
		}
    return true;
}
//添加图片位置  这个函数是为判断无解和提示服务的
void CZLLKView::AddPicPlace(int picindex,int x,int y)
{
   LPZYHLLK_PATH pic;

   if ((pic = (LPZYHLLK_PATH) GlobalAlloc(GPTR,
      sizeof(ZYHLLK_PATH))) == NULL)
   {
      printf("GlobalAlloc() failed with error %d\n", GetLastError());
      return;
   }
   pic->x=x;
   pic->y=y;
   pic->next = pic_place[picindex];
   pic_place[picindex] = pic;
}
//在链表释放图片位置 这个函数是为判断无解和提示服务的
void CZLLKView::ReleasePicPlace(int picindex,int x,int y)
{
   ZYHLLK_PATH *pic = pic_place[picindex];
   ZYHLLK_PATH *Prevpic = NULL;

   while(pic)
   {
      if ((pic->x==x)&&(pic->y==y))
      {
         if (Prevpic)
            Prevpic->next = pic->next;
         else
            pic_place[picindex]= pic->next;
         GlobalFree(pic);
         return;
      }
      Prevpic = pic;
      pic = pic->next;
   }
}
//暂时没有用到
LPZYHLLK_PATH CZLLKView::QueryPicPlace(int picindex,int x,int y)
{
   ZYHLLK_PATH *pic = pic_place[picindex];
   while(pic)
   {
      if ((pic->x== x)&&(pic->y==y))
         return pic;
      pic = pic->next;
   }
   return NULL;
}
//列出每幅图片的所有位置  用来判断无解和提示的
void CZLLKView::ListPicPlace()
{
	int i,j;
	for(i=1;i<=ROW_NUMBER;i++)
	{
		for(j=1;j<=LINE_NUMBER;j++)
		{
			if(llk_map[i][j].PicIndex>0)
			{
				AddPicPlace(llk_map[i][j].PicIndex,i,j);
			}
		}
	}
}
//提示函数
void CZLLKView::BackPicPlace()
{
	int i;
	CRect rect;
	ZYHLLK_PATH *pic=NULL;
    ZYHLLK_PATH *Nextpic = NULL;
	for(i=1;i<=15;i++) 
	{
		pic=pic_place[i];
		while(pic!=NULL)
		{
			Nextpic=pic;
	      	while(Nextpic->next!=NULL)
			{
		    	Nextpic=Nextpic->next;
		    	if(CheckConnection(pic->x,pic->y,Nextpic->x,Nextpic->y))
				{
					llk_map[pic->x][pic->y].state=1;
                   	llk_map[Nextpic->x][Nextpic->y].state=1;
			 		rect.top=tiley(pic->x); rect.bottom=rect.top+PIC_HEIGHT;
			       	rect.left=tilex(pic->y); rect.right=rect.left+PIC_WIDTH;
			       	InvalidateRect(&rect,TRUE);
			    	rect.top=tiley(Nextpic->x); rect.bottom=rect.top+PIC_HEIGHT;
			       	rect.left=tilex(Nextpic->y); rect.right=rect.left+PIC_WIDTH;
			       	InvalidateRect(&rect,TRUE);
					return;
				}
				
			}
			pic=pic->next;
		}	
	}
	return;
}
//重列函数
void CZLLKView::SortPicPlace()
{
	int i,j;
	CRect rect;
	CDWordArray arPic;
	for(i=1;i<=ROW_NUMBER;i++)
	{
	   	for(j=1;j<=LINE_NUMBER;j++)
		{ 
			llk_map[i][j].state=0;
	    	if(llk_map[i][j].PicIndex>0)
			 	arPic.Add(llk_map[i][j].PicIndex);
		}
	}
	//int k = 1;//初始化随机数发生器 
    //int divisor = ROW_NUMBER*LINE_NUMBER - k+1;	index = rand() % divisor+1  k++
    int index;
	for(i=1;i<=ROW_NUMBER;i++)
	{
	    for(j=1;j<=LINE_NUMBER;j++)
		{ 
			if(llk_map[i][j].PicIndex>0)
			{
				index=(int(rand()*001+rand()*0.1+rand()))%arPic.GetSize();
			 	llk_map[i][j].PicIndex=arPic.GetAt(index);
				arPic.RemoveAt(index);
			}
		}
	}
	//重新列出所有图片位置
	for(i=0;i<15;i++)
    {
		pic_place[i+1]=NULL;
	}
	ListPicPlace();  
	//刷新屏幕
	rect.top=DRAW_TOP+BMP_HEIGHT; rect.bottom=BMP_HEIGHT*ROW_NUMBER+DRAW_TOP+PIC_HEIGHT;
	rect.left=DRAW_LEFT+BMP_WIDTH; rect.right=BMP_WIDTH*LINE_NUMBER+DRAW_LEFT+PIC_WIDTH;
	InvalidateRect(&rect,TRUE);

}

void CZLLKView::OnMenuInfo() 
{
	// TODO: Add your command handler code here
	if(bingame)
	{
    	if(m_tishinumber>0)
		{
	     	m_tishinumber--;
	    	DrawInfo(60,80,m_tishinumber);
	    	BackPicPlace();
		}
	    else
		{
	     	AfxMessageBox("提示已经用完");
		}
	}
}

void CZLLKView::OnUpdateMenuInfo(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	CString str;
	str.Format("提示(%d)  F5",m_tishinumber);
	pCmdUI->SetText(str);
	if(m_tishinumber<=0) 
		pCmdUI->Enable(false);

}

void CZLLKView::OnMenuSort() 
{
	// TODO: Add your command handler code here
	if(bingame)
	{
    	if(m_sortnumber>0)
		{
	     	m_sortnumber--;
			DrawInfo(60,60,m_sortnumber);
	    	SortPicPlace();
		}
	    else
		{
	     	AfxMessageBox("重列次数已经用完");
		}
	}
}

void CZLLKView::OnUpdateMenuSort(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	CString str;
	str.Format("重列(  %d)  F6",m_sortnumber);
	pCmdUI->SetText(str);
	if(m_sortnumber<=0) 
		pCmdUI->Enable(false);	
}

void CZLLKView::OnMenuStop() 
{
	// TODO: Add your command handler code here
	if(bstop)
		SetTimer(1,1000,0);
	else 	KillTimer(1);
	bstop=!bstop;
}

void CZLLKView::OnUpdateMenuStop(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if(bstop)
    	pCmdUI->SetCheck(true);
	else pCmdUI->SetCheck(false);	
}

void CZLLKView::OnMenuEffect() 
{
	// TODO: Add your command handler code here
	bsoundeffect=!bsoundeffect;
}

void CZLLKView::OnUpdateMenuEffect(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if(bsoundeffect)
    	pCmdUI->SetCheck(true);
	else pCmdUI->SetCheck(false);
}

void CZLLKView::OnMenuMusic() 
{
	// TODO: Add your command handler code here
	bmusic=!bmusic;
}

void CZLLKView::OnUpdateMenuMusic(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if(bmusic)
    	pCmdUI->SetCheck(true);
	else pCmdUI->SetCheck(false);	
}
void CZLLKView::DrawRectangleHollow()
{
	CDC*  pDC;
	pDC=GetDC();
	CPen penNew(PS_SOLID,1,RGB(255,255,255)),*ppenOld;
	ppenOld=pDC->SelectObject(&penNew);
	pDC->MoveTo(118,38);
	pDC->LineTo(522,38);
	pDC->LineTo(522,61);
	pDC->LineTo(118,61);
	pDC->LineTo(118,38);
}
void CZLLKView::DrawProgress(int progress)
{
	CDC *pDc;
	pDc=GetDC();
	// 渲染客户去
	CRect rect;
	rect.SetRect(120,40,120+progress,60);
    pDc->FillSolidRect(&rect,RGB(255,0,0));
}
void CZLLKView::DrawInfo(int x,int y,CString str)
{
	CDC *pDc;
	pDc=GetDC();
	pDc->SetTextColor(RGB(255,0,0));
	pDc->SetBkMode(TRANSPARENT);
	pDc->TextOut(x,y,str);
}
void CZLLKView::DrawInfo2(int x,int y,int i)
{
	CDC *pDc;
	CString str;
	pDc=GetDC();
	pDc->SetTextColor(RGB(255,0,0));
	pDc->SetBkMode(TRANSPARENT);
	str.Format("%d",i);
	// 渲染客户去
	CRect rect;
	rect.SetRect(x,y,x+40,y+40);
    pDc->FillSolidRect(&rect,RGB(100,100,200));
	pDc->TextOut(x,y,str);
}
void CZLLKView::DrawInfo3(int x,INT y,CString str)
{
	CDC *pDc;
	pDc=GetDC();
	pDc->SetTextColor(RGB(255,0,0));
	pDc->SetBkMode(TRANSPARENT);
	// 渲染客户去
	CRect rect;
	rect.SetRect(x,y,x+100,y+15);
    pDc->FillSolidRect(&rect,RGB(100,100,200));
	pDc->TextOut(x,y,str);
}
void CZLLKView::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	if(m_nUpper<400)
    {   m_nUpper=m_nUpper+m_nSpeed;
	    DrawProgress(m_nUpper);
	}
	else 
	{
		KillTimer(1);
		MessageBox(_T("你的时间用完了,SORRY!"),_T("ZYH连连看"),MB_YESNO);
		//调用排行榜
		OnMenuBack();
	}
	
	CView::OnTimer(nIDEvent);
}

void CZLLKView::OnMenuHelp() 
{
	// TODO: Add your command handler code here
	AfxMessageBox("还要帮助?\n连连看这么流行了,是个人都知道怎么玩吧\n不好意思,说过分了,好好玩吧。\n祝你好运了");
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -