예제 #1
0
파일: Sim.cs 프로젝트: hrhtspr/SplatoonSim
 public void SearchBattle()
 {
     var opt = new ParallelOptions();
     opt.MaxDegreeOfParallelism = 4;
     Parallel.ForEach(Players.Where(p => !p.isBattle).OrderBy(p=>GB.Random.NextDouble()).ToList(), opt, () => new List<Battle>(), (player, pls, battles) =>
     {
         if (Battles.Find(p => p != null && p.CanJoin(player.Udemae) && p.Join(player)) == null)
         {
             if (battles.Find(p => p != null && p.CanJoin(player.Udemae) && p.Join(player)) == null)
             {
                 var battle = new Battle(player.Udemae);
                 lock (this)
                 {
                     battles.Add(battle);
                     battle.Join(player);
                 }
             }
         }
         return battles;
     }
     ,
     (battles) =>
     {
         lock (this)
         {
             Battles.AddRange(battles);
         }
     }
     );
 }
예제 #2
0
 public void LeaveBattle(Battle battle)
 {
     isBattle = false;
 }
예제 #3
0
 public void JoinBattle(Battle battle)
 {
     isBattle = true;
 }