Exemple #1
0
        public void StartWorld()
        {
            string[,] usedBitmaps = new string[, ]
            {
                { "okun.bmp", "okun_dead.bmp" },
                { "chuka.bmp", "chuka_dead.bmp" },
                { "fish_xz.bmp", "fish_xz_dead.bmp" },
                { "worm.bmp", "worm.bmp" },
                { "cat.bmp", "cat.bmp" },
                { "cleaner.bmp", "cleaner.bmp" }
            };

            bitmapsCount = usedBitmaps.Length / 2;
            LoadImages(usedBitmaps);

            fishPredCount = 0;
            fishHerbCount = 0;

            string[] ratioStr = ratioText.Split(new char[] { '/' });

            int i = 0;

            foreach (string s in ratioStr)
            {
                ratio[i] = Convert.ToInt32(s);
                i++;
            }

            fishCount = ratio[0] + ratio[1];
            worldArr  = new List <Entity>();

            fieldPB.Image = new Bitmap(fieldPB.Width, fieldPB.Height);
            graphics      = Graphics.FromImage(fieldPB.Image);
            CreateGround();

            random = new Random();

            cat     = new Cat(Bitmaps.GetRow(4)[0], random);
            cleaner = new Cleaner(Bitmaps.GetRow(5)[0], random);

            i = 0;
            int x, y;
            int lastX = 0;
            int lastY = 50;

            while (i < ratio[0])
            {
                x = (lastX + Width + MAX_FISH_WIDTH) % Width;
                y = lastY;
                if (x + MAX_FISH_WIDTH >= Width)
                {
                    y = (y + MAX_FISH_HEIGHT + Height) % Height;
                }
                lastX = x;
                lastY = y;
                PredFish fish = new PredFish(x, y, Bitmaps.GetRow(1), this, 100, 30, random);
                worldArr.Add(fish);
                fish.DieEvent     += cleaner.FishDied;
                fish.OnTheSurface += cat.Stealing;
                fishPredCount++;
                i++;
            }

            while (i < fishCount)
            {
                x = (lastX + Width + MAX_FISH_WIDTH) % Width;
                y = lastY;
                if (x + MAX_FISH_WIDTH >= Width)
                {
                    y = (y + MAX_FISH_HEIGHT + Height) % Height;
                }
                lastX = x;
                lastY = y;
                HerbFish fish;
                if (random.Next(2) == 0)
                {
                    fish = new HerbFish(x, y, Bitmaps.GetRow(0), this, 60, 30, random);
                }
                else
                {
                    fish = new HerbFish(x, y, Bitmaps.GetRow(2), this, 70, 35, random);
                }
                worldArr.Add(fish);
                fish.DieEvent     += cleaner.FishDied;
                fish.OnTheSurface += cat.Stealing;
                fishHerbCount++;
                i++;
            }

            /*PredFish fish = new PredFish(100, 100, Bitmaps.GetRow(1), random);
             * worldArr.Add(fish);
             * HerbFish fishs = new HerbFish(200, 200, Bitmaps.GetRow(0), random);
             * worldArr.Add(fishs);
             * PredFish fishhh = new PredFish(300, 300, Bitmaps.GetRow(1), random);
             * worldArr.Add(fishhh);
             * HerbFish fishshh = new HerbFish(400, 400, Bitmaps.GetRow(0), random);
             * worldArr.Add(fishshh);*/
        }