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

📄 ptgamedlg.cpp

📁 美女品图
💻 CPP
📖 第 1 页 / 共 2 页
字号:
				CDialog::EndDialog(0);
			}
			track[tracksteps]=3;
			tempsite.x =blacksite.x;
			tempsite.y =blacksite.y-1 ;
			siteinfo[blacksite.x][blacksite.y].x = siteinfo[tempsite.x][tempsite.y].x;
            siteinfo[blacksite.x][blacksite.y].y = siteinfo[tempsite.x][tempsite.y].y;
            tempsite.x = siteinfo[blacksite.x][blacksite.y].x;
            tempsite.y = siteinfo[blacksite.x][blacksite.y].y;
            paintpic(blacksite,tempsite); 
            blacksite.y = blacksite.y - 1;
            paintblack();
            paintline();
            if(tracksteps > 1)
			{
                if(track[tracksteps - 1]== 4)
				{
                    tracksteps = tracksteps - 2;
                }
            }
		}
		break;
	case VK_DOWN:
		if(blacksite.y<vnums)
		{
			tracksteps+=1;
			if(tracksteps>1000)
			{
				MessageBox("所定义数组空间已用完,你水平太臭了!","俄罗斯方块游戏",MB_OK|MB_ICONINFORMATION);
				CDialog::EndDialog(0);
			}
			track[tracksteps]=4;
			tempsite.x =blacksite.x;
			tempsite.y =blacksite.y+1 ;
			siteinfo[blacksite.x][blacksite.y].x = siteinfo[tempsite.x][tempsite.y].x;
            siteinfo[blacksite.x][blacksite.y].y = siteinfo[tempsite.x][tempsite.y].y;
            tempsite.x = siteinfo[blacksite.x][blacksite.y].x;
            tempsite.y = siteinfo[blacksite.x][blacksite.y].y;
            paintpic(blacksite,tempsite); 
            blacksite.y = blacksite.y + 1;
            paintblack();
            paintline();
            if(tracksteps > 1)
			{
                if(track[tracksteps - 1]== 3)
				{
                    tracksteps = tracksteps - 2;
                }
            }
		}
		break;
	}
	CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
}

void CPtGameDlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	struct site mousesite;
	mousesite.x =point.x/cellwidth+1;
	mousesite.y =point.y/cellheight+1;
	if(abs(mousesite.x-blacksite.x)+abs(mousesite.y-blacksite.y)==1)
	{
		if(mousesite.x - blacksite.x == 1)
		{
			::SendMessage(m_hWnd,WM_KEYDOWN,VK_RIGHT,0);
		}
        if(mousesite.x - blacksite.x == -1)
		{
			::SendMessage(m_hWnd,WM_KEYDOWN,VK_LEFT,0);
		}
		if(mousesite.y - blacksite.y == 1)
		{
			::SendMessage(m_hWnd,WM_KEYDOWN,VK_DOWN,0);
		}
		if(mousesite.y - blacksite.y == -1)
		{
			::SendMessage(m_hWnd,WM_KEYDOWN,VK_UP,0);
		}
	}
	winornot();//判断是否已赢得这局游戏
	CDialog::OnLButtonDown(nFlags, point);
}

void CPtGameDlg::OnNewgame() 
{
	// TODO: Add your command handler code here
	tracksteps=0;
	cellwidth=clientwidth/hnums;
	cellheight=clientheight/vnums;
	initialsiteinfo();
	blacksite.x =hnums;
	blacksite.y =vnums;
	Invalidate(FALSE);
	initialgame();
}

void CPtGameDlg::initialgame()
{
	int i,temp;
	srand(time(NULL));
	for(i=1;i<300;i++)
	{
		temp=rand()%4+1;
		switch(temp)
		{
		case 1:
			::SendMessage(m_hWnd,WM_KEYDOWN,VK_LEFT,0);
			break;
		case 2:
			::SendMessage(m_hWnd,WM_KEYDOWN,VK_RIGHT,0);
			break;
		case 3:
			::SendMessage(m_hWnd,WM_KEYDOWN,VK_UP,0);
			break;
		case 4:
			::SendMessage(m_hWnd,WM_KEYDOWN,VK_DOWN,0);
			break;
		}
	}
}

void CPtGameDlg::OnAutoplay() 
{
	// TODO: Add your command handler code here
	tempsteps=tracksteps;
	HMENU hmenu;
	hmenu=::GetSubMenu(::GetMenu(m_hWnd),0);
	if(autoplay==FALSE)
	{
		if(tempsteps>0)
		{
		m_wndStatusBar.SetText("正在自动拼图",0,0);
		autoplay=TRUE;
		::ModifyMenu(hmenu,1,MF_BYPOSITION|MF_STRING,::GetMenuItemID(hmenu,1),"停止自动拼图");
		SetTimer(1,300,NULL);
		}
	}
	else
	{
		autoplay=FALSE;
		KillTimer(1);
		::ModifyMenu(hmenu,1,MF_BYPOSITION|MF_STRING,::GetMenuItemID(hmenu,1),"自动拼图");
		m_wndStatusBar.SetText("正在游戏",0,0);
	}
}

void CPtGameDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	switch(nIDEvent)
	{
	case 1:
		switch(track[tempsteps])
		{
		case 1:
			::SendMessage(m_hWnd,WM_KEYDOWN,VK_RIGHT,0);
			break;
		case 2:
			::SendMessage(m_hWnd,WM_KEYDOWN,VK_LEFT,0);
			break;
		case 3:
			::SendMessage(m_hWnd,WM_KEYDOWN,VK_DOWN,0);
			break;
		case 4:
			::SendMessage(m_hWnd,WM_KEYDOWN,VK_UP,0);
			break;
		}
		tempsteps-=1;
		if(tracksteps==0)
		{
			KillTimer(1);
			paintpic(blacksite,blacksite);
			autoplay=FALSE;
			MessageBox("自动拼图已完成!","拼图游戏",MB_OK|MB_ICONINFORMATION);
			HMENU hmenu;
			hmenu=::GetSubMenu(::GetMenu(m_hWnd),0);
			::ModifyMenu(hmenu,1,MF_BYPOSITION|MF_STRING,::GetMenuItemID(hmenu,1),"自动拼图");
			m_wndStatusBar.SetText("正在游戏",0,0);
		}
		break;
	case 2:
		m_iStart+=1;
		m_wndStatusBar.SetText(m_strInfo.Mid(m_iStart),2,0);
		if(m_iStart>=m_strInfo.GetLength())m_iStart=0;
		break;
	}
	CDialog::OnTimer(nIDEvent);
}

void CPtGameDlg::OnExit() 
{
	// TODO: Add your command handler code here
	KillTimer(1);
	CDialog::EndDialog(0);
}

void CPtGameDlg::OnSet() 
{
	// TODO: Add your command handler code here
	CSettingDlg set;
	if(set.DoModal()==IDOK)
	{
		hnums=set.m_iCols;
		vnums=set.m_iRows;
		musiconoff=set.m_bMusic;
		musicfilename=set.m_strMusicFileName;
		if(musiconoff==TRUE)
		{
			PlayMusic();
		}
		else
		{
			MCI_GENERIC_PARMS mciGP;
			mciSendCommand(m_wID,MCI_STOP,MCI_NOTIFY,(DWORD)(LPVOID)&mciGP);
		}
		CPtGameDlg::OnNewgame();
	}
}

void CPtGameDlg::winornot()
{
	int i,j;
	for(i = 1;i<=hnums;i++)
	{
		for(j = 1;j<=vnums;j++)
		{
			if(i !=blacksite.x || j != blacksite.y)
				if(siteinfo[i][j].x !=i || siteinfo[i][j].y !=j)
					return;
		}
	}
	paintpic(blacksite, blacksite);
	paintline();
	MessageBox("恭喜你,你已赢得这局游戏,要重新开始,请单击 '新游戏' ","拼图游戏",MB_OK|MB_ICONINFORMATION);
	tracksteps = 0;
	return;
}

void CPtGameDlg::OnUserpic() 
{
	// TODO: Add your command handler code here
	CString filter="BMP文件(*.bmp)|*.bmp";
	CFileDialog picfile(TRUE,NULL,NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,filter);
	if(picfile.DoModal()==IDOK)
	{
		HBITMAP hbitmap;
		hbitmap=(HBITMAP)::LoadImage(NULL,picfile.GetPathName(),IMAGE_BITMAP,500,350,LR_LOADFROMFILE);
		bitmap.Detach();
		bitmap.Attach(hbitmap);
		CPtGameDlg::OnNewgame();
	}

}

void CPtGameDlg::OnAbout() 
{
	// TODO: Add your command handler code here
	CAboutDlg about;
	about.DoModal();
}



void CPtGameDlg::PlayMusic()
{
	MCI_GENERIC_PARMS mciGP;
	mciSendCommand(m_wID,MCI_CLOSE,MCI_NOTIFY,(DWORD)(LPVOID)&mciGP);
	MCI_OPEN_PARMS mciOP;
	DWORD dwReturn;
	mciOP.lpstrDeviceType=NULL;
	mciOP.lpstrElementName=musicfilename;
	dwReturn=mciSendCommand(NULL,MCI_OPEN,MCI_OPEN_ELEMENT,(DWORD)(LPVOID)&mciOP);
	if(dwReturn==0)
	{
		m_wID=mciOP.wDeviceID;
	}
	MCI_PLAY_PARMS mciPP;
	mciSendCommand(m_wID,MCI_PLAY,MCI_NOTIFY,(DWORD)(LPVOID)&mciPP);
}

void CPtGameDlg::OnPrelook() 
{
	// TODO: Add your command handler code here
	CLookDlg look;
	look.DoModal();
}

void CPtGameDlg::OnPic1() 
{
	// TODO: Add your command handler code here
	gamepicture=IDB_BITMAP1;
	AfxGetApp()->WriteProfileInt(_T("游戏参数"),_T("gamepicture"),IDB_BITMAP1);
	bitmap.Detach();
	bitmap.LoadBitmap(IDB_BITMAP1);
	CPtGameDlg::OnNewgame();
}

void CPtGameDlg::OnPic2() 
{
	// TODO: Add your command handler code here
	gamepicture=IDB_BITMAP2;
	AfxGetApp()->WriteProfileInt(_T("游戏参数"),_T("gamepicture"),IDB_BITMAP2);
	bitmap.Detach();
	bitmap.LoadBitmap(IDB_BITMAP2);
	CPtGameDlg::OnNewgame();
	
}

void CPtGameDlg::OnPic3() 
{
	// TODO: Add your command handler code here
	gamepicture=IDB_BITMAP3;
	AfxGetApp()->WriteProfileInt(_T("游戏参数"),_T("gamepicture"),IDB_BITMAP3);
	bitmap.Detach();
	bitmap.LoadBitmap(IDB_BITMAP3);
	CPtGameDlg::OnNewgame();
	
}

void CPtGameDlg::OnPic4() 
{
	// TODO: Add your command handler code here
	gamepicture=IDB_BITMAP4;
	AfxGetApp()->WriteProfileInt(_T("游戏参数"),_T("gamepicture"),IDB_BITMAP4);
	bitmap.Detach();
	bitmap.LoadBitmap(IDB_BITMAP4);
	CPtGameDlg::OnNewgame();
	
}

void CPtGameDlg::OnPic5() 
{
	// TODO: Add your command handler code here
	gamepicture=IDB_BITMAP5;
	AfxGetApp()->WriteProfileInt(_T("游戏参数"),_T("gamepicture"),IDB_BITMAP5);
	bitmap.Detach();
	bitmap.LoadBitmap(IDB_BITMAP5);
	CPtGameDlg::OnNewgame();
	
}

void CPtGameDlg::OnPic6() 
{
	// TODO: Add your command handler code here
	gamepicture=IDB_BITMAP6;
	AfxGetApp()->WriteProfileInt(_T("游戏参数"),_T("gamepicture"),IDB_BITMAP6);
	bitmap.Detach();
	bitmap.LoadBitmap(IDB_BITMAP6);
	CPtGameDlg::OnNewgame();
	
}

void CPtGameDlg::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	KillTimer(1);
	KillTimer(2);
	CDialog::OnClose();
}

void CPtGameDlg::OnMousetell() 
{
	// TODO: Add your command handler code here
	HMENU hmenu;
	hmenu=::GetSubMenu(::GetMenu(m_hWnd),0);
	if(m_bMouseTell==FALSE)
	{
		m_bMouseTell=TRUE;
		::ModifyMenu(hmenu,2,MF_BYPOSITION|MF_STRING,::GetMenuItemID(hmenu,2),"取消鼠标提示");
	}
	else
	{
		m_bMouseTell=FALSE;
		::ModifyMenu(hmenu,2,MF_BYPOSITION|MF_STRING,::GetMenuItemID(hmenu,2),"鼠标提示");
	}
}


void CPtGameDlg::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	struct site mousesite;
	mousesite.x = point.x/cellwidth+1;
	mousesite.y = point.y/cellheight+1;
	if(m_bMouseTell==TRUE)
	{	
		CString str;
		char buffer[5];
		str="该图块在原始图片中的位置: ( 第 " ;
		_itoa(siteinfo[mousesite.x][mousesite.y].y,buffer,10);
		str+=buffer;
		str+=" 行, 第 ";
		_itoa(siteinfo[mousesite.x][mousesite.y].x,buffer,10);
		str+=buffer;
		str+=" 列 )";
		m_wndStatusBar.SetText(str,1,0);
	}
	else
		m_wndStatusBar.SetText("用方向键移动,或用鼠标左键单击黑块周围图块",1,0);
	
	CDialog::OnMouseMove(nFlags, point);
}

⌨️ 快捷键说明

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