📄 gamedlg.cpp
字号:
// gameDlg.cpp : implementation file
//
#include "stdafx.h"
#include "game.h"
#include "gameDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include "Gameover.h"
#define M 13 //水平格数
#define N 22 //垂直格数
#define V 34 //
int G[M][N];
int Run_Time = 500;
////////////////////////////
////////////////////////////
int movie=1;
////////////////////////////
#define Clear_away one(0, object.x, object.y)
int X=47, Y=-5,Z=40, r=25;//x,y为游戏矩形(非边框)左顶点的坐标,r为每个单元格的大小
COLORREF BackColor = RGB(200,230,214);//RGB(170,185,226); //RGB(118,4,118); //背景色,游戏开始时的默认值。
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 Running=0;
int HScore, Score=0;
int level=1,llevel=1;
int X1=250, X2=300;
int OK_X=960, OK_Y=20, sizeZ=40;
int J_x= 425, J_y = 265;
int m_a = 435, m_b = 95;
int Back;
//////////////
int start=0;
//int go=1;
//int repair=2;
int repaircount=0;//需要补框的次数,并不是每次都需要补框
//////////////
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.15;
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)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CGameDlg dialog
CGameDlg::CGameDlg(CWnd* pParent /*=NULL*/)
: CDialog(CGameDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CGameDlg)
// 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 CGameDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CGameDlg)
DDX_Control(pDX, IDC_PAUSE, m_Pause);
DDX_Control(pDX, IDC_COMBO1, m_str);
DDX_Control(pDX, IDC_OUT, m_Out);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CGameDlg, CDialog)
//{{AFX_MSG_MAP(CGameDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BACKCOLOR, OnBackcolor)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_DOWN, OnDown)
ON_BN_CLICKED(IDC_LEFT, OnLeft)
ON_BN_CLICKED(IDC_RIGHT, OnRight)
ON_BN_CLICKED(IDC_UP, OnUp)
ON_WM_TIMER()
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
ON_BN_CLICKED(IDC_MYSELF, OnMyself)
ON_BN_CLICKED(IDC_PAUSE, OnPause)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGameDlg message handlers
BOOL CGameDlg::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
// m_str.AddString("1 低级"); //添加选项,也可在下拉列表框的数据选项下之接添加,
// m_str.AddString("2 中级"); //添加数字,会避免他自动排序而打乱原来顺序
// m_str.AddString("3 高级");
m_str.SetCurSel(0);
ooo.x = ooo.y = 0;
recto = rectp = ooo;//桌面大小
ClientToScreen(&recto);
GetCursorPos(&rectp);
GetClientRect(&rect);
m_W = rect.Width();
m_H = rect.Height()+30;
GetDesktopWindow()->GetWindowRect(desktopRect);
LW = desktopRect.Width();
LH = desktopRect.Height();
So.bottom = int(LH-R*LH);
So.top = int(R*LH);
So.right = int(LW-R*LW);
So.left = int(R*LW);
SetTimer(10,1,NULL);
SetTimer(9,1,NULL);
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CGameDlg::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 CGameDlg::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
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CGameDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
//=========================================================================================
//=======================================================================================
void CGameDlg::one(OBJECT object) //以组形式画出 //暂没找到哪调用过他
{
Clear_away;
one(object.Type, object.x, object.y+1); //调用one(int Type,int i,int j) 画单元格
}
void CGameDlg::one(OBJECT object,int a,int b)
{
one(object.Type, object.x+b, object.y+a); //调用one(int Type,int i,int j) //下落的位置;
}
void CGameDlg::Clear(int a,int b)
{
one(0,object.x+a, object.y+b); //调用one(int Type,int i,int j) ,画单元格,Type为0,故为背景;
}
int CGameDlg::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 CGameDlg::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 CGameDlg::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 CGameDlg::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);
}
/////////////////////////////////////////////////////////////////////////////
// CMyView message handlers
void CGameDlg::OnDraw(CDC* pDC) //开始进入
{
// TODO: add draw code for native data here
Shape();
int i,j;
for(i=0;i<M;i++) //初始化全 为0
for(j=0;j<N;j++)
G[i][j]=0;
Running=1;
Score=0;
object.Type=3; //起始设定第一块方块的颜色类型为type3
object.x=M/2;
object.y=0;
object.group=3;
ZZ=1;
PreView();
Show(object);
ChangeShape(object);
ObjectGroup(object);
switch(m_str.GetCurSel())
{
case 0: Run_Time=700;break;
case 1: Run_Time=400;break;
case 2: Run_Time=100;break;
}
SetTimer(11, Run_Time, NULL);
pointo.x = pointo.y = 0;
ClientToScreen(&pointo);
poinfrom = pointo;
}
void CGameDlg::Shape() //外部框架
{
int line=18; //外边框距游戏边框的距离
int rr=7; //实现边框中线宽度(向里扩展)
CDC *pDC=GetDC();//获取一个客户区的设备描述表
ASSERT(pDC!=NULL);
CPen pen;
pen.CreatePen (PS_SOLID,1,RGB(43,45,57));//创建画笔,设定边框的边线 线形(SOLID实线 DASH虚线 DOT点线 DASHDOT虚点线 DASHDOTDOI双点虚线(除了SOLID,其余线宽必须为1)) 宽度1 颜色 可省略,默认颜色RGB(0,0,0)
CBrush brush1,brush2;
CBrush brush3_up,brush3_left,brush3_right,brush3_down;
brush1.CreateSolidBrush(RGB(53,73,162));//边框颜色
//////////////////////////////
brush3_down.CreateSolidBrush(RGB(200,190,200));//边框中线颜色
brush3_up.CreateSolidBrush(RGB(20,20,20));
brush3_left.CreateSolidBrush(RGB(100,100,100));
brush3_right.CreateSolidBrush(RGB(150,170,220));
///////////////////////////////////////
brush2.CreateSolidBrush(BackColor); //背景色
/////连画三个矩形,大小依次减小,形成边框///////////////////////////////////////
pDC->SelectObject (pen); //话边线
pDC->SelectObject (brush1);
pDC->Rectangle(X-line,Z-line,X+M*r+line,Y+N*r+line);//矩形的左顶点坐标,和右底点坐标
int b=line*2/3,c=b-rr;
/////////////////////////////////////////// 中框
// pDC->SelectObject (brush3);
// pDC->Rectangle(X-b,Y-b,X+M*r+b,Y+N*r+b);
pDC->SelectObject (brush3_up);
POINT pt_up[4]={{X-b,Z-b},{X-b+10,Z-b+10},{X+M*r+b-10,Z-b+10},{X+M*r+b,Z-b}};
pDC->Polygon(pt_up,4);
pDC->SelectObject (brush3_left);
POINT pt_left[4]={{X-b,Z-b},{X-b+10,Z-b+10},{X-b+10,Y+N*r+b-10},{X-b,Y+N*r+b}};
pDC->Polygon(pt_left,4);
pDC->SelectObject (brush3_right);
POINT pt_right[4]={{X+M*r+b-10,Z-b+10},{X+M*r+b,Z-b},{X+M*r+b,Y+N*r+b},{X+M*r+b-10,Y+N*r+b-10}};
pDC->Polygon(pt_right,4);
pDC->SelectObject (brush3_down);
POINT pt_down[4]={{X-b+10,Y+N*r+b-10},{X-b,Y+N*r+b},{X+M*r+b,Y+N*r+b},{X+M*r+b-10,Y+N*r+b-10}};
pDC->Polygon(pt_down,4);
///////////////////////////////////////////
pDC->SelectObject (brush1);
pDC->Rectangle(X-c,Z-c,X+M*r+c,Y+N*r+c);
pDC->SelectObject (brush2);
pDC->Rectangle(X-2,Z-2,X+M*r+2,Y+N*r+2);
/////画完后的处理语句///////////////////////////////////////////////////////////
DeleteObject(pen);
DeleteObject(brush1);
DeleteObject(brush2);
DeleteObject(brush3_right);
DeleteObject(brush3_left);
DeleteObject(brush3_up);
DeleteObject(brush3_down);
ReleaseDC(pDC);
}
void CGameDlg::one(int Type, int i, int j) //某元格颜色 位置
{
if(Running==0)
{
OnDestroy();
return;
}
CDC *pDC=GetDC();
ASSERT(pDC!=NULL);
COLORREF color,L_color=RGB(0,0,0);
COLORREF color2=RGB(90,90,90),color3=RGB(40,40,40),color4=RGB(230,230,230); //color2=RGB(131,129,222)
switch(Type)
{
case 0: color=L_color=color2=color3=color4=BackColor;break; // 如果是0,既不是下落的方块,就是背景色,
case 1: color=RGB(131,129,222); break;
case 2: color=RGB(250,90,130); break;
case 3: color=RGB(50,100,220); break;
case 4: color=RGB(40,120,50); break;
case 5: color=RGB(0,250,0); break;
case 6: color=RGB(131,19,222); break;
case 7: color=RGB(120,190,30); break;
case 8: color=RGB(140,20,150); break;
case 9: color=RGB(40,120,150); break;
case 10: color=RGB(23,62,180); break;
case 11: color=RGB(131,129,22); break;
case 12: color=RGB(20,190,130); break;
case 13: color=RGB(40,234,220); break;
case 14: color=RGB(140,70,150); break;
case 15: color=RGB(30,150,40); break;
case 16: color=RGB(78,203,30); break;
case 17: color=RGB(120,100,30); break;
case 18: color=RGB(240,70,20); break;
case 19: color=RGB(40,180,90); break;
case 20: color=RGB(123,62,180); break;
case 21: color=RGB(120,0,20); break;
case 22: color=RGB(0,0,250); break;
case 23: color=RGB(0,250,0); break;
case 24: color=RGB(0,250,250); break;
case 25: color=RGB(250,0,0); break;
case 26: color=RGB(250,0,250); break;
case 27: color=RGB(250,250,0); break;
case 28: color=RGB(250,250,250);break;
//////////////以下会产生一个组多种颜色的下落形状,由于个人爱好,屏蔽;
// case 29: color=RGB(rand()%255,rand()%255,rand()%255); break;
// case 30: color=RGB(rand()%255,rand()%255,rand()%255); break;
// case 31: color=RGB(rand()%255,rand()%255,rand()%255); break;
// case 32: color=RGB(rand()%255,rand()%255,rand()%255); break;
// case 33: color=RGB(rand()%255,rand()%255,rand()%255); break;
// case 34: color=RGB(rand()%255,rand()%255,rand()%255); break;
}
CPen pen;
CBrush brush,brush2,brush3,brush4;
pen.CreatePen(PS_SOLID,1,L_color);
brush.CreateSolidBrush (color);
brush2.CreateSolidBrush (color2);
brush3.CreateSolidBrush (color3);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -