📄 linecolorview.cpp
字号:
m_virDCTop.MoveTo(m_rectHigher.left-2, m_rectHigher.bottom+1);
m_virDCTop.LineTo(m_rectHigher.right, m_rectHigher.bottom+1);
m_virDCTop.MoveTo(m_rectHigher.left-2, m_rectHigher.top-2);
m_virDCTop.LineTo(m_rectHigher.left-2, m_rectHigher.bottom+1);
m_virDCTop.MoveTo(m_rectHigher.right, m_rectHigher.top-2);
m_virDCTop.LineTo(m_rectHigher.right, m_rectHigher.bottom+2);
m_virDCTop.FillRect(&m_rectPlayer, m_gdi.GetBrush(BLACK));
m_virDCTop.SelectObject(m_gdi.GetPen(WHITE));
m_virDCTop.MoveTo(m_rectPlayer.left-2, m_rectPlayer.top-2);
m_virDCTop.LineTo(m_rectPlayer.right+1, m_rectPlayer.top-2);
m_virDCTop.MoveTo(m_rectPlayer.left-2, m_rectPlayer.bottom+1);
m_virDCTop.LineTo(m_rectPlayer.right+1, m_rectPlayer.bottom+1);
m_virDCTop.MoveTo(m_rectPlayer.left-2, m_rectPlayer.top-2);
m_virDCTop.LineTo(m_rectPlayer.left-2, m_rectPlayer.bottom+1);
m_virDCTop.MoveTo(m_rectPlayer.right+1, m_rectPlayer.top-2);
m_virDCTop.LineTo(m_rectPlayer.right+1, m_rectPlayer.bottom+2);
int nLeft = (m_rectWindow.Width()-TOPGRIDWIDTH*3)/2;
m_virDCTop.SelectObject(m_gdi.GetPen(BLACK));
m_virDCTop.MoveTo(nLeft, 5);
m_virDCTop.LineTo(nLeft+90, 5);
m_virDCTop.MoveTo(nLeft, 35);
m_virDCTop.LineTo(nLeft+90, 35);
m_virDCTop.MoveTo(nLeft, 5);
m_virDCTop.LineTo(nLeft, 35);
m_virDCTop.MoveTo(nLeft+30, 5);
m_virDCTop.LineTo(nLeft+30, 35);
m_virDCTop.MoveTo(nLeft+60, 5);
m_virDCTop.LineTo(nLeft+60, 35);
m_virDCTop.MoveTo(nLeft+90, 5);
m_virDCTop.LineTo(nLeft+90, 36);
m_virDCTop.SelectObject(m_gdi.GetPen(WHITE));
m_virDCTop.MoveTo(nLeft+2, 6);
m_virDCTop.LineTo(nLeft+90, 6);
m_virDCTop.MoveTo(nLeft+2, 36);
m_virDCTop.LineTo(nLeft+92, 36);
m_virDCTop.MoveTo(nLeft+2, 6);
m_virDCTop.LineTo(nLeft+2, 35);
m_virDCTop.MoveTo(nLeft+30+2, 6);
m_virDCTop.LineTo(nLeft+30+2, 35);
m_virDCTop.MoveTo(nLeft+60+2, 6);
m_virDCTop.LineTo(nLeft+60+2, 35);
m_virDCTop.MoveTo(nLeft+90+2, 6);
m_virDCTop.LineTo(nLeft+90+2, 37);
UpdateSorce();
}
int CLineColorView::GetGridPos(int nX, int nY)
{
int nBaseLeft = (m_rectWindow.right-MAX_GRIDX*GRIDWIDTH)/2;
int nBaseTop = (m_rectWindow.bottom-MAX_GRIDY*GRIDWIDTH)/2;;
for (int y=1; y<=MAX_GRIDY; y++)
{
for (int x=1; x<=MAX_GRIDX; x++)
{
if (nX > nBaseLeft + (x-1)*GRIDWIDTH+1 &&
nX < nBaseLeft + x*GRIDWIDTH-1 &&
nY > nBaseTop + (y-1)*GRIDWIDTH+1 &&
nY < nBaseTop + y*GRIDWIDTH-1)
{
return 10*y+x;
}
}
}
return 0;
}
void CLineColorView::SetActiveBall(int x, int y)
{
g_pThread->ResumeThread();
}
void CLineColorView::SwapActiveBall(int x, int y, int old_x, int old_y)
{
CRect rect;
rect.left = m_rectGrid.left + old_x*GRIDWIDTH + 3;
rect.right = m_rectGrid.left + old_x*GRIDWIDTH + 20;
rect.top = m_rectGrid.top + old_y*GRIDWIDTH + 3;
rect.bottom = m_rectGrid.top + old_y*GRIDWIDTH + 20;
HICON hIcon = this->GetIcon(m_ball.GetBallColor(old_x, old_y));
m_virDCGrid.DrawIcon(rect.left, rect.top, hIcon);
SetActiveBall(x, y);
this->UpdatePage();
}
void CLineColorView::ClearBall(int nX, int nY)
{
CRect rect;
rect.left = m_rectGrid.left + nX*GRIDWIDTH + 3;
rect.right = m_rectGrid.left + nX*GRIDWIDTH + 33;
rect.top = m_rectGrid.top + nY*GRIDWIDTH + 2;
rect.bottom = m_rectGrid.top + nY*GRIDWIDTH + 33;
m_virDCGrid.FillRect(&rect, m_gdi.GetBrush(DARK_GRAY));
}
void CLineColorView::MoveBall(int x, int y, int old_x, int old_y)
{
ClearBall(old_x, old_y);
DrawOneBall(x, y, m_ball.GetBallColor(x, y));
}
void CLineColorView::UpdateSorce()
{
int nCount = 0;
for (int x=0; x<9; x++)
{
for (int y=0; y<9; y++)
{
if (m_ball.m_nClearX[y][x] != 0)
{
nCount++;
ClearBall(x, y);
}
}
}
m_nSorce += nCount * 2;
int offset = 0;
if (m_nSorce >= 0 && m_nSorce <= 9)
{
offset = -8;
}
else
if (m_nSorce >= 10 && m_nSorce <= 99)
{
offset = -16;
}
else
if (m_nSorce >= 100 && m_nSorce <= 999)
{
offset = -24;
}
else
{
offset = -32;
}
m_strPlayer.Format("%d", m_nSorce);
m_strHigher.Format("%d", m_Recorder[0].nScore);
m_virDCTop.SetBkColor(RGB_BLACK);
m_virDCTop.SetTextColor(RGB_WHITE);
m_virDCTop.TextOut(m_rectPlayer.right+offset, m_rectPlayer.top, m_strPlayer);
m_virDCTop.TextOut(m_rectHigher.left, m_rectHigher.top, m_strHigher);
this->DrawRightInfo();
}
void CLineColorView::OnMessageJumpBall(WPARAM wparam, LPARAM lparam)
{
int i = (int)wparam;
CClientDC dc(this);
int ret = -11;
while (ret == -11)
{
ret = m_ball.GetActiveBall();
Sleep(1);
}
int y = ret / 10;
int x = ret % 10;
int color = m_ball.GetBallColor(x, y);
CRect rect = GetCellRect(x, y);
HICON hIcon = this->GetIcon(color);
m_virDCGrid.FillRect(&rect, m_gdi.GetBrush(DARK_GRAY));
::DrawIconEx(m_virDCGrid.m_hDC, rect.left, rect.top+8-2*i,
hIcon, 32, 24+i*2, NULL, NULL, DI_NORMAL);
m_virDCSrc.BitBlt(0, 0, m_rectWindow.Width(),
m_rectWindow.Height(), &m_virDCGrid, 0, 0, SRCCOPY);
this->UpdatePage();
}
CRect CLineColorView::GetCellRect(int x, int y)
{
CRect rect;
rect.left = m_rectGrid.left + x*GRIDWIDTH + 3;
rect.right = m_rectGrid.left + x*GRIDWIDTH + 33;
rect.top = m_rectGrid.top + y*GRIDWIDTH + 2;
rect.bottom = m_rectGrid.top + y*GRIDWIDTH + 33;
return rect;
}
void CLineColorView::OnFileHistroy()
{
m_dlgRecorder.MoveParm(m_Recorder);
m_dlgRecorder.DoModal();
}
void CLineColorView::WriteFile()
{
FILE *fp = fopen("recorder.dat", "wb");
if (fp == NULL)
{
return;
}
fwrite(&m_Recorder, 1, sizeof(RECORDER_INFO)*10, fp);
fclose(fp);
}
void CLineColorView::GameOver()
{
MessageBox("Game Over!");
for (int i=0; i<10; i++)
{
if (m_Recorder[i].nScore < m_nSorce)
{
for (int j=8; j>=i; j--)
{
memcpy(
&m_Recorder[j+1],
&m_Recorder[j],
sizeof(RECORDER_INFO));
}
m_dlgInput.DoModal();
sprintf(m_Recorder[i].szUserName,
"%s", m_dlgInput.GetPlayName());
m_Recorder[i].nScore = m_nSorce;
break;
}
}
}
void CLineColorView::ReadFile()
{
FILE *fp = fopen("recorder.dat", "r+b");
if (fp == NULL)
{
return;
}
fread(&m_Recorder, 1, sizeof(RECORDER_INFO)*10, fp);
fclose(fp);
}
void CLineColorView::DrawLeftInfo()
{
m_virDCLeft.FillRect(&m_rectLeft, m_gdi.GetBrush(BLACK));
m_virDCLeft.SelectObject(m_gdi.GetPen(GRAY));
int nHeight = m_rectLeft.Height() / 3;
m_virDCLeft.MoveTo(0, nHeight);
m_virDCLeft.LineTo(m_rectLeft.right, nHeight);
m_virDCLeft.MoveTo(0, 2*nHeight);
m_virDCLeft.LineTo(m_rectLeft.right, 2*nHeight);
HICON hicon1 = this->GetIcon(0x10);
HICON hicon2 = this->GetIcon(0x20);
HICON hicon3 = this->GetIcon(0x30);
int flag1 = m_Recorder[0].nScore / 360;
int flag2 = (m_Recorder[0].nScore - flag1*360) / 60;
int flag3 = (m_Recorder[0].nScore % 60) / 10;
int i = 0;
int x = 0;
int y = 0;
for (i=0; i<flag1; i++)
{
if (i >= 3)
{
x = m_rectLeft.left+(3+32)*(i-3);
y = m_rectLeft.top + 12 + 32;
}
else
{
x = m_rectLeft.left+(3+32)*i;
y = m_rectLeft.top + 6;
}
::DrawIconEx(
m_virDCLeft.m_hDC, x, y, hicon3, 32, 32, NULL, NULL, DI_NORMAL);
}
for (i=0; i<flag2; i++)
{
if (i >= 3)
{
x = m_rectLeft.left+(3+32)*(i-3);
y = nHeight + 12 + 32;
}
else
{
x = m_rectLeft.left+(3+32)*i;
y = nHeight + 6;
}
::DrawIconEx(
m_virDCLeft.m_hDC, x, y,
hicon2, 32, 32, NULL, NULL, DI_NORMAL);
}
for (i=0; i<flag3; i++)
{
if (i >= 3)
{
x = m_rectLeft.left+(3+32)*(i-3);
y = nHeight*2 + 12 + 32;
}
else
{
x = m_rectLeft.left+(3+32)*i;
y = nHeight*2 + 6;
}
::DrawIconEx(
m_virDCLeft.m_hDC, x, y, hicon1, 32, 32, NULL, NULL, DI_NORMAL);
}
}
void CLineColorView::DrawRightInfo()
{
m_virDCRight.FillRect(&m_rectRight, m_gdi.GetBrush(BLACK));
m_virDCRight.SelectObject(m_gdi.GetPen(GRAY));
int nHeight = m_rectRight.Height() / 3;
m_virDCRight.MoveTo(0, nHeight);
m_virDCRight.LineTo(m_rectRight.right, nHeight);
m_virDCRight.MoveTo(0, 2*nHeight);
m_virDCRight.LineTo(m_rectRight.right, 2*nHeight);
HICON hicon1 = ::LoadIcon(
AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDI_FLAG1));
HICON hicon2 = ::LoadIcon(
AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDI_FLAG2));
HICON hicon3 = ::LoadIcon(
AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDI_FLAG3));
int flag1 = m_nSorce / 360;
int flag2 = (m_nSorce - flag1*360) / 60;
int flag3 = (m_nSorce % 60) / 10;
int i = 0;
int x = 0;
int y = 0;
for (i=0; i<flag1; i++)
{
if (i >= 3)
{
x = m_rectRight.left+(3+32)*(i-3);
y = m_rectRight.top + 12 + 32;
}
else
{
x = m_rectRight.left+(3+32)*i;
y = m_rectRight.top + 6;
}
::DrawIconEx(
m_virDCRight.m_hDC, x, y, hicon3, 32, 32, NULL, NULL, DI_NORMAL);
}
for (i=0; i<flag2; i++)
{
if (i >= 3)
{
x = m_rectRight.left+(3+32)*(i-3);
y = nHeight + 12 + 32;
}
else
{
x = m_rectRight.left+(3+32)*i;
y = nHeight + 6;
}
::DrawIconEx(
m_virDCRight.m_hDC, x, y,
hicon2, 32, 32, NULL, NULL, DI_NORMAL);
}
for (i=0; i<flag3; i++)
{
if (i >= 3)
{
x = m_rectRight.left+(3+32)*(i-3);
y = nHeight*2 + 12 + 32;
}
else
{
x = m_rectRight.left+(3+32)*i;
y = nHeight*2 + 6;
}
::DrawIconEx(
m_virDCRight.m_hDC, x, y, hicon1, 32, 32, NULL, NULL, DI_NORMAL);
}
}
void CLineColorView::UpdatePage()
{
m_virDCSrc.BitBlt(
0, 0, m_rectTop.Width(), m_rectTop.Height(),
&m_virDCTop, 0, 0, SRCCOPY);
m_virDCSrc.BitBlt(
0, m_rectTop.Height(), m_rectLeft.Width(), m_rectLeft.Height(),
&m_virDCLeft, 0, 0, SRCCOPY);
m_virDCSrc.BitBlt(
m_rectLeft.Width(), m_rectTop.Height(), m_rectGrid.Width(), m_rectGrid.Height(),
&m_virDCGrid, 0, 0, SRCCOPY);
m_virDCSrc.BitBlt(
m_rectGrid.Width()+m_rectLeft.Width(), m_rectTop.Height(), m_rectRight.Width(), m_rectRight.Height(),
&m_virDCRight, 0, 0, SRCCOPY);
CClientDC dc(this);
dc.BitBlt(
0, 0, m_rectWindow.Width(), m_rectWindow.Height(),
&m_virDCSrc, 0, 0, SRCCOPY);
}
void CLineColorView::InitPage()
{
m_virDCSrc.FillRect(&m_rectWindow, m_gdi.GetBrush(BLACK));
DrawTopInfo();
DrawGrid();
this->DrawLeftInfo();
this->DrawRightInfo();
DrawFirst();
UpdatePage();
}
BOOL CLineColorView::OnEraseBkgnd(CDC* pDC)
{
//return true;
return CView::OnEraseBkgnd(pDC);
}
void CLineColorView::InitIcon()
{
m_iconLevel1 = AfxGetApp()->LoadIcon(IDI_FLAG1);
m_iconLevel2 = AfxGetApp()->LoadIcon(IDI_FLAG2);
m_iconLevel3 = AfxGetApp()->LoadIcon(IDI_FLAG3);
m_iconRed = AfxGetApp()->LoadIcon(IDI_RED);
m_iconGreen = AfxGetApp()->LoadIcon(IDI_GREEN);
m_iconDarkBlue = AfxGetApp()->LoadIcon(IDI_NAVYBLUE);
m_iconBrown = AfxGetApp()->LoadIcon(IDI_WHITE);
m_iconBrightBlue = AfxGetApp()->LoadIcon(IDI_TINTBLUE);
m_iconPink = AfxGetApp()->LoadIcon(IDI_PINK);
m_iconYellow = AfxGetApp()->LoadIcon(IDI_YELLOW);
}
HICON CLineColorView::GetIcon(int nType)
{
switch (nType)
{
case 0x01:
return m_iconRed;
break;
case 0x02:
return m_iconGreen;
break;
case 0x03:
return m_iconDarkBlue;
break;
case 0x04:
return m_iconBrown;
break;
case 0x05:
return m_iconBrightBlue;
break;
case 0x06:
return m_iconPink;
break;
case 0x07:
return m_iconYellow;
break;
case 0x10:
return m_iconLevel1;
break;
case 0x20:
return m_iconLevel2;
break;
case 0x30:
return m_iconLevel3;
break;
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -