📄 bbdlg.cpp
字号:
}
//擦除
int row=0;
BYTE CopyCount=0;
::PostMessage(game,WM_KEYDOWN,VK_SPACE,1);
::PostMessage(game,WM_KEYUP,VK_SPACE,1);
//::Sleep(30);
//TRACE("\n%d\n",count);
if(nClearNum>0)//有可消除行
{
m_uiTop-=nClearNum;
for(i=0;i<nClearNum;i++)
{
row=ClearLines[i]-CopyCount;
ASSERT(row>0);
::memcpy(Face[row],Face[row+1]
,(ROW_BLOCK_COUNT+2)*(COL_BLOCK_COUNT-row)*sizeof(BYTE));
++CopyCount;
}
//改变top数组
for(i=1;i<=ROW_BLOCK_COUNT;i++)
{
top[i]-=nClearNum;
while(Face[top[i]][i]<=0)
--top[i];
}//
nClearNum=0;
if(s_uEraseDelay>0)
::Sleep(s_uEraseDelay);
}
else
{
if(s_uFastDelay>0)
::Sleep(s_uFastDelay);
for(i=0;i<1;i++)
{
clr=::GetPixel(hfmdc,(prior.m_pos[i].col-1)*18+10
,352-(prior.m_pos[i].row-1)*18);
//clr=::GetPixel(hDC,(prior.m_pos[i].col-1)*18+200
// ,510-(prior.m_pos[i].row-1)*18);
if(clr!=color[prior.GetType()])
{
//::Sleep(10);
// ++error;
if(s_CurBlock.GetType()>-1)
Help(s_CurBlock.GetType(),s_CurBlock.GetStatus());
break;
}
}
}
}
::ReleaseDC(fhwnd,hfmdc);//::ReleaseDC(NULL,hDC);
::ReleaseDC(nhwnd,hsmdc);
::ReleaseDC(game,gdc);
if(!(ths->m_bpause))
ThreadFinish(ths);
return 0;
}
void CBBDlg::OnSave()
{
// TODO: Add your control notification handler code here
CString ifo,text;
char enter='\n';
CStdioFile file("\\vc\\Bb\\中游方块配置.ini",CFile::modeReadWrite);
file.Seek(18,CFile::begin);
//file.ReadString(text);
//int i=text.GetLength();
//file.Write(&enter,1);
text.Format("%d",s_uFastDelay);
ifo="DelayFastAfter="+text;
file.WriteString(ifo+"\n");
//file.Write(&enter,1);
text.Format("%d",s_uDownDelay);
ifo="DelayDownAfter="+text;
file.WriteString(ifo+"\n");
//file.Write(&enter,1);
text.Format("%d",s_uEraseDelay);
ifo="DelayEraseAfter="+text;
file.WriteString(ifo+"\n");
//file.Write(&enter,1);
text.Format("%d",s_uTurnDelay);
ifo="DelayTurnAfter="+text;
ifo=ifo+" ";//+"\n";
file.WriteString(ifo+"\n");
//file.Write(&enter,1);
file.Close();
}
void CBBDlg::OnDefault()
{
// TODO: Add your control notification handler code here
CString s;
s_uFastDelay=0;
s_uDownDelay=20;
s_uEraseDelay=200;
s_uTurnDelay=100;
s.Format("%d",s_uFastDelay);
m_fast_delay.SetWindowText(s);
m_setFast.SetPos(s_uFastDelay);
s.Format("%d",s_uDownDelay);
m_down_delay.SetWindowText(s);
m_setdown.SetPos(s_uDownDelay);
s.Format("%d",s_uEraseDelay);
m_erase_delay.SetWindowText(s);
m_setErase.SetPos(s_uEraseDelay);
s.Format("%d",s_uTurnDelay);
m_turn_delay.SetWindowText(s);
m_setturn.SetPos(s_uTurnDelay);
}
void CBBDlg::OnReleasedcaptureFastAfter(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
CString s;
s_uFastDelay=m_setFast.GetPos();
s.Format("%d",s_uFastDelay);
m_fast_delay.SetWindowText(s);
*pResult = 0;
}
void CBBDlg::OnReleasedcaptureDownAfter(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
CString s;
s_uDownDelay=m_setdown.GetPos();
s.Format("%d",s_uDownDelay);
m_down_delay.SetWindowText(s);
*pResult = 0;
}
void CBBDlg::OnReleasedcaptureTurnAfter(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
CString s;
s_uTurnDelay=m_setturn.GetPos();
s.Format("%d",s_uTurnDelay);
m_turn_delay.SetWindowText(s);
*pResult = 0;
}
void CBBDlg::OnReleasedcaptureEraseAfter(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
CString s;
s_uEraseDelay=m_setErase.GetPos();
s.Format("%d",s_uEraseDelay);
m_erase_delay.SetWindowText(s);
*pResult = 0;
}
void CBBDlg::Help(BOOL uitype,BOOL uistatus)
{
const int mask[7]={0,1,3,5,7,11,15};
const int height[19]={2,1,4,3,2,3,2,3,2,3,2,2,3,2,3,2,3,2,3};//各种方块的起始高度
const int right[19] ={10,12,9,10,11,10,11,10,11,10,11,11,10,11,10,11,10,11,10};
//各种方块的起始右端
const int nScdScan=8;//第二扫描行
int nInitHeight=height[mask[uitype]+uistatus];//"干扰方块"的起始高度
int nInitRight=right[mask[uitype]+uistatus];//"干扰方块"的起始右端
int nInitScan=COL_BLOCK_COUNT-nInitHeight-2;//起始扫描行,2是缓冲
int i,j;
COLORREF clr;
//::Sleep(10);
HDC hDC=::GetDC(fhwnd);//HDC hDC=::GetDC(NULL);
bool empty=true;
m_uiTop=0;
::memset(Face,0,(COL_BLOCK_COUNT+4)*(ROW_BLOCK_COUNT+2)*sizeof(BYTE));
::memset(top,0,(ROW_BLOCK_COUNT+2)*sizeof(int));
top[0]=top[ROW_BLOCK_COUNT+1]=COL_BLOCK_COUNT;
for(i=0;i<ROW_BLOCK_COUNT+2;i++)
Face[0][i]=1;
for(i=0;i<COL_BLOCK_COUNT+4;i++)
{
Face[i][0]=1;
Face[i][ROW_BLOCK_COUNT+1]=1;
}
for(j=1;j<=ROW_BLOCK_COUNT;j++)//起始扫描行
{
clr=::GetPixel(hDC,10+(j-1)*18,352-(nInitScan-1)*18);
//clr=::GetPixel(hDC,200+(j-1)*18,510-(nInitScan-1)*18);
if(clr==108799||clr==9649966||clr==16712451||clr==3911680
||clr==2621663||clr==15711039||clr==14358453)
{
Face[nInitScan][j]=1;
if(UINT(nInitScan)>top[j])
{
top[j]=nInitScan;
if(UINT(nInitScan)>m_uiTop)
m_uiTop=nInitScan;
}
empty=false;
}
}
if(!empty)//起始扫描行就已经非空
{
clr=::GetPixel(hDC,171,10);//clr=::GetPixel(hDC,362,168);
if(clr==108799)
{
gEnd.SetEvent();
//m_bpause=TRUE;
::ReleaseDC(NULL,hDC);
return;
}
for(i=COL_BLOCK_COUNT;i>nInitScan;--i)
{
for(j=1;j<=8 || (j>=nInitRight&&j<=ROW_BLOCK_COUNT);j++)
{
clr=::GetPixel(hDC,10+(j-1)*18,352-(i-1)*18);
//clr=::GetPixel(hDC,200+(j-1)*18,510-(i-1)*18);
if(clr==108799||clr==9649966||clr==16712451||clr==3911680
||clr==2621663||clr==15711039||clr==14358453)
{
Face[i][j]=1;
if(UINT(i)>top[j])
{
top[j]=i;
if(UINT(i)>m_uiTop)
m_uiTop=UINT(i);
}
}
}
}
}
empty=true;
for(j=1;j<=ROW_BLOCK_COUNT;j++)//第二扫描行
{
clr=::GetPixel(hDC,10+(j-1)*18,352-(nScdScan-1)*18);
//clr=::GetPixel(hDC,200+(j-1)*18,510-(nScdScan-1)*18);
if(clr==108799||clr==9649966||clr==16712451||clr==3911680
||clr==2621663||clr==15711039||clr==14358453)
{
Face[nScdScan][j]=1;
if(nScdScan>top[j])
{
top[j]=nScdScan;
if(nScdScan>m_uiTop)
m_uiTop=nScdScan;
}
empty=false;
}
}
i=empty?(nScdScan-1):(nInitScan-1);
for(;i>0;--i)
{
if(i!=nScdScan)
{
for(j=1;j<=ROW_BLOCK_COUNT;j++)
{
clr=::GetPixel(hDC,10+(j-1)*18,352-(i-1)*18);
//clr=::GetPixel(hDC,200+(j-1)*18,510-(i-1)*18);
if(clr==108799||clr==9649966||clr==16712451||clr==3911680
||clr==2621663||clr==15711039||clr==14358453)
{
Face[i][j]=1;
if(UINT(i)>top[j])
{
top[j]=i;
if(UINT(i)>m_uiTop)
m_uiTop=UINT(i);
}
}
}
}
}
::ReleaseDC(fhwnd,hDC);
}
void CBBDlg::OnWatch()
{
return;
}
void CBBDlg::OnCancel()
{
// TODO: Add extra cleanup here
gEnd.SetEvent();
m_bpause=TRUE;
::Sleep(300);
CDialog::OnCancel();
}
void CBBDlg::GetBlk(HDC& hdc)
{
//HDC hdc=::GetDC(NULL);
COLORREF col1,col2;
col1=::GetPixel(hdc,23,23);//col1=::GetPixel(hdc,23+389,23+531);
//TRACE1("\nFang:%d",col1);
if(col1==color[0])
{
s_CurBlock=CRussionBlock(0,0);
//::ReleaseDC(NULL,hdc);
return;
}
col1=::GetPixel(hdc,14,19);//col1=::GetPixel(hdc,14+389,19+531);
col2=::GetPixel(hdc,14,34);//col2=::GetPixel(hdc,14+389,34+531);
//TRACE1("\nHeng1:%d",col1);
//TRACE1("\nHeng2:%d",col2);
if(col1!=gray||col2!=gray)
{
if(col1!=gray)
{
if(col1==color[3])
s_CurBlock=CRussionBlock(3,1);
else if(col1==color[4])
s_CurBlock=CRussionBlock(4,1);
else if(col1==color[5])
{
if(col2!=gray)
s_CurBlock=CRussionBlock(5,0);
else
s_CurBlock=CRussionBlock(5,2);
}
else
//case color[6]:
s_CurBlock=CRussionBlock(6,0);
//::ReleaseDC(NULL,hdc);
return;
}
else
{
if(col2==color[2])
s_CurBlock=CRussionBlock(2,1);
else if(col2==color[4])
s_CurBlock=CRussionBlock(4,3);
else
s_CurBlock=CRussionBlock(6,2);
//::ReleaseDC(NULL,hdc);
return;
}
}
else//three lines
{
col1=::GetPixel(hdc,21,13);//col1=::GetPixel(hdc,21+389,13+531);
col2=::GetPixel(hdc,37,13);//col2=::GetPixel(hdc,37+389,13+531);
//TRACE1("\nshu1:%d",col1);
//TRACE1("\nshu2:%d",col2);
if(col1!=gray||col2!=gray)
{
if(col1!=gray)
{
if(col1==color[2])
s_CurBlock=CRussionBlock(2,0);
else if(col1==color[4])
s_CurBlock=CRussionBlock(4,0);
else if(col1==color[6])
{
if(col2!=gray)
s_CurBlock=CRussionBlock(6,1);
else
s_CurBlock=CRussionBlock(6,3);
}
else//case color[5]:
s_CurBlock=CRussionBlock(5,1);
//::ReleaseDC(NULL,hdc);
return;
}
else
{
if(col2==color[3])
s_CurBlock=CRussionBlock(3,0);
else if(col2==color[4])
s_CurBlock=CRussionBlock(4,2);
else
s_CurBlock=CRussionBlock(5,3);
//::ReleaseDC(NULL,hdc);
return;
}
}
}
col1=::GetPixel(hdc,10,28);//col1=::GetPixel(hdc,10+389,28+531);
//TRACE1("\nheng gun:%d",col1);
if(col1==color[1])
{
s_CurBlock=CRussionBlock(1,0);
//::ReleaseDC(NULL,hdc);
return;
}
col1=::GetPixel(hdc,30,9);//col1=::GetPixel(hdc,30+389,9+531);
//TRACE1("\nshu gun:%d",col1);
if(col1==color[1])
{
s_CurBlock=CRussionBlock(1,1);
//::ReleaseDC(NULL,hdc);
return;
}
s_CurBlock=CRussionBlock(-1,0);
//::ReleaseDC(NULL,hdc);
}
BOOL CALLBACK EnumChildProc(HWND hwndd, LPARAM lParam)
{
RECT rect;
CBBDlg* ths=(CBBDlg* )lParam;
::GetClientRect(hwndd,&rect);
int nWidth=rect.right-rect.left,nHeight=rect.bottom-rect.top;
if(nWidth==252 && nHeight==360)
{
ths->fhwnd=hwndd;
}
if(nWidth==55 && nHeight==59)
{
ths->nhwnd=hwndd;
}
return TRUE;
}
void CBBDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if(nIDEvent==1)
{
POINT pt1;
POINT pt2;
//pt1.x=155;pt1.y=225;
//pt2.x=254;pt2.y=448;
pt1.x=155;pt1.y=225;
pt2.x=254;pt2.y=448;
game=::FindWindow(NULL,"网际俄罗斯方块 Ver 0.4 -深圳网域-");
if(game==NULL)
game=::FindWindow(NULL,"俄罗斯方块单机版 <-> 疯狂练武 <-> 养兵杀敌 -深圳网域-");
if(game)
{
::EnumChildWindows(game,EnumChildProc,LPARAM(this));
if(nhwnd!=0 && fhwnd!=0)
{
KillTimer(1);
m_start.EnableWindow(TRUE);
}
//gwnd=new CWnd;
//gwnd->Attach(game);
//gwnd=CWnd::FromHandle(game);
//::ClientToScreen(game,&pt1);
//::ClientToScreen(game,&pt2);
//nhwnd=gwnd->ChildWindowFromPoint(pt2)->m_hWnd;
//fhwnd=gwnd->ChildWindowFromPoint(pt1)->m_hWnd;
//fhdc=::GetWindowDC(fhwnd);
//nhdc=::GetDC(game);
//nhdc=::GetDC(NULL);
//nhdc=::GetWindowDC(nhwnd);
}
CDialog::OnTimer(nIDEvent);
}
/*else if(nIDEvent==2)
{
CString str;
str.Format("%d",s_CurBlock.GetType());
m_Etype.SetWindowText(str);
str.Format("%d",s_CurBlock.GetStatus());
m_Estatus.SetWindowText(str);
str.Format("0x%x",nhwnd);
m_Ehandle.SetWindowText(str);
CDialog::OnTimer(nIDEvent);
}*/
}
void CBBDlg::ThreadFinish(CBBDlg* ths)
{
s_CurBlock=CRussionBlock(-1,0);
::memset(Face,0,(COL_BLOCK_COUNT+4)*(ROW_BLOCK_COUNT+2)*sizeof(BYTE));
::memset(top,0,(ROW_BLOCK_COUNT+2)*sizeof(int));
top[0]=top[ROW_BLOCK_COUNT+1]=COL_BLOCK_COUNT;
int i;
for(i=0;i<ROW_BLOCK_COUNT+2;i++)
Face[0][i]=1;
for(i=0;i<COL_BLOCK_COUNT+4;i++)
{
Face[i][0]=1;
Face[i][ROW_BLOCK_COUNT+1]=1;
}
m_uiTop=0;
//SetTimer(2,10,NULL);
//开始线程
gEnd.ResetEvent();
AfxBeginThread(Cal,(void* )ths);
// m_bpause=0;
}
void CBBDlg::GetBlk2(HDC &hdc)
{
//HDC hdc=::GetDC(NULL);
COLORREF col1,col2;
col1=::GetPixel(hdc,249,423);//col1=::GetPixel(hdc,23+389,23+531);
//TRACE1("\nFang:%d",col1);
if(col1==color[0])
{
s_CurBlock=CRussionBlock(0,0);
//::ReleaseDC(NULL,hdc);
return;
}
col1=::GetPixel(hdc,240,419);//col1=::GetPixel(hdc,14+389,19+531);
col2=::GetPixel(hdc,240,434);//col2=::GetPixel(hdc,14+389,34+531);
//TRACE1("\nHeng1:%d",col1);
//TRACE1("\nHeng2:%d",col2);
if(col1!=gray||col2!=gray)
{
if(col1!=gray)
{
if(col1==color[3])
s_CurBlock=CRussionBlock(3,1);
else if(col1==color[4])
s_CurBlock=CRussionBlock(4,1);
else if(col1==color[5])
{
if(col2!=gray)
s_CurBlock=CRussionBlock(5,0);
else
s_CurBlock=CRussionBlock(5,2);
}
else
//case color[6]:
s_CurBlock=CRussionBlock(6,0);
//::ReleaseDC(NULL,hdc);
return;
}
else
{
if(col2==color[2])
s_CurBlock=CRussionBlock(2,1);
else if(col2==color[4])
s_CurBlock=CRussionBlock(4,3);
else
s_CurBlock=CRussionBlock(6,2);
//::ReleaseDC(NULL,hdc);
return;
}
}
else//three lines
{
col1=::GetPixel(hdc,247,413);//col1=::GetPixel(hdc,21+389,13+531);
col2=::GetPixel(hdc,263,413);//col2=::GetPixel(hdc,37+389,13+531);
//TRACE1("\nshu1:%d",col1);
//TRACE1("\nshu2:%d",col2);
if(col1!=gray||col2!=gray)
{
if(col1!=gray)
{
if(col1==color[2])
s_CurBlock=CRussionBlock(2,0);
else if(col1==color[4])
s_CurBlock=CRussionBlock(4,0);
else if(col1==color[6])
{
if(col2!=gray)
s_CurBlock=CRussionBlock(6,1);
else
s_CurBlock=CRussionBlock(6,3);
}
else//case color[5]:
s_CurBlock=CRussionBlock(5,1);
//::ReleaseDC(NULL,hdc);
return;
}
else
{
if(col2==color[3])
s_CurBlock=CRussionBlock(3,0);
else if(col2==color[4])
s_CurBlock=CRussionBlock(4,2);
else
s_CurBlock=CRussionBlock(5,3);
//::ReleaseDC(NULL,hdc);
return;
}
}
}
col1=::GetPixel(hdc,236,428);//col1=::GetPixel(hdc,10+389,28+531);
//TRACE1("\nheng gun:%d",col1);
if(col1==color[1])
{
s_CurBlock=CRussionBlock(1,0);
//::ReleaseDC(NULL,hdc);
return;
}
col1=::GetPixel(hdc,256,409);//col1=::GetPixel(hdc,30+389,9+531);
//TRACE1("\nshu gun:%d",col1);
if(col1==color[1])
{
s_CurBlock=CRussionBlock(1,1);
//::ReleaseDC(NULL,hdc);
return;
}
s_CurBlock=CRussionBlock(-1,0);
//::ReleaseDC(NULL,hdc);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -