📄 box9dlg.cpp
字号:
// box9Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "box9.h"
#include "box9Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include "JiLuDlg.h"
/////////////////////////////////////////////////////////////////////////////
// CBox9Dlg dialog
CBox9Dlg::CBox9Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CBox9Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CBox9Dlg)
m_iSuccess = _T("0");
m_youSuc = _T("");
m_iStep = _T("-1");
timer = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CBox9Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBox9Dlg)
DDX_Control(pDX, IDC_REONE, m_bnBack);
DDX_Text(pDX, IDC_SUCESS, m_iSuccess);
DDX_Text(pDX, IDC_YOUSUC, m_youSuc);
DDX_Text(pDX, IDC_ISTEP, m_iStep);
DDX_Text(pDX, IDC_TIMER, timer);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CBox9Dlg, CDialog)
//{{AFX_MSG_MAP(CBox9Dlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_RE, OnRe)
ON_BN_CLICKED(IDC_REONE, OnReone)
ON_COMMAND(ID_MENUITEM32774, OnMenuitemExit)
ON_COMMAND(ID_MENUITEM32775, OnMenuitemJiLu)
ON_WM_TIMER()
ON_COMMAND(ID_MENUITEM32777, OnMenuitemBlind)
ON_BN_CLICKED(IDBLIND, OnBlind)
ON_COMMAND(ID_MENUITEM32776, OnMenuitemExit)
//}}AFX_MSG_MAP
ON_COMMAND_EX_RANGE(2000,2000+8, OnButton)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBox9Dlg message handlers
#include"Nameinputdlg.h"
BOOL CBox9Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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
//读取记录数据
m_jiLuDlg.datfilename="记录.dat";
blindDlg.datfilename="记录2.dat";
m_jiLuDlg.title="记录";
blindDlg.title="瞎子拼图记录";
curdlg=&m_jiLuDlg;
SetTimer(1,1000,NULL); timer="0"; //settimer
OnOK(); //进入就运行一次
return TRUE; // return TRUE unless you set the focus to a control
}
// 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 CBox9Dlg::OnPaint()
{
CDialog::OnPaint();
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CBox9Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
int Rand(int max)
{
static once=1;
if(once==1)
{
srand(time(NULL));
}
once=0;
int ret=rand()%(max+1);
return ret;
}
void CBox9Dlg::OnOK()
{
m_bnBack.EnableWindow(0);
for(int i=0;i<9;) // init num
{
m_list[i]=Rand(8);
for(int j=0;j<i;j++)
if( m_list[i]==m_list[j]) break;
if (j==i) i++;
}
for(int m=0;m<9;m++) //bac for replay
{
m_listold[m]=m_listrestart[m]=m_list[m];
}
char str[2];
int iStep=0;
m_iStep=itoa(iStep,str,10);
SetTimer(1,1000,NULL); timer="0"; //settimer
Show();
}
void CBox9Dlg::Show()
{
static char p[9][2]; //box caption
CRect rect;
GetDlgItem(IDC_BOX)->GetWindowRect(rect);
ScreenToClient(rect);
static showa=rect.left,showb=rect.top;
for( int i=0;i<9;i++)
{
itoa(m_list[i],p[i],10);
if (m_list[i]!=m_listold[i] && m_box[i].m_hWnd!=NULL
||m_list[i]==0)
m_box[i].DestroyWindow();
if(m_box[i].m_hWnd!=NULL) //set box caption when new game
{
if(curdlg==&m_jiLuDlg)
m_box[i].SetWindowText(p[i]);
//else if(curdlg==&blindDlg);
}
if(m_box[i].m_hWnd==NULL && m_list[i]!=0)
{
if(curdlg==&blindDlg)
p[i][0]='?';p[i][1]=0;
m_box[i].Create(p[i],WS_VISIBLE |WS_CHILD|BS_TEXT,
CRect(i%3*30+showa,i/3*30+showb,i%3*30+30+showa,i/3*30+30+showb),this,2000+i);
}
}
Success();
}
void CBox9Dlg::List(int i)
{
for(int m=0;m<9;m++)
m_listold[m]=m_list[m];
int ix=i%3, iy=i/3;
int equal0;
for(int t=0;t<9;t++)
if(m_list[t]==0)
equal0=t;
int equal0x=equal0%3, equal0y=equal0/3;
int iStep=atoi(m_iStep);iStep++;
char str[2];
if ( (ix==1 || equal0x==1) && (iy== equal0y)
||(iy==1 || equal0y==1) && (ix== equal0x) )
{
m_list[equal0]=m_list[i];
m_list[i]=0;
}
else if ( ((ix|equal0x)==2) && (iy== equal0y) )
{
int bbig=(ix>equal0x)?1:-1;
m_list[equal0]=m_list[equal0+bbig];
m_list[equal0+bbig]=m_list[i];
m_list[i]=0;
}
else if ( ((iy|equal0y)==2) && (ix== equal0x) )
{
int bbig=(iy>equal0y)?1:-1;
m_list[equal0]=m_list[equal0+bbig*3];
m_list[equal0+bbig*3]=m_list[i];
m_list[i]=0;
}
else {
iStep--;goto StayBnBack;
}
m_bnBack.EnableWindow(1);
StayBnBack:
m_iStep=itoa(iStep,str,10);
Show();
}
BOOL CBox9Dlg::OnButton(int id)
{
List(id-2000);
/*static int step,time;
step++;
curdlg->UpdateDat(step,time);
*/
return TRUE;
}
void CBox9Dlg::OnRe()
{
m_bnBack.EnableWindow(0);
for(int m=0;m<9;m++)
m_list[m]=m_listrestart[m];
char str[2];
int iStep=0;
m_iStep=itoa(iStep,str,10);
SetTimer(1,1000,NULL); timer="0"; //settimer
Show();
}
void CBox9Dlg::OnReone()
{
// TODO: Add your control notification handler code here
for(int m=0;m<9;m++)
m_list[m]=m_listold[m];
char str[2];
int iStep=atoi(m_iStep);iStep--;
m_iStep=itoa(iStep,str,10);
m_bnBack.EnableWindow(0);
Show();
}
BOOL CBox9Dlg::Success()
{
int successNum=0;
for(int m=0;m<8;m++)
if(m_list[m]==m+1)
successNum++;
static PSTR str=new char[2];
itoa(successNum,str,10);
//GetDlgItem(IDC_SUCESS)->SetWindowText(str);
m_iSuccess=str;
int i;
if (successNum==8)
{
m_youSuc="你赢了 ^-^";
for(i=0;i<8;i++)
if(m_box[i].m_hWnd!=NULL)
{
m_box[i].EnableWindow(0);
m_bnBack.EnableWindow(0);
}
UpdateData(FALSE);
KillTimer(1);
int step=atoi(m_iStep);
int time=atoi(this->timer);
curdlg->UpdateDat(step,time);
}
else
{
m_youSuc="";
for(i=0;i<8;i++)
if(m_box[i].m_hWnd!=NULL)
{ m_box[i].EnableWindow(1);}
}
UpdateData(FALSE);
if (successNum==8)
return TRUE;
return FALSE;
}
void CBox9Dlg::OnMenuitemExit()
{
PostQuitMessage(0);
}
void CBox9Dlg::OnMenuitemJiLu()
{
m_jiLuDlg.DoModal();
}
void CBox9Dlg::OnTimer(UINT nIDEvent)
{
if(GetActiveWindow()!=this) return;
int tmp=atoi(timer);
tmp++;
char c[5]="";
itoa(tmp,c,10);
timer=c;
UpdateData(false);
CDialog::OnTimer(nIDEvent);
CDialog::OnTimer(nIDEvent);
}
void CBox9Dlg::OnMenuitemBlind()
{
blindDlg.DoModal();
}
void CBox9Dlg::OnBlind()
{
CString str;
GetDlgItemText(IDBLIND,str);
if(str=="瞎子拼图")
{
str="普通拼图";
curdlg=&blindDlg;
for( int i=0;i<9;i++)
{
if(m_box[i].m_hWnd!=NULL)
m_box[i].SetWindowText("?");
}
}
else
{
str="瞎子拼图";
curdlg=&m_jiLuDlg;
}
OnOK();
SetDlgItemText(IDBLIND,str);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -