作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想知道如何让玩家的句子在包含脏话后基本停止。现在,我已经设置好了,但是我需要知道如何使用 tolower 方法以及如何阻止它在使用此 for 循环时连续说同一个词 3 次:
std::size_t found;
std::string word[3] = { "swear", "swear1", "swear2" };
for(int i = 0; i < 3; i++)
{
found = msg.find(word[i]); // needs to have tolower
if(found != std::string::npos)
{
SendNotification("Message blocked. Does it contain swearing?");
return;
}
else
{
GetPlayer()->Say(msg, lang);
}
}
帮助将不胜感激!
最佳答案
它只阻止第一个单词的原因是因为当第一个单词不匹配时,您正在 Say()
中 else
阻止消息.在循环开始之前保留一个变量bool badWordFound = false
,并在if(...){ }
block 中将其设置为真。然后,在检查所有单词后,如果 badWordFound == true
显示您的警告,else Say()
set found to false
for each swear word
if found in the sentance
set found to true
if found is false
display sentance
else
display warning
HTH
编辑:此外,如果这不仅仅是一个练习,那么关于在内存中缓存过滤器列表的评论值得跟进。
关于c++ - 找到玩家说的话并阻止它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8497696/
我是一名优秀的程序员,十分优秀!