开发者

python games problem

I have made a mine sweeper game which fully works except for one key point, which is:

Allow the player to place flags on cells to mark mine locations and to remove flags. if a cell is marked wi开发者_C百科th a flag the player can not activate it by clicking on it.

Now I don't know how to do this flag requirement.


If you're asking for a hint on how to do that, a safe way to go is to make the playfield a 2D array and each item of the array an object holding certain information. (In your case that's probably a boolean telling whether the cell contains a mine and a boolean telling whether the cell is marked or not.)


You can make a list for each specific tile in the game, and its attributes eg. number (int), flagged (bool), death_tile (bool) and more. You can then put:

if not [square coordinate] [flagged]:
    open_tile()

Replace [square coordinate] with its value in the list, and [flagged] with the data value saying if it is flagged or not. open_tile() would be replaced by the function that reveals the tile.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜