Пример #1
0
        private async Task GetBestHeroes(List <HeroInfo> heroes, CancellationToken token)
        {
            await Task.Run(() =>
            {
                try
                {
                    if (token.IsCancellationRequested)
                    {
                        return;
                    }

                    foreach (PictureBox pic in bestHeroesPictures)
                    {
                        Invoke(new Action(() =>
                        {
                            bestHeroes.Controls.Remove(pic);
                        }));
                    }

                    HeroComparer comparer = new HeroComparer(enemies, GetWhichInfo());
                    heroes.Sort(comparer);
                    foreach (HeroInfo hero in heroes)
                    {
                        if (IsThereSuchEnemy(hero))
                        {
                            continue;
                        }
                        PictureBox pic = new PictureBox();
                        pic.Image      = hero.heroIcon;
                        pic.Size       = new Size(2 * pic.Image.Width / 5, 2 * pic.Image.Height / 5);
                        pic.SizeMode   = PictureBoxSizeMode.Zoom;
                        pic.Tag        = hero;
                        Invoke(new Action(() => {
                            ToolTip tip   = new ToolTip();
                            string values = "";
                            foreach (PictureBox enemy in enemies)
                            {
                                if (enemy is null || enemy.Tag is null)
                                {
                                    continue;
                                }
                                HeroInfo enemyInfo = enemy.Tag as HeroInfo;
                                values            += enemyInfo.heroName + ": " + hero.info[enemyInfo.heroName][GetWhichInfo()] + "\n";
                            }
                            tip.SetToolTip(pic, values);
                            ;                        bestHeroes.Controls.Add(pic);
                        }));
                        bestHeroesPictures.Add(pic);
                    }
                }
                catch (InvalidOperationException e)
                {
                    return;
                }
            });
        }
Пример #2
0
 void CreateHeroList(List <string> names, List <HeroInfo> heroes)
 {
     Task.Run(() => {
         semaphore.Wait();
         foreach (string name in names)
         {
             HeroInfo newHero = new HeroInfo(name);
             heroes.Add(newHero);
         }
         semaphore.Release();
     });
 }
Пример #3
0
        private bool IsThereSuchEnemy(HeroInfo hero)
        {
            bool passHero = false;

            foreach (PictureBox enemy in enemies)
            {
                if (passHero || enemy.Tag is null)
                {
                    break;
                }
                HeroInfo enemyInfo = enemy.Tag as HeroInfo;
                passHero = enemyInfo.heroName == hero.heroName;
            }

            return(passHero);
        }
Пример #4
0
 async Task LoadHeroesInfo(List <HeroInfo> heroes)
 {
     await Task.Run(() =>
     {
         foreach (string filename in Directory.GetFiles("heroes\\"))
         {
             IFormatter formatter = new BinaryFormatter();
             Stream stream        = new FileStream(filename, FileMode.Open,
                                                   FileAccess.Read);
             HeroInfo hero = formatter.Deserialize(stream) as HeroInfo;
             heroes.Add(hero);
             stream.Close();
             Debug.WriteLine(hero.heroName + " loading has been done");
         }
     });
 }