Exemplo n.º 1
0
 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);
         }
     }
     );
 }
Exemplo n.º 2
0
 public void LeaveBattle(Battle battle)
 {
     isBattle = false;
 }
Exemplo n.º 3
0
 public void JoinBattle(Battle battle)
 {
     isBattle = true;
 }