gusucode.com > 基于VC++编程war3连连看源码程序 > war3连连看/源代码/MainFrm.cpp
// MainFrm.cpp : implementation of the CMainFrame class // #include "stdafx.h" #include "link.h" #include "MainFrm.h" #include "HtmlHelp.h" //打开chm帮助文件 #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CMainFrame IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd) BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd) //{{AFX_MSG_MAP(CMainFrame) ON_COMMAND(ID_New_Game, OnNewGame) ON_COMMAND(ID_APP_ABOUT, OnAppAbout) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CMainFrame construction/destruction CMainFrame::CMainFrame() { // TODO: add member initialization code here } CMainFrame::~CMainFrame() { } BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) { //设置窗口的属性 cs.cx = 900 ; //窗口的宽度 cs.cy = 700; //窗口的高度 cs.x = 0 ; //窗口的位置,x轴 cs.y = 0 ; //窗口位置,y轴 if( !CFrameWnd::PreCreateWindow(cs) ) return FALSE; // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return TRUE; } ///////////////////////////////////////////////////////////////////////////// // CMainFrame diagnostics #ifdef _DEBUG void CMainFrame::AssertValid() const { CFrameWnd::AssertValid(); } void CMainFrame::Dump(CDumpContext& dc) const { CFrameWnd::Dump(dc); } #endif //_DEBUG extern CLinkApp theApp; #include <fstream> #include <string> #include <iostream> using namespace std ; //新建游戏 void CMainFrame::OnNewGame() { srand(time(0)); int i , j ; for( i = 0 ;i<leny ; ++i ) for( j =0 ; j<lenx ; ++j ) theApp.PicArray[i][j].visible = false ; int x , y ; for( i=0; i<lenx-1 ; ++i ) { for( j =0 ; j<leny ; ++j ) { bool re = true ; while( re ) { x = rand()%lenx ; y = rand()%leny ; if( theApp.PicArray[y][x].visible == false ) { theApp.PicArray[y][x].type = i ; theApp.PicArray[y][x].visible = true ; theApp.PicArray[y][x].x = x ; theApp.PicArray[y][x].y = y ; re = false ; } } } } for( i = 0; i<leny ; ++i ) for( j =0 ; j<lenx ; ++j ) if( theApp.PicArray[i][j].visible == false ) { theApp.PicArray[i][j].type = lenx-1 ; theApp.PicArray[i][j].visible = true ; theApp.PicArray[i][j].x = j ; theApp.PicArray[i][j].y = i ; } theApp.PreClick.x = -1 ; theApp.PreClick.y = -1 ; theApp.score = 0 ; theApp.stage = 1 ; CDC* pDC=GetDC(); theApp.PaintPicture(pDC); CString str ; str.Format( "您的得分是 %u ,共%d关,现在是第 %d 关", theApp.score,totalStage ,theApp.stage) ; pDC->TextOut( 150 , 15 , str) ; string temp ; ifstream input("picture_introduction.txt",ios::in) ; input.seekg(0) ; if( input == NULL ) { MessageBox( "打开图片介绍文本失败!","错误",MB_OK ) ; return ; } //在picture_introduction.txt中读入图片的介绍信息 int total_num = lenx * totalStage ; CString message; i=0 ; while( i < total_num ) { input>>temp ; CString t ; t.Format("%s", temp ); if( !temp.empty() && temp[0] != '#' ) { theApp.pic_info[i/lenx][i%lenx].Format("%-18s", temp.c_str()); ++i ; } temp=""; } ReleaseDC( pDC ) ; } //显示chm帮助文档 void CMainFrame::OnAppAbout() { ShellExecute(NULL, "open", "help.chm", NULL, NULL, SW_SHOWNORMAL);//打开指定的文件 }