-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pr-meltout #45
base: master
Are you sure you want to change the base?
pr-meltout #45
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
代码清爽,看着真是舒服啊
level1/p10_pushBoxes/pushBoxes.c
Outdated
flag = 0; | ||
for (int k = 1; k <= AimNum; ++k) | ||
{ | ||
if (i == AimX[k] && j == AimY[k]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
嵌套层次稍深了一点,可以考虑适当地提取函数
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
将判断修改进了原有的CheckStatus函数中
int CheckStatus(int x, int y)
{
if (x < 0 || x > h + 1 || y < 0 || y > w + 1)return -1;
if (Maze[x][y] == '#')return 0;
if (Maze[x][y] == 'o')return 1;
else
{
for (int k = 1; k <= AimNum; ++k)
{
if (x == AimX[k] && y == AimY[k])
return 2;
}
}
return 3;
}
PrintMaze中修改为
if (i == NowX && j == NowY)printf("S");
else if (CheckStatus(i, j) == 2)printf("O");
else printf("%c", Maze[i][j]);
level1/p10_pushBoxes/pushBoxes.c
Outdated
flag = CheckStatus(NowX + tx * 2, NowY + ty * 2); | ||
if (flag == 2) | ||
{ | ||
Maze[NowX + tx][NowY + ty] = ' '; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上,层次过深
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
新增函数MoveCharacter
int MoveCharacter(int tx, int ty)
{
int flag[2];
flag[0] = CheckStatus(NowX + tx, NowY + ty);
flag[1] = CheckStatus(NowX + tx * 2, NowY + ty * 2);
if (flag[0] == 1 && flag[1] >= 2)
{
Maze[NowX + tx][NowY + ty] = ' ';
Maze[NowX + tx * 2][NowY + ty * 2] = 'o';
NowX += tx; NowY += ty;
Score--;
}
else if (flag[0] >= 2)
{
NowX += tx;
NowY += ty;
Score--;
}
else return 1;
return 0;
}
返回1则说明未移动,主函数中不进行刷新
ヽ(○´∀`)ノ♪