1.游戏界面
2.游戏说明
贪吃蛇游戏按键说明:
升级版的功能:可以进行通关模式,通过方向键WSAD键或者上下左右键,可以改变人移动方向的改变:
3.程序分析
第一部分——绘制并打印地图(使用三维数组):
int g_map[2][10][12] =
{
{
{1,1,1,1,1,0,0,0,0,0,0,0},
{1,0,0,0,1,0,1,1,1,0,0,0},
{1,0,4,0,1,0,1,1,1,1,1,1},
{1,0,4,6,1,0,1,0,0,0,3,1},
{1,1,1,4,1,1,1,0,0,0,3,1},
{0,1,0,0,0,0,0,0,0,0,3,1},
{0,1,0,0,0,1,0,0,0,0,0,1},
{0,1,0,0,0,1,0,0,0,0,0,1},
{0,1,1,1,1,1,0,0,0,0,0,1},
{0,0,0,0,0,0,1,1,1,1,1,1},
},
{
{0,1,1,1,1,0,0,0,0,0,0,0},
{0,1,1,1,1,1,1,1,1,0,0,0},
{0,1,0,0,0,0,1,1,1,1,1,1},
{1,1,4,1,1,0,1,1,0,0,0,1},
{1,0,6,0,1,0,0,1,0,0,0,1},
{1,0,0,1,1,1,0,0,0,0,0,1},
{1,0,0,0,4,0,0,4,0,0,0,1},
{1,0,3,3,1,0,4,0,0,0,1,1},
{1,1,3,3,1,0,0,0,1,1,1,0},
{0,1,1,1,1,1,1,1,1,1,1,0},
},
};
int g_nCurrentLevel = 0;
void DrapMap();
void DrapMap()
{
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 12; j++)
{
switch (g_map[g_nCurrentLevel][i][j])
{
case 0:
printf(" ");
break;
case 1:
SetColor(FOREGROUND_RED | FOREGROUND_INTENSITY);
printf("■");
break;
case 3:
SetColor(FOREGROUND_GREEN | FOREGROUND_INTENSITY);
printf("☆");
break;
case 4:
SetColor(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
printf("□");
break;
case 6:
SetColor(FOREGROUND_BLUE | FOREGROUND_INTENSITY);
printf("♀");
break;
case 7:
SetColor(FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
printf("★");
break;
case 9:
SetColor(FOREGROUND_BLUE | FOREGROUND_INTENSITY);
printf("♀");
break;
}
}
printf("\n");
}
}
第二部分——获取玩家位置,控制方向:
POINT GetGamerPosition()
{
POINT pos = { -1,-1 };
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 12; j++)
{
if (g_map[i][j] == 6 || g_map[i][j] == 9)
{
pos.x = i;
pos.y = j;
return pos;
}
}
}
return pos;
}
void Up()
{
POINT pos = GetGamerPosition();
if (g_map[pos.x - 1][pos.y] == 0)
{
g_map[pos.x - 1][pos.y] = 6;
if (g_map[pos.x][pos.y] == 9)
g_map[pos.x][pos.y] = 3;
else
g_map[pos.x][pos.y] = 0;
}
if (g_map[pos.x - 1][pos.y] == 3)
{
g_map[pos.x - 1][pos.y] = 9;
if (g_map[pos.x][pos.y] == 9)
g_map[pos.x][pos.y] = 3;
else
g_map[pos.x][pos.y] = 0;
}
if (g_map[pos.x - 1][pos.y] == 4)
{
if (g_map[pos.x - 2][pos.y] == 0)
{
g_map[pos.x - 2][pos.y] = 4;
g_map[pos.x - 1][pos.y] = 6;
if (g_map[pos.x][pos.y] == 9)
g_map[pos.x][pos.y] = 3;
else
g_map[pos.x][pos.y] = 0;
}
if (g_map[pos.x - 2][pos.y] == 3)
{
g_map[pos.x - 2][pos.y] = 7;
g_map[pos.x - 1][pos.y] = 6;
if (g_map[pos.x][pos.y] == 9)
g_map[pos.x][pos.y] = 3;
else
g_map[pos.x][pos.y] = 0;
}
}
if (g_map[pos.x - 1][pos.y] == 7)
{
if (g_map[pos.x - 2][pos.y] == 0)
{
g_map[pos.x - 2][pos.y] = 4;
g_map[pos.x - 1][pos.y] = 9;
if (g_map[pos.x][pos.y] == 9)
g_map[pos.x][pos.y] = 3;
else
g_map[pos.x][pos.y] = 0;
}
if (g_map[pos.x - 2][pos.y] == 3)
{
g_map[pos.x - 2][pos.y] = 7;
g_map[pos.x - 1][pos.y] = 9;
if (g_map[pos.x][pos.y] == 9)
g_map[pos.x][pos.y] = 3;
else
g_map[pos.x][pos.y] = 0;
}
}
}
void Down()
{
POINT pos = GetGamerPosition();
if (g_map[pos.x + 1][pos.y] == 0)
{
g_map[pos.x + 1][pos.y] = 6;
if (g_map[pos.x][pos.y] == 9)
g_map[pos.x][pos.y] = 3;
else
g_map[pos.x][pos.y] = 0;
}
if (g_map[pos.x + 1][pos.y] == 3)
{
g_map[pos.x + 1][pos.y] = 9;
if (g_map[pos.x][pos.y] == 9)
g_map[pos.x][pos.y] = 3;
else
g_map[pos.x][pos.y] = 0;
}
if (g_map[pos.x + 1][pos.y] == 4)
{
if (g_map[pos.x + 2][pos.y] == 0)
{
g_map[pos.x + 2][pos.y] = 4;
g_map[pos.x + 1][pos.y] = 6;
if (g_map[pos.x][pos.y] == 9)
g_map[pos.x][pos.y] = 3;
else
g_map[pos.x][pos.y] = 0;
}
if (g_map[pos.x + 2][pos.y] == 3)
{
g_map[pos.x + 2][pos.y] = 7;
g_map[pos.x + 1][pos.y] = 6;
if (g_map[pos.x][pos.y] == 9)
g_map[pos.x][pos.y] = 3;
else
g_map[pos.x][pos.y] = 0;
}
}
if (g_map[pos.x + 1][pos.y] == 7)
{
if (g_map[pos.x + 2][pos.y] == 0)
{
g_map[pos.x + 2][pos.y] = 4;
g_map[pos.x + 1][pos.y] = 9;
if (g_map[pos.x][pos.y] == 9)
g_map[pos.x][pos.y] = 3;
else
g_map[pos.x][pos.y] = 0;
}
if (g_map[pos.x + 2][pos.y] == 3)
{
g_map[pos.x + 2][pos.y] = 7;
g_map[pos.x + 1][pos.y] = 9;
if (g_map[pos.x][pos.y] == 9)
g_map[pos.x][pos.y] = 3;
else
g_map[pos.x][pos.y] = 0;
}
}
}
void Left()
{
POINT pos = GetGamerPosition();
if (g_map[pos.x][pos.y - 1] == 0)
{
g_map[pos.x][pos.y - 1] = 6;
if (g_map[pos.x][pos.y] == 9)
g_map[pos.x][pos.y] = 3;
else
g_map[pos.x][pos.y] = 0;
}
if (g_map[pos.x][pos.y - 1] == 3)
{
g_map[pos.x][pos.y - 1] = 9;
if (g_map[pos.x][pos.y] == 9)
g_map[pos.x][pos.y] = 3;
else
g_map[pos.x][pos.y] = 0;
}
if (g_map[pos.x][pos.y - 1] == 4)
{
if (g_map[pos.x][pos.y - 2] == 0)
{
g_map[pos.x][pos.y - 2] = 4;
g_map[pos.x][pos.y - 1] = 6;
if (g_map[pos.x][pos.y] == 9)
g_map[pos.x][pos.y] = 3;
else
g_map[pos.x][pos.y] = 0;
}
if (g_map[pos.x][pos.y - 2] == 3)
{
g_map[pos.x][pos.y - 2] = 7;
g_map[pos.x][pos.y - 1] = 6;
if (g_map[pos.x][pos.y] == 9)
g_map[pos.x][pos.y] = 3;
else
g_map[pos.x][pos.y] = 0;
}
}
if (g_map[pos.x][pos.y - 1] == 7)
{
if (g_map[pos.x][pos.y - 2] == 0)
{
g_map[pos.x][pos.y - 2] = 4;
g_map[pos.x][pos.y - 1] = 9;
if (g_map[pos.x][pos.y] == 9)
g_map[pos.x][pos.y] = 3;
else
g_map[pos.x][pos.y] = 0;
}
if (g_map[pos.x][pos.y - 2] == 3)
{
g_map[pos.x][pos.y - 2] = 7;
g_map[pos.x][pos.y - 1] = 9;
if (g_map[pos.x][pos.y] == 9)
g_map[pos.x][pos.y] = 3;
else
g_map[pos.x][pos.y] = 0;
}
}
}
void Right()
{
POINT pos = GetGamerPosition();
if (g_map[pos.x][pos.y + 1] == 0)
{
g_map[pos.x][pos.y + 1] = 6;
if (g_map[pos.x][pos.y] == 9)
g_map[pos.x][pos.y] = 3;
else
g_map[pos.x][pos.y] = 0;
}
if (g_map[pos.x][pos.y + 1] == 3)
{
g_map[pos.x][pos.y + 1] = 9;
if (g_map[pos.x][pos.y] == 9)
g_map[pos.x][pos.y] = 3;
else
g_map[pos.x][pos.y] = 0;
}
if (g_map[pos.x][pos.y + 1] == 4)
{
if (g_map[pos.x][pos.y + 2] == 0)
{
g_map[pos.x][pos.y + 2] = 4;
g_map[pos.x][pos.y + 1] = 6;
if (g_map[pos.x][pos.y] == 9)
g_map[pos.x][pos.y] = 3;
else
g_map[pos.x][pos.y] = 0;
}
if (g_map[pos.x][pos.y + 2] == 3)
{
g_map[pos.x][pos.y + 2] = 7;
g_map[pos.x][pos.y + 1] = 6;
if (g_map[pos.x][pos.y] == 9)
g_map[pos.x][pos.y] = 3;
else
g_map[pos.x][pos.y] = 0;
}
}
if (g_map[pos.x][pos.y + 1] == 7)
{
if (g_map[pos.x][pos.y + 2] == 0)
{
g_map[pos.x][pos.y + 2] = 4;
g_map[pos.x][pos.y + 1] = 9;
if (g_map[pos.x][pos.y] == 9)
g_map[pos.x][pos.y] = 3;
else
g_map[pos.x][pos.y] = 0;
}
if (g_map[pos.x][pos.y + 2] == 3)
{
g_map[pos.x][pos.y + 2] = 7;
g_map[pos.x][pos.y + 1] = 9;
if (g_map[pos.x][pos.y] == 9)
g_map[pos.x][pos.y] = 3;
else
g_map[pos.x][pos.y] = 0;
}
}
}
第三部分——计算空余箱子的个数,判断是否进入下一关:
int GetSpaceBox()
{
int nCount = 0;
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 12; j++)
{
if (g_map[g_nCurrentLevel][i][j] == 4)
nCount++;
}
}
return nCount;
}
4.整个游戏源代码
#include <stdio.h>
#include <Windows.h>
#include <stdlib.h>
#include <conio.h>
int g_map[2][10][12] =
{
{
{1,1,1,1,1,0,0,0,0,0,0,0},
{1,0,0,0,1,0,1,1,1,0,0,0},
{1,0,4,0,1,0,1,1,1,1,1,1},
{1,0,4,6,1,0,1,0,0,0,3,1},
{1,1,1,4,1,1,1,0,0,0,3,1},
{0,1,0,0,0,0,0,0,0,0,3,1},
{0,1,0,0,0,1,0,0,0,0,0,1},
{0,1,0,0,0,1,0,0,0,0,0,1},
{0,1,1,1,1,1,0,0,0,0,0,1},
{0,0,0,0,0,0,1,1,1,1,1,1},
},
{
{0,1,1,1,1,0,0,0,0,0,0,0},
{0,1,1,1,1,1,1,1,1,0,0,0},
{0,1,0,0,0,0,1,1,1,1,1,1},
{1,1,4,1,1,0,1,1,0,0,0,1},
{1,0,6,0,1,0,0,1,0,0,0,1},
{1,0,0,1,1,1,0,0,0,0,0,1},
{1,0,0,0,4,0,0,4,0,0,0,1},
{1,0,3,3,1,0,4,0,0,0,1,1},
{1,1,3,3,1,0,0,0,1,1,1,0},
{0,1,1,1,1,1,1,1,1,1,1,0},
},
};
int g_nCurrentLevel = 0;
void DrapMap();
POINT GetGamerPosition();
void Up();
void Down();
void Left();
void Right();
int GetSpaceBox();
void SetColor(int nColor);
int main()
{
SetConsoleTitle(L"推箱子");
system("mode con cols=26 lines=12");
while (1)
{
if (GetSpaceBox() == 0)
{
g_nCurrentLevel++;
}
system("cls");
DrapMap();
char ch = _getch();
switch (ch)
{
case 'w':case 72:
Up();
break;
case 's':case 80:
Down();
break;
case 'a':case 75:
Left();
break;
case 'd':case 77:
Right();
break;
}
}
return 0;
}
void DrapMap()
{
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 12; j++)
{
switch (g_map[g_nCurrentLevel][i][j])
{
case 0:
printf(" ");
break;
case 1:
SetColor(FOREGROUND_RED | FOREGROUND_INTENSITY);
printf("■");
break;
case 3:
SetColor(FOREGROUND_GREEN | FOREGROUND_INTENSITY);
printf("☆");
break;
case 4:
SetColor(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
printf("□");
break;
case 6:
SetColor(FOREGROUND_BLUE | FOREGROUND_INTENSITY);
printf("♀");
break;
case 7:
SetColor(FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
printf("★");
break;
case 9:
SetColor(FOREGROUND_BLUE | FOREGROUND_INTENSITY);
printf("♀");
break;
}
}
printf("\n");
}
}
POINT GetGamerPosition()
{
POINT pos = { -1,-1 };
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 12; j++)
{
if (g_map[g_nCurrentLevel][i][j] == 6 || g_map[g_nCurrentLevel][i][j] == 9)
{
pos.x = i;
pos.y = j;
return pos;
}
}
}
return pos;
}
void Up()
{
POINT pos = GetGamerPosition();
if (g_map[g_nCurrentLevel][pos.x - 1][pos.y] == 0)
{
g_map[g_nCurrentLevel][pos.x - 1][pos.y] = 6;
if (g_map[g_nCurrentLevel][pos.x][pos.y] == 9)
g_map[g_nCurrentLevel][pos.x][pos.y] = 3;
else
g_map[g_nCurrentLevel][pos.x][pos.y] = 0;
}
if (g_map[g_nCurrentLevel][pos.x - 1][pos.y] == 3)
{
g_map[g_nCurrentLevel][pos.x - 1][pos.y] = 9;
if (g_map[g_nCurrentLevel][pos.x][pos.y] == 9)
g_map[g_nCurrentLevel][pos.x][pos.y] = 3;
else
g_map[g_nCurrentLevel][pos.x][pos.y] = 0;
}
if (g_map[g_nCurrentLevel][pos.x - 1][pos.y] == 4)
{
if (g_map[g_nCurrentLevel][pos.x - 2][pos.y] == 0)
{
g_map[g_nCurrentLevel][pos.x - 2][pos.y] = 4;
g_map[g_nCurrentLevel][pos.x - 1][pos.y] = 6;
if (g_map[g_nCurrentLevel][pos.x][pos.y] == 9)
g_map[g_nCurrentLevel][pos.x][pos.y] = 3;
else
g_map[g_nCurrentLevel][pos.x][pos.y] = 0;
}
if (g_map[g_nCurrentLevel][pos.x - 2][pos.y] == 3)
{
g_map[g_nCurrentLevel][pos.x - 2][pos.y] = 7;
g_map[g_nCurrentLevel][pos.x - 1][pos.y] = 6;
if (g_map[g_nCurrentLevel][pos.x][pos.y] == 9)
g_map[g_nCurrentLevel][pos.x][pos.y] = 3;
else
g_map[g_nCurrentLevel][pos.x][pos.y] = 0;
}
}
if (g_map[g_nCurrentLevel][pos.x - 1][pos.y] == 7)
{
if (g_map[g_nCurrentLevel][pos.x - 2][pos.y] == 0)
{
g_map[g_nCurrentLevel][pos.x - 2][pos.y] = 4;
g_map[g_nCurrentLevel][pos.x - 1][pos.y] = 9;
if (g_map[g_nCurrentLevel][pos.x][pos.y] == 9)
g_map[g_nCurrentLevel][pos.x][pos.y] = 3;
else
g_map[g_nCurrentLevel][pos.x][pos.y] = 0;
}
if (g_map[g_nCurrentLevel][pos.x - 2][pos.y] == 3)
{
g_map[g_nCurrentLevel][pos.x - 2][pos.y] = 7;
g_map[g_nCurrentLevel][pos.x - 1][pos.y] = 9;
if (g_map[g_nCurrentLevel][pos.x][pos.y] == 9)
g_map[g_nCurrentLevel][pos.x][pos.y] = 3;
else
g_map[g_nCurrentLevel][pos.x][pos.y] = 0;
}
}
}
void Down()
{
POINT pos = GetGamerPosition();
if (g_map[g_nCurrentLevel][pos.x + 1][pos.y] == 0)
{
g_map[g_nCurrentLevel][pos.x + 1][pos.y] = 6;
if (g_map[g_nCurrentLevel][pos.x][pos.y] == 9)
g_map[g_nCurrentLevel][pos.x][pos.y] = 3;
else
g_map[g_nCurrentLevel][pos.x][pos.y] = 0;
}
if (g_map[g_nCurrentLevel][pos.x + 1][pos.y] == 3)
{
g_map[g_nCurrentLevel][pos.x + 1][pos.y] = 9;
if (g_map[g_nCurrentLevel][pos.x][pos.y] == 9)
g_map[g_nCurrentLevel][pos.x][pos.y] = 3;
else
g_map[g_nCurrentLevel][pos.x][pos.y] = 0;
}
if (g_map[g_nCurrentLevel][pos.x + 1][pos.y] == 4)
{
if (g_map[g_nCurrentLevel][pos.x + 2][pos.y] == 0)
{
g_map[g_nCurrentLevel][pos.x + 2][pos.y] = 4;
g_map[g_nCurrentLevel][pos.x + 1][pos.y] = 6;
if (g_map[g_nCurrentLevel][pos.x][pos.y] == 9)
g_map[g_nCurrentLevel][pos.x][pos.y] = 3;
else
g_map[g_nCurrentLevel][pos.x][pos.y] = 0;
}
if (g_map[g_nCurrentLevel][pos.x + 2][pos.y] == 3)
{
g_map[g_nCurrentLevel][pos.x + 2][pos.y] = 7;
g_map[g_nCurrentLevel][pos.x + 1][pos.y] = 6;
if (g_map[g_nCurrentLevel][pos.x][pos.y] == 9)
g_map[g_nCurrentLevel][pos.x][pos.y] = 3;
else
g_map[g_nCurrentLevel][pos.x][pos.y] = 0;
}
}
if (g_map[g_nCurrentLevel][pos.x + 1][pos.y] == 7)
{
if (g_map[g_nCurrentLevel][pos.x + 2][pos.y] == 0)
{
g_map[g_nCurrentLevel][pos.x + 2][pos.y] = 4;
g_map[g_nCurrentLevel][pos.x + 1][pos.y] = 9;
if (g_map[g_nCurrentLevel][pos.x][pos.y] == 9)
g_map[g_nCurrentLevel][pos.x][pos.y] = 3;
else
g_map[g_nCurrentLevel][pos.x][pos.y] = 0;
}
if (g_map[g_nCurrentLevel][pos.x + 2][pos.y] == 3)
{
g_map[g_nCurrentLevel][pos.x + 2][pos.y] = 7;
g_map[g_nCurrentLevel][pos.x + 1][pos.y] = 9;
if (g_map[g_nCurrentLevel][pos.x][pos.y] == 9)
g_map[g_nCurrentLevel][pos.x][pos.y] = 3;
else
g_map[g_nCurrentLevel][pos.x][pos.y] = 0;
}
}
}
void Left()
{
POINT pos = GetGamerPosition();
if (g_map[g_nCurrentLevel][pos.x][pos.y - 1] == 0)
{
g_map[g_nCurrentLevel][pos.x][pos.y - 1] = 6;
if (g_map[g_nCurrentLevel][pos.x][pos.y] == 9)
g_map[g_nCurrentLevel][pos.x][pos.y] = 3;
else
g_map[g_nCurrentLevel][pos.x][pos.y] = 0;
}
if (g_map[g_nCurrentLevel][pos.x][pos.y - 1] == 3)
{
g_map[g_nCurrentLevel][pos.x][pos.y - 1] = 9;
if (g_map[g_nCurrentLevel][pos.x][pos.y] == 9)
g_map[g_nCurrentLevel][pos.x][pos.y] = 3;
else
g_map[g_nCurrentLevel][pos.x][pos.y] = 0;
}
if (g_map[g_nCurrentLevel][pos.x][pos.y - 1] == 4)
{
if (g_map[g_nCurrentLevel][pos.x][pos.y - 2] == 0)
{
g_map[g_nCurrentLevel][pos.x][pos.y - 2] = 4;
g_map[g_nCurrentLevel][pos.x][pos.y - 1] = 6;
if (g_map[g_nCurrentLevel][pos.x][pos.y] == 9)
g_map[g_nCurrentLevel][pos.x][pos.y] = 3;
else
g_map[g_nCurrentLevel][pos.x][pos.y] = 0;
}
if (g_map[g_nCurrentLevel][pos.x][pos.y - 2] == 3)
{
g_map[g_nCurrentLevel][pos.x][pos.y - 2] = 7;
g_map[g_nCurrentLevel][pos.x][pos.y - 1] = 6;
if (g_map[g_nCurrentLevel][pos.x][pos.y] == 9)
g_map[g_nCurrentLevel][pos.x][pos.y] = 3;
else
g_map[g_nCurrentLevel][pos.x][pos.y] = 0;
}
}
if (g_map[g_nCurrentLevel][pos.x][pos.y - 1] == 7)
{
if (g_map[g_nCurrentLevel][pos.x][pos.y - 2] == 0)
{
g_map[g_nCurrentLevel][pos.x][pos.y - 2] = 4;
g_map[g_nCurrentLevel][pos.x][pos.y - 1] = 9;
if (g_map[g_nCurrentLevel][pos.x][pos.y] == 9)
g_map[g_nCurrentLevel][pos.x][pos.y] = 3;
else
g_map[g_nCurrentLevel][pos.x][pos.y] = 0;
}
if (g_map[g_nCurrentLevel][pos.x][pos.y - 2] == 3)
{
g_map[g_nCurrentLevel][pos.x][pos.y - 2] = 7;
g_map[g_nCurrentLevel][pos.x][pos.y - 1] = 9;
if (g_map[g_nCurrentLevel][pos.x][pos.y] == 9)
g_map[g_nCurrentLevel][pos.x][pos.y] = 3;
else
g_map[g_nCurrentLevel][pos.x][pos.y] = 0;
}
}
}
void Right()
{
POINT pos = GetGamerPosition();
if (g_map[g_nCurrentLevel][pos.x][pos.y + 1] == 0)
{
g_map[g_nCurrentLevel][pos.x][pos.y + 1] = 6;
if (g_map[g_nCurrentLevel][pos.x][pos.y] == 9)
g_map[g_nCurrentLevel][pos.x][pos.y] = 3;
else
g_map[g_nCurrentLevel][pos.x][pos.y] = 0;
}
if (g_map[g_nCurrentLevel][pos.x][pos.y + 1] == 3)
{
g_map[g_nCurrentLevel][pos.x][pos.y + 1] = 9;
if (g_map[g_nCurrentLevel][pos.x][pos.y] == 9)
g_map[g_nCurrentLevel][pos.x][pos.y] = 3;
else
g_map[g_nCurrentLevel][pos.x][pos.y] = 0;
}
if (g_map[g_nCurrentLevel][pos.x][pos.y + 1] == 4)
{
if (g_map[g_nCurrentLevel][pos.x][pos.y + 2] == 0)
{
g_map[g_nCurrentLevel][pos.x][pos.y + 2] = 4;
g_map[g_nCurrentLevel][pos.x][pos.y + 1] = 6;
if (g_map[g_nCurrentLevel][pos.x][pos.y] == 9)
g_map[g_nCurrentLevel][pos.x][pos.y] = 3;
else
g_map[g_nCurrentLevel][pos.x][pos.y] = 0;
}
if (g_map[g_nCurrentLevel][pos.x][pos.y + 2] == 3)
{
g_map[g_nCurrentLevel][pos.x][pos.y + 2] = 7;
g_map[g_nCurrentLevel][pos.x][pos.y + 1] = 6;
if (g_map[g_nCurrentLevel][pos.x][pos.y] == 9)
g_map[g_nCurrentLevel][pos.x][pos.y] = 3;
else
g_map[g_nCurrentLevel][pos.x][pos.y] = 0;
}
}
if (g_map[g_nCurrentLevel][pos.x][pos.y + 1] == 7)
{
if (g_map[g_nCurrentLevel][pos.x][pos.y + 2] == 0)
{
g_map[g_nCurrentLevel][pos.x][pos.y + 2] = 4;
g_map[g_nCurrentLevel][pos.x][pos.y + 1] = 9;
if (g_map[g_nCurrentLevel][pos.x][pos.y] == 9)
g_map[g_nCurrentLevel][pos.x][pos.y] = 3;
else
g_map[g_nCurrentLevel][pos.x][pos.y] = 0;
}
if (g_map[g_nCurrentLevel][pos.x][pos.y + 2] == 3)
{
g_map[g_nCurrentLevel][pos.x][pos.y + 2] = 7;
g_map[g_nCurrentLevel][pos.x][pos.y + 1] = 9;
if (g_map[g_nCurrentLevel][pos.x][pos.y] == 9)
g_map[g_nCurrentLevel][pos.x][pos.y] = 3;
else
g_map[g_nCurrentLevel][pos.x][pos.y] = 0;
}
}
}
int GetSpaceBox()
{
int nCount = 0;
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 12; j++)
{
if (g_map[g_nCurrentLevel][i][j] == 4)
nCount++;
}
}
return nCount;
}
void SetColor(int nColor)
{
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, nColor);
}
感谢阅读,如有不足之处,欢迎来指正。谢谢!
|