- 论坛徽章:
- 0
|
昨天没有做。晚上看羽毛球去了。不算昨天的话今天已经是第九天了,仍然有问题。不过基本上已经差不多了。现在的问题是:
有时候点不开雷,明明知道是雷但是展开无效。这个问题上次就有,但是上次没有太在意,一直在考虑递归开一片的问题。
我估计这个问题仍然是我递归的问题。递归过程中把状态置为LOCK锁定,但是函数没有正常退出,所以没有解除锁定状态。而expand函数是只能对INITIAL的格子状态展开的。
不能加断点调试真让我郁闷
不过解决了雷都被正确标记后,游戏不结束的问题。仍然是递归调用那里处理问题。
要考试了,近期不打算再花时间弄了。真让人精疲力尽……
把这部分有问题的代码贴出来,有高手请指教一下啊!
我的email:
blackchoc@126.com
//expand the mine
void expand(int row , int col)
{
if(isValid(row,col))
{
if(this.status[row][col] == INITIAL)
{
if(isBomb(row,col))
{
setGameStatus(EXPLODED);
}
else // it's not a bomb itself
{
if ( (computeBomb(row,col)-computeFlag(row,col)) != 0 ) // there are many bombs around this grid,如果发现它周围一共有3个雷,而且你都已经标了3个,那么不管你标的对不对都自动展开.
{
if(isBomb(row,col))// make a wrong judge
setGameStatus(EXPLODED);
else
{
this.status[row][col] = EXPANDED;
this.humantable[row*grid+col].setBackground(new Color(217, 217, 217));
this.showBomb(row,col);
this.marked++;
}
}
else // there is no bomb around this grid
{
this.status[row][col] = LOCK; //在递归调用前加锁add lock to the current grid
this.expand(row-1,col-1); //up_left
this.expand(row-1,col); //up_middle
this.expand(row-1,col+1); //up_right
this.expand(row,col-1); //left
this.expand(row,col+1); //right
this.expand(row+1,col-1); //down_left
this.expand(row+1,col); //down_middle
this.expand(row+1,col+1); //down_right
this.status[row][col] =
this.humantable[row*gridEXPANDED; //unlock the grid
this.marked++;+col].setBackground(new Color(217, 217, 217));
}
}
}
}
}
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/15262/showart_323789.html |
|