📄 russiangamedlg.cpp
字号:
// RussianGameDlg.cpp : implementation file
//
#include "stdafx.h"
#include "RussianGame.h"
#include "RussianGameDlg.h"
#include "HeroDlg.h"
#include "NameDlg.h"
#include "mmsystem.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define LeftMargin 20
#define TopMargin 20
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CRussianGameDlg dialog
CRussianGameDlg::CRussianGameDlg(CWnd* pParent /*=NULL*/)
: CDialog(CRussianGameDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CRussianGameDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_iScore=0;
m_iSp=1;
m_iLine=0;
pause=FALSE;
gameover=TRUE;
FlagSound=FALSE;
board.game =FALSE;
board.level =1;
board.scroe =0;
board.pic[0].LoadBitmap(IDB_BITMAP0);
board.pic[1].LoadBitmap(IDB_BITMAP1);
rect.left =LeftMargin;
rect.top =TopMargin;
rect.right =LeftMargin+202;
rect.bottom =TopMargin+362;
picnext[1].LoadBitmap(IDB_PIC1);
picnext[2].LoadBitmap(IDB_PIC2);
picnext[3].LoadBitmap(IDB_PIC3);
picnext[4].LoadBitmap(IDB_PIC4);
picnext[5].LoadBitmap(IDB_PIC5);
picnext[6].LoadBitmap(IDB_PIC6);
picnext[7].LoadBitmap(IDB_PIC7);
int i,j;
for(i=0;i<11;i++)
for(j=0;j<19;j++)
board.square[i][j]=0;
scorenum[0]=AfxGetApp()->GetProfileInt(_T("英雄榜"),_T("scorenum1"),500);
scorenum[1]=AfxGetApp()->GetProfileInt(_T("英雄榜"),_T("scorenum2"),500);
scorenum[2]=AfxGetApp()->GetProfileInt(_T("英雄榜"),_T("scorenum3"),500);
scorenum[3]=AfxGetApp()->GetProfileInt(_T("英雄榜"),_T("scorenum4"),500);
scorenum[4]=AfxGetApp()->GetProfileInt(_T("英雄榜"),_T("scorenum5"),500);
scorename[0]=AfxGetApp()->GetProfileString(_T("英雄榜"),_T("scorename1"),_T("无名英雄"));
scorename[1]=AfxGetApp()->GetProfileString(_T("英雄榜"),_T("scorename2"),_T("无名英雄"));
scorename[2]=AfxGetApp()->GetProfileString(_T("英雄榜"),_T("scorename3"),_T("无名英雄"));
scorename[3]=AfxGetApp()->GetProfileString(_T("英雄榜"),_T("scorename4"),_T("无名英雄"));
scorename[4]=AfxGetApp()->GetProfileString(_T("英雄榜"),_T("scorename5"),_T("无名英雄"));
}
void CRussianGameDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CRussianGameDlg)
DDX_Control(pDX, IDC_SOUND, m_Sound);
DDX_Control(pDX, IDC_EXIT, m_Exit);
DDX_Control(pDX, IDC_START, m_Start);
DDX_Control(pDX, IDC_SPADD, m_SpAdd);
DDX_Control(pDX, IDC_PAUSE, m_Pause);
DDX_Control(pDX, IDC_LINEADD, m_LineAdd);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CRussianGameDlg, CDialog)
//{{AFX_MSG_MAP(CRussianGameDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_SPADD, OnSpadd)
ON_BN_CLICKED(IDC_EXIT, OnExit)
ON_BN_CLICKED(IDC_START, OnStart)
ON_WM_TIMER()
ON_WM_KEYDOWN()
ON_BN_CLICKED(IDC_PAUSE, OnPause)
ON_BN_CLICKED(IDC_LINEADD, OnLineadd)
ON_BN_CLICKED(IDC_SOUND, OnSound)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CRussianGameDlg message handlers
BOOL CRussianGameDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
RECT rect;
GetWindowRect(&rect);
int cx=rect.right -rect.left ;
int cy=rect.bottom -rect.top ;
POINT pos[9];
pos[0].x =0;
pos[0].y = 0;
pos[1].x = cx;
pos[1].y = 0;
pos[2].x = cx;
pos[2].y = cy - 20;
pos[3].x = cx - 25;
pos[3].y = cy - 20;
pos[4].x = cx - 50;
pos[4].y = cy;
pos[5].x = 50;
pos[5].y = cy;
pos[6].x = 25;
pos[6].y = cy - 20;
pos[7].x = 0;
pos[7].y = cy - 20;
pos[8] = pos[0];
HRGN hrgn;//,hrgn1;
hrgn=CreatePolygonRgn(pos,9,2);
CDC *pDC=GetDC();
// SetBkMode(pDC->m_hDC,TRANSPARENT);
// pDC->BeginPath();
// pDC->TextOut(cx/2-20,cy-10,"英雄无敌",8);
// pDC->EndPath();
// hrgn1=PathToRegion(pDC->m_hDC);
//CombineRgn(hrgn,hrgn,hrgn1,RGN_DIFF);
// SetWindowRgn(hrgn,TRUE);
m_SpAdd.SetIcon(IDI_ICONADD);
m_SpAdd.AddToolTip(_T("水平"));
m_SpAdd.SetBtnCursor(IDC_HAND);
m_SpAdd.SetActiveFgColor(RGB(0,0,255));
m_Start.SetIcon(IDI_ICONSTART);
m_Start.AddToolTip(_T("开始"));
m_Start.SetBtnCursor(IDC_HAND);
m_Start.SetActiveFgColor(RGB(0,0,255));
m_Pause.SetIcon(IDI_ICONPAUSE);
m_Pause.AddToolTip(_T("暂停"));
m_Pause.SetBtnCursor(IDC_HAND);
m_Pause.SetActiveFgColor(RGB(0,0,255));
m_Exit.SetIcon(IDI_ICONEXIT);
m_Exit.AddToolTip(_T("退出"));
m_Exit.SetBtnCursor(IDC_HAND);
m_Exit.SetActiveFgColor(RGB(0,0,255));
m_LineAdd.SetIcon(IDI_ICONADD);
m_LineAdd.AddToolTip(_T("行数"));
m_LineAdd.SetBtnCursor(IDC_HAND);
m_LineAdd.SetActiveFgColor(RGB(0,0,255));
m_Sound.SetIcon(IDI_ICONSOUND);
m_Sound.AddToolTip(_T("声音"));
m_Sound.SetBtnCursor(IDC_HAND);
m_Sound.SetActiveFgColor(RGB(0,0,255));
Score_num.Create(this,285,105,0,5);
Sp_num.Create(this,305,157,0,2);
Line_num.Create(this,305,243,0,2);
//TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CRussianGameDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CRussianGameDlg::OnPaint()
{
CPaintDC dc(this);
if (IsIconic())
{
// device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
/*CDC memdc;
CDC *pDC=GetDC();
RECT rect;
memdc.CreateCompatibleDC(pDC);
GetClientRect(&rect);
CBitmap bitmap;
bitmap.LoadBitmap(IDB_BACKPIC);
int cx=rect.right -rect.left ;
int cy=rect.bottom -rect.top ;
memdc.SelectObject(bitmap);
pDC->BitBlt(0,0,cx,cy,&memdc,0,0,SRCCOPY);
ReleaseDC(pDC);*/
CBrush br(RGB(0,0,255));
CRect rc=rect;
dc.FrameRect(&rc,&br);
rc.InflateRect(2,2);
CBrush br1(RGB(0,255,0));
dc.FrameRect(&rc,&br1);
CBrush br2(RGB(255,0,0));
rc.InflateRect(2,2);
dc.FrameRect(&rc,&br2);
br.DeleteObject();
br1.DeleteObject();
br2.DeleteObject();
rc.SetRectEmpty();
paintpic(&dc);
Score_num.SetNumber(board.scroe);
Sp_num.SetNumber(board.level);
Line_num.SetNumber(m_iLine);
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CRussianGameDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CRussianGameDlg::checkforhighscore()
{
getscore();
int n,j;
for (n=0;n<5;n++)
if(board.scroe >= scorenum[n])
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -