gpt4 book ai didi

c++ - 在棋盘游戏中检查大量复选框的最佳方法

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:08:40 25 4
gpt4 key购买 nike

我在游戏中有很多复选框,需要一套规则。有一个规则,就是整个矩阵的一行中只能有一个交叉复选框。我把这个问题想象成一个二维数组,然后检查每一行/每一列。有没有更快的方法或者更好的方法,因为会有很多IF,ELSE..

Sample

最佳答案

这在很大程度上取决于你如何表示你的矩阵...如果我理解你的问题,最简单的方法就是简单地做一个循环,并为每一行计算检查的数量 。所以:

for each row:

if col1 = is checked, check++

if col2 = is checked, check++

if col3 = is checked, check++

if check > 1 tell the user that there is an error.

end for

如果您更改矩阵以存储未选中的 0 值和选中的 1 值,您可以像这样测试它:

for each row:

if col1 + col2 + col3 > 1 tell the user that there is an error

end for

关于c++ - 在棋盘游戏中检查大量复选框的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17558628/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com