예제 #1
0
 public Index this[int index]
 {
     get
     {
         ThrowIfIndicesExceedDimensions(index);
         return(Indices.ElementAt(index));
     }
 }
예제 #2
0
        public static void Step(DMEnv env)
        {
            var horses   = env.Sce.Horses;
            var scenario = env.Sce;

            if (horses.Count == 0)
            {
                env.Next = "🏇还未开始!";
                return;
            }
            HashSet <int> winners = new HashSet <int>();

            for (int i = 0; i < horses.Count; i++)
            {
                if (horses[i].Step())
                {
                    winners.Add(i);
                }
            }
            env.Append(DisplayHorses(horses));
            if (winners.Count > 0)
            {
                env.LineAppend("赢家:");
                Dictionary <string, int> profits = new Dictionary <string, int>();
                foreach (int index in winners)
                {
                    env.Append(Indices.ElementAt(index));
                    double bonus = BonusMin + Horse.Rand.NextDouble() * (BonusMax - BonusMin);
                    foreach (var e in horses[index].Bets)
                    {
                        profits[e.Key] = (int)(e.Value * bonus) + (profits.ContainsKey(e.Key) ? profits[e.Key] : 0);
                    }
                }
                env.AppendLine("号🐎。");
                foreach (var e in profits)
                {
                    if (scenario.TryGetInvestigator(e.Key, out Investigator inv))
                    {
                        if (!inv.Values.TryWidelyGet("账户", out Value account))
                        {
                            account = new Value(0);
                            inv.Values.Put("账户", account);
                        }
                        env.AppendLine(inv.Change("账户", e.Value));
                    }
                    else
                    {
                        env.AppendLine($"未找到【{e.Key}】,很遗憾,他的奖金全没了");
                    }
                }
                horses.Clear();
                env.Append("🏇已结束!");
            }
            env.Save();
        }