前言
本来可以从俄罗斯方块控制台版改一版, 将UI接口换掉, 变成SDK版.
正好放假了, 有时间.
就用了一个星期来重头做一个新版, 享受一下静下心来, 有条不紊干活的感觉^_^
这个工程用来验证SDK编程中对消息循环, UI绘制, 局部刷新的理解.
做这么个东西, 以自己为用户, 玩起来还是挺耐玩.
完全靠4个箭头键实现左移, 右移, 旋转, 下落, 消行或固定
考虑到自己智商比较挫, 没有加自动落下的实现. 毕竟每个人都不喜欢输的感觉.
如果真是全心投入, 如果输了, 应该能总结出输的原因 : "做人心不能贪, 不能眼高手低, 如果有问题, 要立即解决, 不要指望时来运转".
反正输了之后, 能总结的失败原因能总结出来一堆.
正宗方块的资料
UI预览
工程下载
vc6sp6 + win7x64
工程下载点:俄罗斯方块SDK版
工程预览
4格骨牌数据,没有搞成内建数据类型的数组,封装成了类的数组, 如果要加入新的异形骨牌,容易维护.
我觉得这个数组比上次做的好, 增加再多的数据,也不会显的乱.
- CTetrominoData m_TetrominoData[TETROMINODATA_ARY_SIZE];
- void CRussiaBlock::TetrominoDataInit() {
- /// I型(方向0,90,180,270)
- m_TetrominoData[0] = CTetrominoDataI0();
- m_TetrominoData[1] = CTetrominoDataI90();
- m_TetrominoData[2] = CTetrominoDataI180();
- m_TetrominoData[3] = CTetrominoDataI270();
- m_TetrominoData[0].SetRotateL(&m_TetrominoData[3]);
- m_TetrominoData[0].SetRotateR(&m_TetrominoData[1]);
- m_TetrominoData[1].SetRotateL(&m_TetrominoData[0]);
- m_TetrominoData[1].SetRotateR(&m_TetrominoData[2]);
- m_TetrominoData[2].SetRotateL(&m_TetrominoData[1]);
- m_TetrominoData[2].SetRotateR(&m_TetrominoData[3]);
- m_TetrominoData[3].SetRotateL(&m_TetrominoData[2]);
- m_TetrominoData[3].SetRotateR(&m_TetrominoData[0]);
- /// O型(方向0,90,180,270)
- m_TetrominoData[4] = CTetrominoDataO0();
- m_TetrominoData[5] = CTetrominoDataO90();
- m_TetrominoData[6] = CTetrominoDataO180();
- m_TetrominoData[7] = CTetrominoDataO270();
- m_TetrominoData[4].SetRotateL(&m_TetrominoData[7]);
- m_TetrominoData[4].SetRotateR(&m_TetrominoData[5]);
- m_TetrominoData[5].SetRotateL(&m_TetrominoData[4]);
- m_TetrominoData[5].SetRotateR(&m_TetrominoData[6]);
- m_TetrominoData[6].SetRotateL(&m_TetrominoData[4]);
- m_TetrominoData[6].SetRotateR(&m_TetrominoData[7]);
- m_TetrominoData[7].SetRotateL(&m_TetrominoData[6]);
- m_TetrominoData[7].SetRotateR(&m_TetrominoData[4]);
- /// T型(方向0,90,180,270)
- m_TetrominoData[8] = CTetrominoDataT0();
- m_TetrominoData[9] = CTetrominoDataT90();
- m_TetrominoData[10] = CTetrominoDataT180();
- m_TetrominoData[11] = CTetrominoDataT270();
- m_TetrominoData[8].SetRotateL(&m_TetrominoData[11]);
- m_TetrominoData[8].SetRotateR(&m_TetrominoData[9]);
- m_TetrominoData[9].SetRotateL(&m_TetrominoData[8]);
- m_TetrominoData[9].SetRotateR(&m_TetrominoData[10]);
- m_TetrominoData[10].SetRotateL(&m_TetrominoData[9]);
- m_TetrominoData[10].SetRotateR(&m_TetrominoData[11]);
- m_TetrominoData[11].SetRotateL(&m_TetrominoData[10]);
- m_TetrominoData[11].SetRotateR(&m_TetrominoData[8]);
- /// J型(方向0,90,180,270)
- m_TetrominoData[12] = CTetrominoDataJ0();
- m_TetrominoData[13] = CTetrominoDataJ90();
- m_TetrominoData[14] = CTetrominoDataJ180();
- m_TetrominoData[15] = CTetrominoDataJ270();
- m_TetrominoData[12].SetRotateL(&m_TetrominoData[15]);
- m_TetrominoData[12].SetRotateR(&m_TetrominoData[13]);
- m_TetrominoData[13].SetRotateL(&m_TetrominoData[12]);
- m_TetrominoData[13].SetRotateR(&m_TetrominoData[14]);
- m_TetrominoData[14].SetRotateL(&m_TetrominoData[13]);
- m_TetrominoData[14].SetRotateR(&m_TetrominoData[15]);
- m_TetrominoData[15].SetRotateL(&m_TetrominoData[14]);
- m_TetrominoData[15].SetRotateR(&m_TetrominoData[12]);
- /// L型(方向0,90,180,270)
- m_TetrominoData[16] = CTetrominoDataL0();
- m_TetrominoData[17] = CTetrominoDataL90();
- m_TetrominoData[18] = CTetrominoDataL180();
- m_TetrominoData[19] = CTetrominoDataL270();
- m_TetrominoData[16].SetRotateL(&m_TetrominoData[19]);
- m_TetrominoData[16].SetRotateR(&m_TetrominoData[17]);
- m_TetrominoData[17].SetRotateL(&m_TetrominoData[16]);
- m_TetrominoData[17].SetRotateR(&m_TetrominoData[18]);
- m_TetrominoData[18].SetRotateL(&m_TetrominoData[17]);
- m_TetrominoData[18].SetRotateR(&m_TetrominoData[19]);
- m_TetrominoData[19].SetRotateL(&m_TetrominoData[18]);
- m_TetrominoData[19].SetRotateR(&m_TetrominoData[16]);
- /// S型(方向0,90,180,270)
- m_TetrominoData[20] = CTetrominoDataS0();
- m_TetrominoData[21] = CTetrominoDataS90();
- m_TetrominoData[22] = CTetrominoDataS180();
- m_TetrominoData[23] = CTetrominoDataS270();
- m_TetrominoData[20].SetRotateL(&m_TetrominoData[23]);
- m_TetrominoData[20].SetRotateR(&m_TetrominoData[21]);
- m_TetrominoData[21].SetRotateL(&m_TetrominoData[20]);
- m_TetrominoData[21].SetRotateR(&m_TetrominoData[22]);
- m_TetrominoData[22].SetRotateL(&m_TetrominoData[21]);
- m_TetrominoData[22].SetRotateR(&m_TetrominoData[23]);
- m_TetrominoData[23].SetRotateL(&m_TetrominoData[22]);
- m_TetrominoData[23].SetRotateR(&m_TetrominoData[20]);
- /// Z型(方向0,90,180,270)
- m_TetrominoData[24] = CTetrominoDataZ0();
- m_TetrominoData[25] = CTetrominoDataZ90();
- m_TetrominoData[26] = CTetrominoDataZ180();
- m_TetrominoData[27] = CTetrominoDataZ270();
- m_TetrominoData[24].SetRotateL(&m_TetrominoData[27]);
- m_TetrominoData[24].SetRotateR(&m_TetrominoData[25]);
- m_TetrominoData[25].SetRotateL(&m_TetrominoData[24]);
- m_TetrominoData[25].SetRotateR(&m_TetrominoData[26]);
- m_TetrominoData[26].SetRotateL(&m_TetrominoData[25]);
- m_TetrominoData[26].SetRotateR(&m_TetrominoData[27]);
- m_TetrominoData[27].SetRotateL(&m_TetrominoData[26]);
- m_TetrominoData[27].SetRotateR(&m_TetrominoData[24]);
- }
骨牌数据类
- // TetrominoData.h: interface for the CTetrominoData class.
- //
- //////////////////////////////////////////////////////////////////////
- #if !defined(AFX_TETROMINODATA_H__B5414B4A_2708_4A07_AD1D_7AAB52962115__INCLUDED_)
- #define AFX_TETROMINODATA_H__B5414B4A_2708_4A07_AD1D_7AAB52962115__INCLUDED_
- #if _MSC_VER > 1000
- #pragma once
- #endif // _MSC_VER > 1000
- #include "common.h"
- class CTetrominoData
- {
- public:
- CTetrominoData();
- virtual ~CTetrominoData();
- void SetColor(COLORREF color) {m_color = color;}
- COLORREF GetColor() {return m_color;}
- void SetData(BYTE uc0, BYTE uc1, BYTE uc2, BYTE uc3,
- BYTE uc4, BYTE uc5, BYTE uc6, BYTE uc7,
- BYTE uc8, BYTE uc9, BYTE uc10, BYTE uc11,
- BYTE uc12, BYTE uc13, BYTE uc14, BYTE uc15);
- BYTE operator [](int iIndex);
- void SetRotateL(CTetrominoData* pIn) {m_RotateL = pIn;}
- void SetRotateR(CTetrominoData* pIn) {m_RotateR = pIn;}
- CTetrominoData* GetRotateL() {return m_RotateL;}
- CTetrominoData* GetRotateR() {return m_RotateR;}
- int GetDataRows(); ///< 得到数据行数, 从左上角到最下面的有数据的行数
- int GetDataCols(); ///< 得到数据列数, 从左上角到最右面的有数据的列数
- private:
- COLORREF m_color;
- BYTE m_ucData[16];
- CTetrominoData* m_RotateL; ///< 向左转是哪个骨牌
- CTetrominoData* m_RotateR; ///< 向右转是哪个骨牌
- };
- #endif // !defined(AFX_TETROMINODATA_H__B5414B4A_2708_4A07_AD1D_7AAB52962115__INCLUDED_)
- // TetrominoData.cpp: implementation of the CTetrominoData class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "TetrominoData.h"
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CTetrominoData::CTetrominoData()
- {
- ZeroMemory(m_ucData, (sizeof(m_ucData) / sizeof(m_ucData[0])));
- m_color = RGB(0, 0, 0);
- }
- CTetrominoData::~CTetrominoData()
- {
- }
- void CTetrominoData::SetData(BYTE uc0, BYTE uc1, BYTE uc2, BYTE uc3,
- BYTE uc4, BYTE uc5, BYTE uc6, BYTE uc7,
- BYTE uc8, BYTE uc9, BYTE uc10, BYTE uc11,
- BYTE uc12, BYTE uc13, BYTE uc14, BYTE uc15) {
- m_ucData[0] = uc0;
- m_ucData[1] = uc1;
- m_ucData[2] = uc2;
- m_ucData[3] = uc3;
- m_ucData[4] = uc4;
- m_ucData[5] = uc5;
- m_ucData[6] = uc6;
- m_ucData[7] = uc7;
- m_ucData[8] = uc8;
- m_ucData[9] = uc9;
- m_ucData[10] = uc10;
- m_ucData[11] = uc11;
- m_ucData[12] = uc12;
- m_ucData[13] = uc13;
- m_ucData[14] = uc14;
- m_ucData[15] = uc15;
- }
- int CTetrominoData::GetDataRows() {
- if ((0 != m_ucData[12])
- || (0 != m_ucData[13])
- || (0 != m_ucData[14])
- || (0 != m_ucData[15])) {
- return 4;
- } else if ((0 != m_ucData[8])
- || (0 != m_ucData[9])
- || (0 != m_ucData[10])
- || (0 != m_ucData[11])) {
- return 3;
- } else if ((0 != m_ucData[4])
- || (0 != m_ucData[5])
- || (0 != m_ucData[6])
- || (0 != m_ucData[7])) {
- return 2;
- } else if ((0 != m_ucData[3])
- || (0 != m_ucData[2])
- || (0 != m_ucData[1])
- || (0 != m_ucData[0])) {
- return 1;
- }
- return 0;
- }
- int CTetrominoData::GetDataCols() {
- if ((0 != m_ucData[3])
- || (0 != m_ucData[7])
- || (0 != m_ucData[11])
- || (0 != m_ucData[15])) {
- return 4;
- } else if ((0 != m_ucData[2])
- || (0 != m_ucData[6])
- || (0 != m_ucData[10])
- || (0 != m_ucData[14])) {
- return 3;
- } else if ((0 != m_ucData[1])
- || (0 != m_ucData[5])
- || (0 != m_ucData[9])
- || (0 != m_ucData[13])) {
- return 2;
- } else if ((0 != m_ucData[0])
- || (0 != m_ucData[4])
- || (0 != m_ucData[8])
- || (0 != m_ucData[12])) {
- return 1;
- }
- return 0;
- }
- BYTE CTetrominoData::operator [](int iIndex) {
- BOOL bValid = (iIndex >= 0) && (iIndex < (sizeof(m_ucData) / sizeof(m_ucData[0])));
- return bValid ? m_ucData[iIndex] : m_ucData[0];
- }
- // TetrominoDataS0.h: interface for the CTetrominoDataS0 class.
- //
- //////////////////////////////////////////////////////////////////////
- #if !defined(AFX_TetrominoDataS0_H__D23B94A8_C1F2_44A4_9ACD_2B934A82F86A__INCLUDED_)
- #define AFX_TetrominoDataS0_H__D23B94A8_C1F2_44A4_9ACD_2B934A82F86A__INCLUDED_
- #if _MSC_VER > 1000
- #pragma once
- #endif // _MSC_VER > 1000
- #include "TetrominoData.h"
- class CTetrominoDataS0 : public CTetrominoData
- {
- public:
- CTetrominoDataS0();
- virtual ~CTetrominoDataS0();
- };
- #endif // !defined(AFX_TetrominoDataS0_H__D23B94A8_C1F2_44A4_9ACD_2B934A82F86A__INCLUDED_)
- // TetrominoDataS90.h: interface for the CTetrominoDataS90 class.
- //
- //////////////////////////////////////////////////////////////////////
- #if !defined(AFX_TetrominoDataS90_H__4157546E_E5CA_4624_B8A5_63AE11EBCD5C__INCLUDED_)
- #define AFX_TetrominoDataS90_H__4157546E_E5CA_4624_B8A5_63AE11EBCD5C__INCLUDED_
- #if _MSC_VER > 1000
- #pragma once
- #endif // _MSC_VER > 1000
- #include "TetrominoDataS0.h"
- class CTetrominoDataS90 : public CTetrominoDataS0
- {
- public:
- CTetrominoDataS90();
- virtual ~CTetrominoDataS90();
- };
- #endif // !defined(AFX_TetrominoDataS90_H__4157546E_E5CA_4624_B8A5_63AE11EBCD5C__INCLUDED_)
- // TetrominoDataS180.h: interface for the CTetrominoDataS180 class.
- //
- //////////////////////////////////////////////////////////////////////
- #if !defined(AFX_TetrominoDataS180_H__FC5200AC_B7CC_4291_AE86_3C2E983BD4C9__INCLUDED_)
- #define AFX_TetrominoDataS180_H__FC5200AC_B7CC_4291_AE86_3C2E983BD4C9__INCLUDED_
- #if _MSC_VER > 1000
- #pragma once
- #endif // _MSC_VER > 1000
- #include "TetrominoDataS0.h"
- class CTetrominoDataS180 : public CTetrominoDataS0
- {
- public:
- CTetrominoDataS180();
- virtual ~CTetrominoDataS180();
- };
- #endif // !defined(AFX_TetrominoDataS180_H__FC5200AC_B7CC_4291_AE86_3C2E983BD4C9__INCLUDED_)
- // TetrominoDataS270.h: interface for the CTetrominoDataS270 class.
- //
- //////////////////////////////////////////////////////////////////////
- #if !defined(AFX_TetrominoDataS270_H__4DDC72B7_219B_4E7B_8573_EA98D82CD754__INCLUDED_)
- #define AFX_TetrominoDataS270_H__4DDC72B7_219B_4E7B_8573_EA98D82CD754__INCLUDED_
- #if _MSC_VER > 1000
- #pragma once
- #endif // _MSC_VER > 1000
- #include "TetrominoDataS90.h"
- class CTetrominoDataS270 : public CTetrominoDataS90
- {
- public:
- CTetrominoDataS270();
- virtual ~CTetrominoDataS270();
- };
- #endif // !defined(AFX_TetrominoDataS270_H__4DDC72B7_219B_4E7B_8573_EA98D82CD754__INCLUDED_)
- // TetrominoDataS0.cpp: implementation of the CTetrominoDataS0 class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "TetrominoDataS0.h"
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CTetrominoDataS0::CTetrominoDataS0()
- {
- SetColor(RGB(10, 249, 10));
- SetData(
- 0, 1, 1, 0,
- 1, 1, 0, 0,
- 0, 0, 0, 0,
- 0, 0, 0, 0);
- }
- CTetrominoDataS0::~CTetrominoDataS0()
- {
- }
- // TetrominoDataS90.cpp: implementation of the CTetrominoDataS90 class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "TetrominoDataS90.h"
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CTetrominoDataS90::CTetrominoDataS90()
- {
- SetData(
- 1, 0, 0, 0,
- 1, 1, 0, 0,
- 0, 1, 0, 0,
- 0, 0, 0, 0);
- }
- CTetrominoDataS90::~CTetrominoDataS90()
- {
- }
- // TetrominoDataS180.cpp: implementation of the CTetrominoDataS180 class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "TetrominoDataS180.h"
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CTetrominoDataS180::CTetrominoDataS180()
- {
- SetData(
- 0, 1, 1, 0,
- 1, 1, 0, 0,
- 0, 0, 0, 0,
- 0, 0, 0, 0);
- }
- CTetrominoDataS180::~CTetrominoDataS180()
- {
- }
- // TetrominoDataS270.cpp: implementation of the CTetrominoDataS270 class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "TetrominoDataS270.h"
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CTetrominoDataS270::CTetrominoDataS270()
- {
- SetData(
- 1, 0, 0, 0,
- 1, 1, 0, 0,
- 0, 1, 0, 0,
- 0, 0, 0, 0);
- }
- CTetrominoDataS270::~CTetrominoDataS270()
- {
- }
http://blog.csdn.net/lostspeed/article/details/50643208