我正在创建一个游戏,它具有基于成功百分比的犯罪功能。成功百分比随着玩家执行动作而增加。
现在,我根据成功和失败的操作生成随机百分比。但是,这会导致每次加载页面时百分比都会发生变化。有没有办法在行动完成后使这个百分比保持不变?
这是我的代码:
控制器:
private ViewModelCrime GetChances(UserGangster gangster) {
var cm = new ViewModelCrime();
for (int i = 1; i < 10; i++) {
cm.SelectedCrime = (ViewModelCrime.Crime)i;
double d6 = (cm.ChanceMultiplier * gangster.GansterStatistic.CrimesSuccess * (_rnd.Next(90, 105) / 100)) + ((cm.ChanceMultiplier * gangster.GansterStatistic.CrimesFailed / (_rnd.Next(380, 420) / 100)));
double finalD2 = LimitSuccesPercentage(cm.SelectedCrime, d6);
cm.SuccesPercentage.Add((ViewModelCrime.Crime)i, finalD2);
模型:
public double ChanceMultiplier {
get {
switch (SelectedCrime) {
case Crime.Crime01:
return 0.1;
case Crime.Crime02:
return 0.08;
case Crime.Crime03:
return 0.04;
case Crime.Crime04:
return 0.0035;
case Crime.Crime05:
return 0.0015;
case Crime.Crime06:
return 0.0008;
case Crime.Crime07:
return 0.0005;
case Crime.Crime08:
return 0.0002;
case Crime.Crime09:
return 0.0001;
default:
return 0.0001;
}
}
}
public Dictionary<Crime, double> SuccesPercentage{
get { return _succesPercentage; }
set { _succesPercentage = value; }
在视图中,我使用一行来显示 %
看法:
@string.Format("{0:P0}",Model.SuccesPercentage[(ViewModelCrime.Crime)9])
任何帮助表示赞赏!