📄 list.cpp
字号:
// List.cpp: implementation of the CList class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Brick.h"
#include "List.h"
//////////////////////////////////////////////////////////////////////
extern HBITMAP hBmp1,hBmp2,hBmp3,hBmp4,hBmp5,hBmp6,hBmp7,hBmp8,hBmp9,
hBmp10,hBmp11,hBmp12,hBmp13,hBmp14,hBmp15;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CList::CList()
{
m_pHead = new CBrick;
m_pTail = m_pHead;
m_nLength = 0;
::SetRect(&m_nextRect, 10, 400, 210, 408);
}
CList::~CList()
{
while(m_pHead)
{
m_pTail = m_pHead->m_pNext;
delete m_pHead;
m_pHead = m_pTail;
}
}
void CList::AddBrick(CBrick* temp)
{
CBrick* pNode = new CBrick;
pNode->m_Rect = m_nextRect;
pNode->m_hBmp = temp->m_hBmp;//只用一个数据
::SetRect(&m_nextRect, m_nextRect.left, m_nextRect.top-20,
m_nextRect.right, m_nextRect.bottom-20);//从下到上建立
if(m_pHead == m_pTail)
{
m_pHead->m_pNext = pNode;
m_pTail = pNode;
}
else
{
m_pTail->m_pNext = pNode;
m_pTail = pNode;
}
m_nLength++;
}//AddBrick
void CList::OnDraw(HWND hWnd)
{
CBrick* pNode = m_pHead->m_pNext;
while(pNode)
{
pNode->OnDrawBrick(hWnd);
pNode = pNode->m_pNext;
}
}//CList OnDraw
void CList::DelBrick()
{
CBrick* pNode = m_pHead;
if(!pNode->m_pNext)
return;
while(pNode->m_pNext != m_pTail)
pNode = pNode->m_pNext;
pNode->m_pNext = NULL;
delete m_pTail;
m_pTail = pNode;
::SetRect(&m_nextRect, m_nextRect.left, m_nextRect.top+20,
m_nextRect.right, m_nextRect.bottom+20);//从上到下
m_nLength--;
}//DelBrick
void CList::SetNextRect(int x, int y, int xw, int yh)
{
::SetRect(&m_nextRect, x, y, xw, yh);
}
void CList::CreateTower()
{
int i = 0;
HBITMAP hBmp[15] =
{
hBmp15, hBmp14, hBmp13, hBmp12, hBmp11, hBmp10, hBmp9, hBmp8,
hBmp7, hBmp6 ,hBmp5 ,hBmp4 ,hBmp3 ,hBmp2 ,hBmp1,
};
CBrick* pNode = new CBrick;
for(i = 0; i<15; i++)
{
pNode->m_hBmp = hBmp[i];//从下到上建立
AddBrick(pNode);
}
}//CreateTower
CBrick* CList::GetListHead()
{
return m_pHead;
}
int CList::GetListLength()
{
return m_nLength;
}
CBrick* CList::GetListTail()
{
return m_pTail;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -