/*++
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: skybluehacker@yahoo.com.cn
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++)
{//对�
fengqiao1999
- 粉丝: 493
- 资源: 16
最新资源
- 料带自动上料机含bom和3D图纸和工程图机械结构设计图纸和其它技术资料和技术方案非常好100%好用.zip
- 使用Java多线程和同步机制实现生产者-消费者模式.zip
- 端子排自动切割设备含bom工程图机械结构设计图纸和其它技术资料和技术方案非常好100%好用.zip
- Python爬虫入门实例:利用requests和BeautifulSoup抓取网页标题
- HBase常用的Shell命令
- Linux下Oracle 11g的完整安装与配置指南
- MySQL多平台安装教程:Windows、macOS与Linux
- 新年快乐,喜庆html
- 单片机综合实验储物箱重庆邮电大学
- Screenshot_20241224_205242_com.tencent.tmgp.sgame.jpg
- html css网页制作成品.docx
- Selenium-ECShop项目文档
- 实验报告,重庆邮电大学,单片机,大作业
- 汽车防撞梁总成装配台3D图纸和工程图机械结构设计图纸和其它技术资料和技术方案非常好100%好用.zip
- Java平台Maven项目管理和构建工具的安装与配置
- 重庆邮电大学所有实验单片机,大作业,串口,双机编程,程序文件
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈