📄 xunaelsfkdlg.cpp
字号:
// XuNaElsFKDlg.cpp : implementation file
//
#include "stdafx.h"
#include "XuNaElsFK.h"
#include "XuNaElsFKDlg.h"
#include "GameAboutDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define M 13
#define N 20
#define V 34
int G[M][N];
int Run_Time=0;
#define Clear_away one(0,object.x, object.y)
int X=47,Y=40,r=25;
COLORREF BackColor=RGB(200,140,140);
OBJECT object;
int a0,a1,a2,a3,a4,a5,a6,a7; int ZZ;
OBJECT object2;
int b0,b1,b2,b3,b4,b5,b6,b7; int ZZ2;
OBJECT object3;
int c0,c1,c2,c3,c4,c5,c6,c7; int ZZ3;
int Runing=0,Score=0;
int X1=250,X2=300;int OK_X=960,OK_Y=20,sizeZ=40;
int J_x=430,J_y=245;
int m_a=435,m_b=95;
int Back;
CPoint pointo,poinfrom;
CPoint p1,pp;
CRect rect;
CRect desktopRect;
int Read=1;
int m_W,m_H;int LW,LH;
CPoint ooo;
CRect rect0;//桌面大小
CRect rectO;//窗口大小
CPoint rectp;//鼠标位置
CPoint recto;//窗口位置
CRect So,Si,Sj;
float R=0.15f;
int T=30,Set=0;
/////////////////////////////////////////////////////////////////////////////
// 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)
virtual void OnOK();
//}}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)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CXuNaElsFKDlg dialog
CXuNaElsFKDlg::CXuNaElsFKDlg(CWnd* pParent /*=NULL*/)
: CDialog(CXuNaElsFKDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CXuNaElsFKDlg)
m_fenshu = 0;
stopflag = false;
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CXuNaElsFKDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CXuNaElsFKDlg)
DDX_Text(pDX, IDC_EDIT1, m_fenshu);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CXuNaElsFKDlg, CDialog)
//{{AFX_MSG_MAP(CXuNaElsFKDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_COMMAND(IDM_DINANDU, OnDinandu)
ON_COMMAND(IDM_ZHONGNANDU, OnZhongnandu)
ON_COMMAND(IDM_GAONANDU, OnGaonandu)
ON_WM_CANCELMODE()
ON_WM_CHAR()
ON_WM_KEYDOWN()
ON_WM_TIMER()
ON_BN_CLICKED(IDC_START, OnStart)
ON_BN_CLICKED(IDC_STOP, OnStop)
ON_BN_CLICKED(IDD_CONTINUE, OnContinue)
ON_BN_CLICKED(IDC_EXIT, OnExit)
ON_COMMAND(IDM_YOUXIIMF, OnYouxiimf)
ON_COMMAND(IDM_ZUOZHEIMF, OnZuozheimf)
ON_COMMAND(IDM_START, OnStart)
ON_COMMAND(IDM_STOP, OnStop)
ON_COMMAND(IDM_CONTINUE, OnContinue)
ON_COMMAND(IDM_EXIT, OnExit)
ON_WM_ERASEBKGND()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CXuNaElsFKDlg message handlers
BOOL CXuNaElsFKDlg::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
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CXuNaElsFKDlg::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 CXuNaElsFKDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // 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 *pDC = GetDC();
CRect rect;
CBrush brush;
GetClientRect(&rect);
if (bitmap.GetSafeHandle() == NULL) {
bitmap.LoadBitmap(IDB_BITMAP1);
}
brush.CreatePatternBrush(&bitmap);
pDC->SelectObject(&brush);
pDC->Rectangle(&rect);
*/
Shape();
//ReleaseDC(pDC);
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CXuNaElsFKDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CXuNaElsFKDlg::OnDinandu()
{
// TODO: Add your command handler code here
Run_Time= 500;
}
void CXuNaElsFKDlg::OnZhongnandu()
{
// TODO: Add your command handler code here
Run_Time = 300;
}
void CXuNaElsFKDlg::OnGaonandu()
{
// TODO: Add your command handler code here
Run_Time = 200;
}
//DEL void CXuNaElsFKDlg::OnStop()
//DEL {
//DEL // TODO: Add your command handler code here
//DEL stopflag = true;
//DEL SetTimer(11,100000,NULL);
//DEL return;
//DEL }
//DEL void CXuNaElsFKDlg::OnContinue()
//DEL {
//DEL // TODO: Add your command handler code here
//DEL stopflag = false;
//DEL SetTimer(11,Run_Time,NULL);
//DEL }
//DEL void CXuNaElsFKDlg::OnExit()
//DEL {
//DEL // TODO: Add your command handler code here
//DEL CXuNaElsFKDlg::OnCancel();
//DEL }
void CXuNaElsFKDlg::ChangeShape(OBJECT object)
{
int z[4][2]={0},i,j,k;
if(Runing==0){OnDestroy();return;}//
do{
switch(object.group)
{
case 1: ZZ=0; z[1][0]=1;z[1][1]=0; z[2][0]=0;z[2][1]=1;z[3][0]=1;z[3][1]=1;break;
case 2: ZZ++; ZZ%=4;
switch(ZZ)
{ case 0: z[1][0]=-1;z[1][1]=0; z[2][0]=1;z[2][1]=0;z[3][0]=-1;z[3][1]=-1;break;
case 1: z[1][0]=0;z[1][1]=1; z[2][0]=0;z[2][1]=-1;z[3][0]=1;z[3][1]=-1;break;
case 2: z[1][0]=-1;z[1][1]=0; z[2][0]=1;z[2][1]=0;z[3][0]=1;z[3][1]=1;break;
case 3: z[1][0]=0;z[1][1]=-1; z[2][0]=0;z[2][1]=1;z[3][0]=-1;z[3][1]=1;break;
}
break;
case 3: ZZ++; ZZ%=4;
switch(ZZ)
{ case 0: z[1][0]=-1;z[1][1]=0; z[2][0]=1;z[2][1]=0;z[3][0]=1;z[3][1]=-1;break;
case 1: z[1][0]=0;z[1][1]=1; z[2][0]=0;z[2][1]=-1;z[3][0]=1;z[3][1]=1;break;
case 2: z[1][0]=-1;z[1][1]=0; z[2][0]=1;z[2][1]=0;z[3][0]=-1;z[3][1]=1;break;
case 3: z[1][0]=0;z[1][1]=-1; z[2][0]=0;z[2][1]=1;z[3][0]=-1;z[3][1]=-1;break;
}
break;
case 4: ZZ++; ZZ%=2;
switch(ZZ)
{ case 1:z[1][0]=0;z[1][1]=-1; z[2][0]=0;z[2][1]=2;z[3][0]=0;z[3][1]=1;break;
case 0:z[1][0]=1;z[1][1]=0; z[2][0]=2;z[2][1]=0;z[3][0]=-1;z[3][1]=0;break;
}
break;
case 5: ZZ++; ZZ%=2;
switch(ZZ)
{ case 1:z[1][0]=0;z[1][1]=-1; z[2][0]=1;z[2][1]=0;z[3][0]=1;z[3][1]=1;break;
case 0:z[1][0]=0;z[1][1]=1; z[2][0]=-1;z[2][1]=1;z[3][0]=1;z[3][1]=0;break;
}
break;
case 6: ZZ++; ZZ%=2;
switch(ZZ)
{ case 1:z[1][0]=0;z[1][1]=1; z[2][0]=1;z[2][1]=0;z[3][0]=1;z[3][1]=-1;break;
case 0:z[1][0]=-1;z[1][1]=0; z[2][0]=0;z[2][1]=1;z[3][0]=1;z[3][1]=1;break;
}
break;
case 7: ZZ++; ZZ%=4;
switch(ZZ)
{ case 0:z[1][0]=0;z[1][1]=-1; z[2][0]=1;z[2][1]=0;z[3][0]=-1;z[3][1]=0;break;
case 1:z[1][0]=0;z[1][1]=1; z[2][0]=0;z[2][1]=-1;z[3][0]=1;z[3][1]=0;break;
case 2:z[1][0]=0;z[1][1]=1; z[2][0]=-1;z[2][1]=0;z[3][0]=1;z[3][1]=0;break;
case 3:z[1][0]=-1;z[1][1]=0; z[2][0]=0;z[2][1]=1;z[3][0]=0;z[3][1]=-1;break;
}
break;
}
int t[8];for(i=0,k=0;i<4;i++)for(j=0;j<2;j++) {t[k]=z[i][j];k++;}
InPut(object,t);
}
while(check2()||check1());
}
int CXuNaElsFKDlg::Check(CPoint p, CRect rect)
{
if(p.x>=rect.left&&p.x<=rect.right&&p.y>=rect.top&&p.y<=rect.bottom) return 1;
else return 0;
}
int CXuNaElsFKDlg::check1()
{
if(object.x+a2>M-1||object.x+a4>M-1||object.x+a6>M-1
||object.x+a2<0||object.x+a4<0||object.x+a6<0)
return 1;
else if( G[object.x+a0][object.y+a1]||G[object.x+a2][object.y+a3]
||G[object.x+a4][object.y+a5]||G[object.x+a6][object.y+a7])
return 1;
else return 0;
}
int CXuNaElsFKDlg::check2()
{
if(object.y+a3>N-1||object.y+a5>N-1||object.y+a7>N-1
||object.y+a3<0||object.y+a5<0||object.y+a7<0)
return 1;
else if( G[object.x+a0][object.y+a1]||G[object.x+a2][object.y+a3]
||G[object.x+a4][object.y+a5]||G[object.x+a6][object.y+a7])
return 1;
else return 0;
}
int CXuNaElsFKDlg::check3()
{
if(object.y>N-1||object.y+a3>N-1||object.y+a5>N-1||object.y+a7>N-1)
return 1;
else if(G[object.x+a0][object.y+a1]||G[object.x+a2][object.y+a3]
||G[object.x+a4][object.y+a5]||G[object.x+a6][object.y+a7] )
return 1;
else return 0;
}
void CXuNaElsFKDlg::Clear(int a, int b)
{
one(0,object.x+a, object.y+b);
}
void CXuNaElsFKDlg::ClearUp()
{
CDC *pDC=GetDC(); ASSERT(pDC!=NULL);
COLORREF color=RGB(255,255,255);
CPen pen;
CBrush brush;
pen.CreatePen (PS_SOLID,1,color);
brush.CreateSolidBrush (color);
pDC->SelectObject (pen);
pDC->SelectObject (brush);
pDC->Rectangle(J_x,J_y,J_x+85,J_y+140);
DeleteObject(brush);DeleteObject(pen);
ReleaseDC(pDC);
}
void CXuNaElsFKDlg::cout(int a1, int x, int y)
{
char ch[10];
CDC *pDC=GetDC(); ASSERT(pDC!=NULL);
if(a1==-1) pDC->TextOut(x,y,"-1");
else if (a1==0) pDC->TextOut(x,y,"0");
else {gcvt(a1,10,ch);pDC->TextOut(x,y,ch);}
ReleaseDC(pDC);
}
void CXuNaElsFKDlg::DeleteGroup(OBJECT object)
{
if(Runing==0){OnDestroy();return;}
Clear(a0,a1);
Clear(a2,a3);
Clear(a4,a5);
Clear(a6,a7);
}
void CXuNaElsFKDlg::InPut(OBJECT object, int t[])
{
a0=t[0];a1=t[1];a2=t[2];a3=t[3];
a4=t[4];a5=t[5];a6=t[6];a7=t[7];
}
void CXuNaElsFKDlg::KeepData()
{
G[object.x+a0][object.y+a1]=object.Type;
G[object.x+a2][object.y+a3]=object.Type;
G[object.x+a4][object.y+a5]=object.Type;
G[object.x+a6][object.y+a7]=object.Type;
int i,j,k,p,q,o=0;
for(i=0;i<M;i++) if(G[i][1]>0||G[i][0]>0)
{Runing=0;AfxMessageBox("游戏结束!请重新开始。");return;}//
for(j=N-1;j>=0;j--)
{ for(i=0,k=0;i<M;i++) if(G[i][j]>0) k++;
if(k==M)
{ o++;
for(p=j;p>=1;p--)for(q=0;q<M;q++)
{G[q][p]=G[q][p-1];one(G[q][p],q,p);}
for(q=0;q<M;q++) {G[q][0]=0;one(G[q][p],q,p);}
j++;Score+=100*o;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -