Skip to content
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

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open

pr-meltout #45

wants to merge 16 commits into from

Conversation

me1t0ut
Copy link

@me1t0ut me1t0ut commented Mar 6, 2019

ヽ(○´∀`)ノ♪

Copy link
Owner

@luckymark luckymark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

代码清爽,看着真是舒服啊

flag = 0;
for (int k = 1; k <= AimNum; ++k)
{
if (i == AimX[k] && j == AimY[k])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嵌套层次稍深了一点,可以考虑适当地提取函数

Copy link
Author

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]);

flag = CheckStatus(NowX + tx * 2, NowY + ty * 2);
if (flag == 2)
{
Maze[NowX + tx][NowY + ty] = ' ';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上,层次过深

Copy link
Author

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则说明未移动,主函数中不进行刷新

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants