if (aCHAR == '字符' || '另一个字符') 问题
你好,所以我试图检查字符串中的某个字符,以确保它不是 \、=、| 等,如果不是,则用“玩家”字符替换空格,但该函数每次都返回 true,即使如果 char newLoc 等于 ''(空):
screen.get_contents 返回一个充满字符串的向量容器,并且
sprite.get_location 返回一个包含两个数字的 int 数组,[0] 代表 X,[1] 代表 Y。
bool check_collision(Sprite& sprite,int X, int Y, Screen& screen)
{
////////////////////// check whats already there /////
char newLoc = screen.get_contents(sprite.get_location()[0]+Y,sprite.get_location()[1]+X);
if (newLoc == '|' || '/' || '_' || '=' || 'X' || 'x' )
return true;
else
return false;
};
有什么问题吗? 谢谢!!
Hi so i'm trying to check a certain character in a string to make sure it's not a \,=,|, etc. and replacing the space with the "player" character if it's not but the function is returning true everytime, even if char newLoc is equal to '' (empty):
screen.get_contents returns a vector container full of strins, and
sprite.get_location returns an int array with two number, [0] representing X, [1] is Y.
bool check_collision(Sprite& sprite,int X, int Y, Screen& screen)
{
////////////////////// check whats already there /////
char newLoc = screen.get_contents(sprite.get_location()[0]+Y,sprite.get_location()[1]+X);
if (newLoc == '|' || '/' || '_' || '=' || 'X' || 'x' )
return true;
else
return false;
};
what is the problem? Thanks!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要:
您所写的内容相当于:
相当于:
请注意,更简洁的编写方式可能是:
You need:
What you have written is equivalent to:
which is equivalent to:
Note that a cleaner way of writing this might be:
不起作用,你必须这样做:
但这更容易阅读:
doesn't work, you must do it like this:
However this is more easy to read: