/*++
Copyright (c) 2004-2005 Micro-soft
Module Name:
MineWnd.cpp
Abstract:
the mian Frame of the Mine-Game, we should do the most draw-work here,
surely,the size and style of the window should set here too.
Author:
Microsoft's Engineer - Unknown Name
improved by Weijian Luo (Arthur Luo) 15-Jun-2005
E-mail: [email protected]
Revision History: 1.0
--*/
#include "stdafx.h"
#include "Mine.h"
#include "MineWnd.h"
#include "MineDefs.h"
#include "Mmsystem.h"
#include "DlgNewRecord.h"
#include "DlgHero.h"
#include "DlgCustom.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CMineApp theApp;
#define ID_TIMER_EVENT WM_USER + 1
/////////////////////////////////////////////////////////////////////////////
CMineWnd::CMineWnd()
{
m_pSndDead = NULL;
m_pSndVictory = NULL;
m_pSndClock = NULL;
m_uTimer = 0;
m_brsBG.CreateSolidBrush(COLOR_GRAY);
LoadConfig();
if (m_bSoundful) LoadWaveSrc();
InitGame();
}
CMineWnd::~CMineWnd()
{
FreeMines();
FreeWaveSrc();
SaveConfig();
}
BEGIN_MESSAGE_MAP(CMineWnd, CWnd)
//{{AFX_MSG_MAP(CMineWnd)
ON_WM_PAINT()
ON_WM_SHOWWINDOW()
ON_WM_TIMER()
ON_WM_LBUTTONUP()
ON_WM_RBUTTONUP()
ON_WM_LBUTTONDOWN()
ON_WM_RBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_COMMAND(IDM_START, OnMemuStart)
ON_COMMAND(IDM_PRIMARY, OnMemuPrimary)
ON_COMMAND(IDM_SECOND, OnMemuSecond)
ON_COMMAND(IDM_ADVANCE, OnMemuAdvance)
ON_COMMAND(IDM_CUSTOM, OnMemuCustom)
ON_COMMAND(IDM_MARK, OnMemuMark)
ON_COMMAND(IDM_COLOR, OnMemuColor)
ON_COMMAND(IDM_SOUND, OnMemuSound)
ON_COMMAND(IDM_EXIT, OnMemuExit)
ON_COMMAND(IDM_HELP_LIST, OnMemuHelpList)
ON_COMMAND(IDM_HELP_FIND, OnMemuHelpFind)
ON_COMMAND(IDM_HELP_USE, OnMemuHelpUse)
ON_COMMAND(IDM_ABOUT, OnMemuAbout)
ON_WM_KEYDOWN()
ON_WM_INITMENU()
ON_WM_CLOSE()
ON_COMMAND(IDM_HERO, OnMemuHero)
ON_COMMAND(IDM_CHEAT, OnMemuCheat)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
//
//载入配置
//
void CMineWnd::LoadConfig()
{
//----------获取本地目录-------------*/
char exeFullPath[MAX_PATH];
CString strPath;
GetModuleFileName(NULL, exeFullPath, MAX_PATH);
strPath = CString(exeFullPath);
strPath = strPath.Left(strPath.ReverseFind('\\'));
//-----------------------------------*/
strPath += "\\config.ini";
char strPrimary[80];
char strSecond[80];
char strAdvance[80];
m_uXNum = GetPrivateProfileInt("WINDOW","XNum", 10,strPath);
m_uYNum = GetPrivateProfileInt("WINDOW","YNum", 10,strPath);
m_uMineNum = GetPrivateProfileInt("MINE","MineNum", 10,strPath);
m_uLevel = GetPrivateProfileInt("MINE","Level", 0,strPath);
m_uPrimary = GetPrivateProfileInt("SCORE","Primary", 999,strPath);
m_uSecond = GetPrivateProfileInt("SCORE","Second", 999,strPath);
m_uAdvance = GetPrivateProfileInt("SCORE","Advance", 999,strPath);
GetPrivateProfileString("HOLDER","PrimaryHolder", "匿名",strPrimary,80,strPath);
GetPrivateProfileString("HOLDER","SecondHolder", "匿名",strSecond,80,strPath);
GetPrivateProfileString("HOLDER","AdvanceHolder", "匿名",strAdvance,80,strPath);
m_szPrimary = strPrimary;
m_szSecond = strSecond;
m_szAdvance = strAdvance;
m_bMarkful = GetPrivateProfileInt("CONFIG","Markful", 0,strPath);
m_bColorful = GetPrivateProfileInt("CONFIG","Colorful", 1,strPath);
m_bSoundful = GetPrivateProfileInt("CONFIG","Soundful", 1,strPath);
}
//
// 保存
//
void CMineWnd::SaveConfig()
{
//----------获取本地目录-------------*/
char exeFullPath[MAX_PATH];
CString strPath;
GetModuleFileName(NULL, exeFullPath, MAX_PATH);
strPath = CString(exeFullPath);
strPath = strPath.Left(strPath.ReverseFind('\\'));
//-----------------------------------*/
strPath += "\\config.ini";
//雷区行列数
CString strXNum,strYNum;
//雷数 选择级别
CString strMineNum,strLevel;
//记录保持分数
CString strPrimary,strSecond,strAdvance;
//记录保持者
CString strPrimaryHolder,strSecondHolder,strAdvanceHolder;
//其他配置
CString strMarkful,strColorful,strSoundful;
strXNum.Format("%u",m_uXNum);
strYNum.Format("%u",m_uYNum);
strMineNum.Format("%u",m_uMineNum);
strLevel.Format("%u",m_uLevel);
strPrimary.Format("%u",m_uPrimary);
strSecond.Format("%u",m_uSecond);
strAdvance.Format("%u",m_uAdvance);
strPrimaryHolder.Format("%s",m_szPrimary);
strSecondHolder.Format("%s",m_szSecond);
strAdvanceHolder.Format("%s",m_szAdvance);
strMarkful.Format("%d",m_bMarkful);
strColorful.Format("%d",m_bColorful);
strSoundful.Format("%d",m_bSoundful);
WritePrivateProfileString("WINDOW","XNum", strXNum,strPath);
WritePrivateProfileString("WINDOW","YNum", strYNum,strPath);
WritePrivateProfileString("MINE","MineNum", strMineNum,strPath);
WritePrivateProfileString("MINE","Level", strLevel,strPath);
WritePrivateProfileString("SCORE","Primary", strPrimary,strPath);
WritePrivateProfileString("SCORE","Second", strSecond,strPath);
WritePrivateProfileString("SCORE","Advance", strAdvance,strPath);
WritePrivateProfileString("HOLDER","PrimaryHolder", strPrimaryHolder,strPath);
WritePrivateProfileString("HOLDER","SecondHolder", strSecondHolder,strPath);
WritePrivateProfileString("HOLDER","AdvanceHolder", strAdvanceHolder,strPath);
WritePrivateProfileString("CONFIG","Markful", strMarkful,strPath);
WritePrivateProfileString("CONFIG","Colorful", strColorful,strPath);
WritePrivateProfileString("CONFIG","Soundful", strSoundful,strPath);
}
//
//载入位图
//
void CMineWnd::LoadBitmap()
{
if (m_bColorful)
{
m_clrDark = COLOR_DARK_GRAY;
m_bmpMine.DeleteObject();
m_bmpMine.LoadBitmap(IDB_MINE_COLOR);
m_bmpNumber.DeleteObject();
m_bmpNumber.LoadBitmap(IDB_NUM_COLOR);
m_bmpButton.DeleteObject();
m_bmpButton.LoadBitmap(IDB_BTN_COLOR);
}
else
{
m_clrDark = COLOR_BLACK;
m_bmpMine.DeleteObject();
m_bmpMine.LoadBitmap(IDB_MINE_GRAY);
m_bmpNumber.DeleteObject();
m_bmpNumber.LoadBitmap(IDB_NUM_GRAY);
m_bmpButton.DeleteObject();
m_bmpButton.LoadBitmap(IDB_BTN_GRAY);
}
}
//
// 游戏的初始化
//
void CMineWnd::InitGame()
{
//位图的初始化
LoadBitmap();
m_nLeaveNum = m_uMineNum;
m_uSpendTime = 0;
m_uBtnState = BUTTON_NORMAL;
m_uGameState = GS_WAIT;
if (m_uTimer)
{
KillTimer(ID_TIMER_EVENT);
m_uTimer = 0;
}
m_pNewMine = NULL;
m_pOldMine = NULL;
FreeMines();
//初始化地图
for (UINT i = 0; i<m_uYNum; i++)
{
for (UINT j = 0; j<m_uXNum; j++)
{
m_pMines[i][j].uRow = i;
m_pMines[i][j].uCol = j;
m_pMines[i][j].uState = STATE_NORMAL;
m_pMines[i][j].uAttrib = ATTRIB_EMPTY;
m_pMines[i][j].uOldState = STATE_NORMAL;
}
}
}
//
// 布雷
//
void CMineWnd::LayMines(UINT row, UINT col)
{
//埋下随机种子
srand( (unsigned)time( NULL ) );
UINT i, j;
for(UINT index = 0; index < m_uMineNum;)
{
//取随即数
i = rand() % m_uYNum;
j = rand() % m_uXNum;
if (i == row && j == col) continue;
if(m_pMines[i][j].uAttrib != ATTRIB_MINE)
{
m_pMines[i][j].uAttrib = ATTRIB_MINE;//修改属性为雷
index++;
}
}
}
//
//雷方块拓展(对于周围无雷的空白区域)
//
void CMineWnd::ExpandMines(UINT row, UINT col)
{
UINT i, j;
UINT minRow = (row == 0) ? 0 : row - 1;
UINT maxRow = row + 2;
UINT minCol = (col == 0) ? 0 : col - 1;
UINT maxCol = col + 2;
UINT around = GetAroundNum(row, col);
m_pMines[row][col].uState = 15 - around;
m_pMines[row][col].uOldState = 15 - around;
// “打开”该区域,重绘
DrawSpecialMine(row, col);
//对周围一个雷都没有的空白区域
if (around == 0)
{
for (i = minRow; i < maxRow; i++)
{
for (j = minCol; j < maxCol; j++)
{//对�
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
第2章 扫雷.rar (51个子文件)
第2章 扫雷
Skyblue_Mine
DlgNewRecord.cpp 2KB
StdAfx.cpp 206B
Mine.opt 58KB
Mine.plg 2KB
resource.h 2KB
DlgCustom.h 1KB
DlgNewRecord.h 1KB
Mine.cpp 2KB
Mine.rc 8KB
DlgCustom.cpp 2KB
MineWnd.h 5KB
DlgHero.cpp 2KB
Debug
DlgNewRecord.obj 16KB
Mine.pdb 449KB
config.ini 218B
vc60.pdb 372KB
DlgHero.obj 22KB
Mine.obj 18KB
Mine.sbr 9KB
Mine.exe 252KB
DlgCustom.obj 12KB
DlgNewRecord.sbr 9KB
DlgCustom.sbr 7KB
MineWnd.sbr 84KB
StdAfx.obj 103KB
Mine.res 98KB
StdAfx.sbr 1.3MB
DlgHero.sbr 10KB
MineWnd.obj 104KB
DlgHero.h 1KB
StdAfx.h 999B
Mine.aps 118KB
Mine.clw 2KB
Mine.h 878B
MineDefs.h 3KB
Mine.ncb 177KB
res
WAV2.WAV 37KB
BITMAP21.BMP 1KB
Mine.ico 23KB
BITMAP10.BMP 2KB
WAV3.WAV 25KB
BITMAP31.BMP 542B
WAV1.WAV 1KB
BITMAP20.BMP 2KB
BITMAP30.BMP 2KB
Mine.rc2 396B
bitmap2.bmp 2KB
BITMAP11.BMP 1KB
Mine.dsp 5KB
MineWnd.cpp 38KB
Mine.dsw 531B
共 51 条
- 1
资源评论
破烂熊
- 粉丝: 12
- 资源: 82
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功