我正在编写一款游戏,每年之后,根据结果,角色的属性都会发生变化。该游戏是一个电影业务模拟器,下面是我现在使用的丑陋代码示例:
if (movie.Reviews.Avg > 8.5f)
{
movie.Producer.Reputation += 6f / movie.Producer.Reputation;
return;
}
else if (movie.Reviews.Avg > 7.5f)
{
movie.Producer.Reputation += 5f / movie.Producer.Reputation;
return;
}
else if (movie.Reviews.Avg > 6.5f)
{
movie.Producer.Reputation += 4f / movie.Producer.Reputation;
return;
}
else if (movie.Reviews.Avg > 5)
{
movie.Producer.Reputation += 1f / movie.Producer.Reputation;
return;
}
else if (movie.Reviews.Avg > 4.5)
{
return;
}
else if (movie.Reviews.Avg > 4)
{
movie.Producer.Reputation -= movie.Producer.Reputation / 6f;
return;
}
else if (movie.Reviews.Avg > 3)
{
movie.Producer.Reputation -= movie.Producer.Reputation / 5f;
return;
}
else if (movie.Reviews.Avg > 2)
{
movie.Producer.Reputation -= movie.Producer.Reputation / 4f;
return;
}
else
{
movie.Producer.Reputation -= movie.Producer.Reputation / 3f;
return;
}
此代码的几个问题:
信誉气球。优秀的AI制片人可以做出明智的选择,使他们的电影获得好评,声誉也更高。
因为声誉不断增长,所以属性的绝对变化变得越来越小,而晋升级别又变得越来越缓慢和困难。
我从功能中看到的是什么
答案 0 :(得分:0)
尝试以下操作:
KeyValuePair<float, float>[] average = {
new KeyValuePair<float,float>(2,-3f),
new KeyValuePair<float,float>(3,-4f),
new KeyValuePair<float,float>(4,-5f),
new KeyValuePair<float,float>(4.5f,-6f),
new KeyValuePair<float,float>(5,0),
new KeyValuePair<float,float>(6.5f,1f),
new KeyValuePair<float,float>(7.5f,4f),
new KeyValuePair<float,float>(8.5f,5f),
};
float reputation = 123;
float review = 3.3f;
reputation += average.Where(x => review > x.Key).Select(x => (x.Value == 0) ? 0 : reputation / x.Value).FirstOrDefault();