【发布时间】:2018-03-26 05:05:39
【问题描述】:
所有值的范围从 -100.0f 到 100.0f
public float happysad = 0.0f;
public float passiveagressive = 0.0f;
public float friendenemy = 0.0f;
public float weakstrong = 0.0f;
void GetStrongestTwo() {
/* Work out the 2 most extreme values
if (happysad > 0){
sad is the strongest
}
if (happysad < 0){
sad is the strongest
}
Need to do this for all then work out the two that have the largest (either positive or negative value)
*/
}
我已经尝试过常量 if 语句,但是根据我对 max 和 min 的理解,应该有一个更简单的方法。我的尝试导致了 24 个 if 语句。另一种方法是将值分隔为以下内容。
public float happy = 0.0f;
public float sad = 0.0f;
public float passive = 0.0f;
public float agressive = 0.0f;
public float friend = 0.0f;
public float enemy = 0.0f;
public float weak = 0.0f;
public float strong = 0.0f;
我的问题是应对这一挑战的最佳方法是什么?如果存在编码方法并且我只需要更多研究,我将不胜感激朝着正确的方向推动,或者如果第二种解决方案更可行,那么我稍后会在我的代码中对其进行补偿。由于这些值是相反的,我宁愿只需要在每次发生影响情感元素的事件时添加或删除 1.0f 的值。
【问题讨论】: