既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上C C++开发知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
else
Quit();
}
// 获取控制命令
DWORD m_oldtime;
CMD GetCmd()
{
// 获取控制值
while (true)
{
// 如果超时,自动下落一格
DWORD newtime = GetTickCount();
if (newtime - m_oldtime >= 500)
{
m_oldtime = newtime;
return CMD_DOWN;
}
// 如果有按键,返回按键对应的功能
if (\_kbhit())
{
switch (\_getch())
{
case 'w':
case 'W': return CMD_ROTATE;
case 'a':
case 'A': return CMD_LEFT;
case 'd':
case 'D': return CMD_RIGHT;
case 's':
case 'S': return CMD_DOWN;
case 27: return CMD_QUIT;
case ' ': return CMD_SINK;
case 0:
case 0xE0:
switch (\_getch())
{
case 72: return CMD_ROTATE;
case 75: return CMD_LEFT;
case 77: return CMD_RIGHT;
case 80: return CMD_DOWN;
}
}
}
// 延时 (降低 CPU 占用率)
Sleep(20);
}
}
// 分发控制命令
void DispatchCmd(CMD _cmd)
{
switch (_cmd)
{
case CMD_ROTATE: OnRotate(); break;
case CMD_LEFT: OnLeft(); break;
case CMD_RIGHT: OnRight(); break;
case CMD_DOWN: OnDown(); break;
case CMD_SINK: OnSink(); break;
case CMD_QUIT: break;
}
}
// 生成新的方块
void NewBlock()
{
g_CurBlock.id = g_NextBlock.id, g_NextBlock.id = rand() % 7;
g_CurBlock.dir = g_NextBlock.dir, g_NextBlock.dir = rand() % 4;
g_CurBlock.x = (WIDTH - 4) / 2;
g_CurBlock.y = HEIGHT + 2;
// 下移新方块直到有局部显示
WORD c = g_Blocks[g_CurBlock.id].dir[g_CurBlock.dir];
while ((c & 0xF) == 0)
{
g_CurBlock.y--;
c >>= 4;
}
// 绘制新方块
DrawBlock(g_CurBlock);
// 绘制下一个方块
setfillcolor(BLACK);
solidrectangle((WIDTH + 1) \* UNIT, 0, (WIDTH + 5) \* UNIT - 1, 4 \* UNIT - 1);
DrawBlock(g_NextBlock);
// 设置计时器,用于判断自动下落
m_oldtime = GetTickCount();
}
// 画单元方块
void DrawUnit(int x, int y, COLORREF c, DRAW _draw)
{
// 计算单元方块对应的屏幕坐标
int left = x * UNIT;
int top = (HEIGHT - y - 1) * UNIT;
int right = (x + 1) * UNIT - 1;
int bottom = (HEIGHT - y) * UNIT - 1;
// 画单元方块
switch (_draw)
{
case SHOW:
// 画普通方块
setlinecolor(0x006060);
roundrect(left + 1, top + 1, right - 1, bottom - 1, 5, 5);
setlinecolor(0x003030);
roundrect(left, top, right, bottom, 8, 8);
setfillcolor(c);
setlinecolor(LIGHTGRAY);
fillrectangle(left + 2, top + 2, right - 2, bottom - 2);
break;
case FIX:
// 画固定的方块
setfillcolor(RGB(GetRValue(c) \* 2 / 3, GetGValue(c) \* 2 / 3, GetBValue(c) \* 2 / 3));
setlinecolor(DARKGRAY);
fillrectangle(left + 1, top + 1, right - 1, bottom - 1);
break;
case CLEAR:
// 擦除方块
setfillcolor(BLACK);
solidrectangle(x \* UNIT, (HEIGHT - y - 1) \* UNIT, (x + 1) \* UNIT - 1, (HEIGHT - y) \* UNIT - 1);
break;
}
}
// 画方块
void DrawBlock(BLOCKINFO _block, DRAW _draw)
{
WORD b = g_Blocks[_block.id].dir[_block.dir];
int x, y;
for (int i = 0; i < 16; i++, b <<= 1)
if (b & 0x8000)
{
x = _block.x + i % 4;
y = _block.y - i / 4;
if (y < HEIGHT)
DrawUnit(x, y, g_Blocks[_block.id].color, _draw);
}
}
// 检测指定方块是否可以放下
bool CheckBlock(BLOCKINFO _block)
{
WORD b = g_Blocks[_block.id].dir[_block.dir];
int x, y;
for (int i = 0; i < 16; i++, b <<= 1)
if (b & 0x8000)
{
x = _block.x + i % 4;
y = _block.y - i / 4;
if ((x < 0) || (x >= WIDTH) || (y < 0))
return false;
if ((y < HEIGHT) && (g_World[x][y]))
return false;
}
return true;
}
// 旋转方块
void OnRotate()
{
// 获取可以旋转的 x 偏移量
int dx;
BLOCKINFO tmp = g_CurBlock;
tmp.dir++; if (CheckBlock(tmp)) { dx = 0; goto rotate; }
tmp.x = g_CurBlock.x - 1; if (CheckBlock(tmp)) { dx = -1; goto rotate; }
tmp.x = g_CurBlock.x + 1; if (CheckBlock(tmp)) { dx = 1; goto rotate; }
tmp.x = g_CurBlock.x - 2; if (CheckBlock(tmp)) { dx = -2; goto rotate; }
tmp.x = g_CurBlock.x + 2; if (CheckBlock(tmp)) { dx = 2; goto rotate; }
return;
rotate:
// 旋转
DrawBlock(g_CurBlock, CLEAR);
g_CurBlock.dir++;
g_CurBlock.x += dx;
DrawBlock(g_CurBlock);
}
// 左移方块
void OnLeft()
{
BLOCKINFO tmp = g_CurBlock;
tmp.x–;
if (CheckBlock(tmp))
{
DrawBlock(g_CurBlock, CLEAR);
g_CurBlock.x–;
DrawBlock(g_CurBlock);
}
}
// 右移方块
void OnRight()
{
BLOCKINFO tmp = g_CurBlock;
tmp.x++;
if (CheckBlock(tmp))
{
DrawBlock(g_CurBlock, CLEAR);
g_CurBlock.x++;
DrawBlock(g_CurBlock);
}
}
// 下移方块
void OnDown()
{
BLOCKINFO tmp = g_CurBlock;
tmp.y–;
if (CheckBlock(tmp))
{
DrawBlock(g_CurBlock, CLEAR);
g_CurBlock.y–;
DrawBlock(g_CurBlock);
}
else
OnSink(); // 不可下移时,执行“沉底方块”操作
}
// 沉底方块
void OnSink()
{
int i, x, y;
// 连续下移方块
DrawBlock(g_CurBlock, CLEAR);
BLOCKINFO tmp = g_CurBlock;
tmp.y--;
while (CheckBlock(tmp))
{
g_CurBlock.y--;
tmp.y--;
}
DrawBlock(g_CurBlock, FIX);
// 固定方块在游戏区
WORD b = g_Blocks[g_CurBlock.id].dir[g_CurBlock.dir];
for (i = 0; i < 16; i++, b <<= 1)
if (b & 0x8000)
{
if (g_CurBlock.y - i / 4 >= HEIGHT)
{ // 如果方块的固定位置超出高度,结束游戏
GameOver();
return;
}
else
g_World[g_CurBlock.x + i % 4][g_CurBlock.y - i / 4] = 1;
}
// 检查是否需要消掉行,并标记
BYTE remove = 0; // 低 4 位用来标记方块涉及的 4 行是否有消除行为
for (y = g_CurBlock.y; y >= max(g_CurBlock.y - 3, 0); y--)
{
i = 0;
for (x = 0; x < WIDTH; x++)
if (g_World[x][y] == 1)
i++;
if (i == WIDTH)
{
remove |= (1 << (g_CurBlock.y - y));
setfillcolor(LIGHTGREEN);
setlinecolor(LIGHTGREEN);
setfillstyle(BS_HATCHED, HS_DIAGCROSS);
fillrectangle(0, (HEIGHT - y - 1) \* UNIT + UNIT / 2 - 5, WIDTH \* UNIT - 1, (HEIGHT - y - 1) \* UNIT + UNIT / 2 + 5);
setfillstyle(BS_SOLID);
}
}
if (remove) // 如果产生整行消除
{
// 延时 300 毫秒
Sleep(300);
// 擦掉刚才标记的行
IMAGE img;
for (i = 0; i < 4; i++, remove >>= 1)
{
if (remove & 1)
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
片转存中…(img-EIShVCrS-1715601684757)]
[外链图片转存中…(img-SUTW4gb1-1715601684757)]
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!