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

📄 russiaview.cpp

📁 一个俄罗斯方块的vc源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
{
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	RegisterHotKey(CRussiaView::m_hWnd,1001,MOD_CONTROL|MOD_ALT,'Z');
	RegisterHotKey(m_hWnd,1002,MOD_CONTROL|MOD_ALT,'z');


	CDC* pDC=GetDC();
	Game.GameInit(pDC);
	Game2.GameInit(pDC);
	Initial();
	Game2.SetPosition(320,0);
	Game.SetPosition(0,0);
	ReleaseDC(pDC);
//	Game.SetPosition(20,10);
	return 0;
}

void CRussiaView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default
	int i=nChar;
	if(nChar==VK_SPACE) 
	{
		OnMenuPause();
		return;
	}
	if(m_bPause==TRUE) return;
	switch(nChar)
	{
	case VK_LEFT:
		Game.MoveLeft();
		break;
	case VK_RIGHT:
		Game.MoveRight();
		break;		
	case VK_UP:
		Game.MoveRotate();
		break;
	case VK_DOWN:
		Game.MoveNext();
		break;
	case 65:
		Game2.MoveLeft();
		break;
	case 68:
		Game2.MoveRight();
		break;
	case 87:
		Game2.MoveRotate();
		break;
	case 83:
		Game2.MoveNext();
		break;

	}
	CDC* pDC=GetDC();
	Game.Draw(pDC);
	if(CurrentGameFlag==2)
		Game2.Draw(pDC);
	ReleaseDC(pDC);

	CView::OnKeyDown(nChar, nRepCnt, nFlags);
}

void CRussiaView::OnUpdateMenuPause(CCmdUI* pCmdUI) 
{
	pCmdUI->SetCheck(m_bPause);
}

void CRussiaView::OnMenuSetup() 
{
	// TODO: Add your command handler code here
	m_bPause=TRUE;
	Game.PlayMusic(FALSE);
	CDialogSetup dlg;
	dlg.m_Difficult=Game.GetLevel();
	dlg.m_Speed=Game.GetSpeed();
	dlg.m_Music=m_bMusic;
	if(dlg.DoModal()==IDOK)
	{
		Game.SetLevel(dlg.m_Difficult);
		Game.SetSpeed(dlg.m_Speed);
		Game.SetLevel(dlg.m_Difficult);
		Game2.SetLevel(dlg.m_Difficult);
		Game2.SetSpeed(dlg.m_Speed);
		Game2.SetLevel(dlg.m_Difficult);
		m_bMusic=dlg.m_Music;
	}

	Invalidate(false);
}

void CRussiaView::OnMenuSave() 
{
	m_bPause=true;
	if(CurrentGameFlag!=1) return;
	CFileDialog dlg(FALSE,"fly",NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,"(*.FLY)|*.fly|All Files|*.*||",this);
	if(dlg.DoModal()==IDOK) 
		Game.SaveGame(dlg.GetFileName());
}

void CRussiaView::OnMenuRead() 
{
	m_bPause=true;
	if(CurrentGameFlag!=1) return;
	CFileDialog dlg(TRUE,"fly",NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,"(*.FLY)|*.fly|All Files|*.*||",this);
	if(dlg.DoModal()==IDOK) 
	{
		Game.ReadGame(dlg.GetFileName());
		m_bStart=TRUE;
	}
	Invalidate(false);

}

void CRussiaView::OnMenuNetstart() 
{
	// TODO: Add your command handler code here
	MessageBox("请您购买注册版(E_Mail:kiler@cmmail.com)","俄罗斯方块",MB_ICONINFORMATION);
	
}

void CRussiaView::OnMenuDoublestart() 
{
	MessageBox("请您购买注册版(E_Mail:kiler@cmmail.com)","俄罗斯方块",MB_ICONINFORMATION);
	return;
	CWinApp* pApp = AfxGetApp();
	int dx=pApp->GetProfileInt("Settings","方块大小",20);
	int m1=111+dx*10;
	int m2=85+dx*24;

	
	if(CurrentGameFlag!=2)
	{
		//调整窗口大小
		AfxGetMainWnd() ->SetWindowPos(NULL,0,0,2*m1,m2,SWP_NOMOVE|SWP_NOZORDER|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_SYSMENU );
		AfxGetMainWnd()->CenterWindow();
	}

	CurrentGameFlag=2;
	//1为单人游戏,2为双人游戏,3为网络游戏
	Game.SetPosition(m1,0);
	Game2.SetPosition(0,0);
	m_bPause=false;
	m_bStart=true;
	SetTimer(9999,50*(11-Game.GetSpeed()),NULL);
	Game.Start();
	Game.Draw(GetDC());
	Game2.Start();
	Game2.Draw(GetDC());

	//播放声音
	Game2.PlayMusic(m_bMusic);
	Game.PlayMusic(m_bMusic);
	
}

void CRussiaView::OnMenuHelp() 
{
	CDialogHelp dlg;
	dlg.DoModal();
}

void CRussiaView::OnMenuColor() 
{
	m_bPause=TRUE;
	Game.PlayMusic(FALSE);
	CDialogColorSetup	dlg;

	dlg.m_clrCube=Game.m_clrCube;//方块颜色
	dlg.m_clrDeclareCube=Game.m_clrDeclareCube;//声明区域的方块颜色
	dlg.m_clrMaxRect=Game.m_clrMaxRect;//最大区域颜色
	dlg.m_clrDeclareRect=Game.m_clrDeclareRect;//声明区域颜色
	dlg.m_clrDiamondsRect=Game.m_clrDiamondsRect;//运行区域颜色
	dlg.m_clrLine=Game.m_clrLine;//方格线颜色
	dlg.m_clrDeclareFont=Game.m_clrDeclareFont;	//声明区域的字体颜色
	dlg.m_clrGameOverFont=Game.m_clrGameOverFont;	//游戏结束字体的颜色
	dlg.m_bRandomCubeColor=Game.m_bRandomCubeColor;	//随机产生运动方块颜色
	if(dlg.DoModal()==IDOK)
	{
		//颜色设置
		Game.m_clrCube=dlg.m_clrCube;//方块颜色
		Game.m_clrDeclareCube=dlg.m_clrDeclareCube;//声明区域的方块颜色
		Game.m_clrMaxRect=dlg.m_clrMaxRect;//最大区域颜色
		Game.m_clrDeclareRect=dlg.m_clrDeclareRect;//声明区域颜色
		Game.m_clrDiamondsRect=dlg.m_clrDiamondsRect;//运行区域颜色
		Game.m_clrLine=dlg.m_clrLine;//方格线颜色
		Game.m_clrDeclareFont=dlg.m_clrDeclareFont;	//声明区域的字体颜色
		Game.m_clrGameOverFont=dlg.m_clrGameOverFont;	//游戏结束字体的颜色
		Game.m_bRandomCubeColor=dlg.m_bRandomCubeColor;//随机产生运动方块颜色

		Game2.m_clrCube=dlg.m_clrCube;//方块颜色
		Game2.m_clrDeclareCube=dlg.m_clrDeclareCube;//声明区域的方块颜色
		Game2.m_clrMaxRect=dlg.m_clrMaxRect;//最大区域颜色
		Game2.m_clrDeclareRect=dlg.m_clrDeclareRect;//声明区域颜色
		Game2.m_clrDiamondsRect=dlg.m_clrDiamondsRect;//运行区域颜色
		Game2.m_clrLine=dlg.m_clrLine;//方格线颜色
		Game2.m_clrDeclareFont=dlg.m_clrDeclareFont;	//声明区域的字体颜色
		Game2.m_clrGameOverFont=dlg.m_clrGameOverFont;	//游戏结束字体的颜色
		Game2.m_bRandomCubeColor=dlg.m_bRandomCubeColor;//随机产生运动方块颜色

		if(CurrentGameFlag==2)
		{//1为单人游戏,2为双人游戏,3为网络游戏
			Game.SetPosition(302,0);
			Game2.SetPosition(0,0);
		}
		else if(CurrentGameFlag==1)
		{
			Game.SetPosition(0,0);
			Game2.SetPosition(302,0);
		}
		Invalidate(FALSE);
	}

}

void CRussiaView::OnMenuPlayer() 
{
	CDialogPlayer dlg;
	dlg.DoModal();

}



int CRussiaView::GetMinScore()
{
			TCHAR szDir [MAX_PATH];
			:: GetWindowsDirectory (szDir, MAX_PATH);

			CString str,s[5];
			int i,m[5];

			CStdioFile file;
			for(i=0;i<5;i++)
			{
				s[i]="swallow";
				m[i]=50;
			}	//初始值置为50

							
			//先从文件中把成绩和姓名读出存入m[i]和s[i]中
			str.Format("%s\\kiler.ini",szDir);
			if(file.Open(str,CFile::modeRead)!=0)
			{
				CArchive ar(&file,CArchive::load);
				
				for(i=0;i<5;i++)
				{
					ar.ReadString(str);
					sscanf(str,"%d",&m[i]);
				}


				ar.Close();
				file.Close();
			}
		return(m[4]);
}


void CRussiaView::Initial()
{

	CWinApp* pApp = AfxGetApp();
	Game.m_clrCube=pApp->GetProfileInt(szSection, clrCube, Game.m_clrCube);
	Game.m_clrDeclareCube=pApp->GetProfileInt(szSection, clrDeclareCube, Game.m_clrDeclareCube);
	Game.m_clrMaxRect =pApp->GetProfileInt(szSection,clrMaxRect ,Game.m_clrMaxRect );
	Game.m_clrDeclareRect=pApp->GetProfileInt(szSection,clrDeclareRect , Game.m_clrDeclareRect);
	Game.m_clrDiamondsRect=pApp->GetProfileInt(szSection,clrDiamondsRect , Game.m_clrDiamondsRect);
	Game.m_clrLine=pApp->GetProfileInt(szSection, clrLine, Game.m_clrLine);
	Game.m_clrDeclareFont =pApp->GetProfileInt(szSection, clrDeclareFont,Game.m_clrDeclareFont );
	Game.m_clrGameOverFont=pApp->GetProfileInt(szSection,clrGameOverFont , Game.m_clrGameOverFont);
	Game.m_bRandomCubeColor=pApp->GetProfileInt(szSection, bRandomCubeColor,Game.m_bRandomCubeColor );

	Game2.m_clrCube=pApp->GetProfileInt(szSection, clrCube, Game.m_clrCube);
	Game2.m_clrDeclareCube=pApp->GetProfileInt(szSection, clrDeclareCube, Game.m_clrDeclareCube);
	Game2.m_clrMaxRect =pApp->GetProfileInt(szSection,clrMaxRect ,Game.m_clrMaxRect );
	Game2.m_clrDeclareRect=pApp->GetProfileInt(szSection,clrDeclareRect , Game.m_clrDeclareRect);
	Game2.m_clrDiamondsRect=pApp->GetProfileInt(szSection,clrDiamondsRect , Game.m_clrDiamondsRect);
	Game2.m_clrLine=pApp->GetProfileInt(szSection, clrLine, Game.m_clrLine);
	Game2.m_clrDeclareFont =pApp->GetProfileInt(szSection, clrDeclareFont,Game.m_clrDeclareFont );
	Game2.m_clrGameOverFont=pApp->GetProfileInt(szSection,clrGameOverFont , Game.m_clrGameOverFont);
	Game2.m_bRandomCubeColor=pApp->GetProfileInt(szSection, bRandomCubeColor,Game.m_bRandomCubeColor );

	m_bMusic=pApp->GetProfileInt(szSection, Music, FALSE);
	Game.SetSpeed(pApp->GetProfileInt(szSection, Speed, 5));
	Game.SetLevel(pApp->GetProfileInt(szSection,Difficult ,2));
	Game2.SetSpeed(pApp->GetProfileInt(szSection, Speed, 5));
	Game2.SetLevel(pApp->GetProfileInt(szSection,Difficult ,2));

}

void CRussiaView::OnDestroy() 
{
	CView::OnDestroy();
	
	// TODO: Add your message handler code here
	UnregisterHotKey(m_hWnd,1001);
	UnregisterHotKey(m_hWnd,1002);
	
}

⌨️ 快捷键说明

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