public void Start(MainForm main_f)
        {
            UnSubscribe();
            Apples.Clear();
            Tanks.Clear();
            Obstacles.Clear();
            ShotsKolobok.Clear();
            ShotsTanks.Clear();
            kolobok       = null;
            gameOver      = false;
            Score         = 0;
            Delta         = 30;
            DeltaShots    = 30;
            map           = main_f.map;
            backgroundMap = new Bitmap(map.Width, map.Height);
            mapGraphics   = Graphics.FromImage(backgroundMap);
            mapGraphics.FillRectangle(Brushes.Black, 0, 0, map.Width, map.Height);
            for (int i = 0; i < mapFix.Count(); i++)
            {
                for (int j = 0; j < mapFix[i].Length; j++)
                {
                    if (mapFix[i][j] == 'X')
                    {
                        Obstacles.Add(new FixedObject(j, i, 0));
                        mapGraphics.DrawImage(Obstacles.Last().Img, Obstacles.Last().X *MainForm.sizeCell, Obstacles.Last().Y *MainForm.sizeCell, MainForm.sizeCell, MainForm.sizeCell);
                    }
                    if (mapFix[i][j] == 'Y')
                    {
                        Obstacles.Add(new FixedObject(j, i, 1));
                        mapGraphics.DrawImage(Obstacles.Last().Img, Obstacles.Last().X *MainForm.sizeCell, Obstacles.Last().Y *MainForm.sizeCell, MainForm.sizeCell, MainForm.sizeCell);
                    }
                }
            }

            RespOfApples();

            while (Tanks.Count < tanksCount)
            {
                Tanks.Add(new TankView());
                foreach (var item in Obstacles)
                {
                    if (Tanks.Last().Collide(item))
                    {
                        Tanks.RemoveAt(Tanks.Count - 1);
                        break;
                    }
                }
            }

            for (int i = 0; i < Apples.Count; i++)
            {
                mapGraphics.DrawImage(Apples[i].Img, Apples[i].X * MainForm.sizeCell, Apples[i].Y * MainForm.sizeCell, MainForm.sizeCell, MainForm.sizeCell);
            }

            for (int i = 0; i < Tanks.Count; i++)
            {
                mapGraphics.DrawImage(Tanks[i].Img, Tanks[i].X * MainForm.sizeCell, Tanks[i].Y * MainForm.sizeCell, MainForm.sizeCell, MainForm.sizeCell);
            }

            while (true)
            {
                kolobok = new KolobokView();
                if (!kolobok.CollideWithFixedObjects(Obstacles))
                {
                    break;
                }
            }

            Subscribe();
            mapGraphics.DrawImage(kolobok.Img, kolobok.X * MainForm.sizeCell, kolobok.Y * MainForm.sizeCell, MainForm.sizeCell, MainForm.sizeCell);
            map.Image = backgroundMap;
        }
예제 #2
0
        public void Start(TanksForm fm)
        {
            UnSubscribe();
            Apples.Clear();
            Tanks.Clear();
            Walls.Clear();
            ShotsKolobok.Clear();
            ShotsTanks.Clear();
            kolobok       = null;
            gameOver      = false;
            Score         = 0;
            Delta         = 30;
            DeltaShots    = 30;
            map           = fm.map;
            backgroundMap = new Bitmap(map.Width, map.Height);
            mapGraphics   = Graphics.FromImage(backgroundMap);
            mapGraphics.FillRectangle(Brushes.Black, 0, 0, map.Width, map.Height);
            for (int i = 0; i < example.Count(); i++)
            {
                for (int j = 0; j < example[i].Length; j++)
                {
                    if (example[i][j] == 'X')
                    {
                        Walls.Add(new Wall(j, i));
                        mapGraphics.DrawImage(Walls.Last().Img, Walls.Last().X *TanksForm.sizeCell, Walls.Last().Y *TanksForm.sizeCell, TanksForm.sizeCell, TanksForm.sizeCell);
                    }
                }
            }


            SpawnApples();

            while (Tanks.Count < tanksCount)
            {
                Tanks.Add(new Tank());
                foreach (var item in Walls)
                {
                    if (Tanks.Last().CollidesWith(item))
                    {
                        Tanks.RemoveAt(Tanks.Count - 1);
                        break;
                    }
                }
            }

            for (int i = 0; i < Apples.Count; i++)
            {
                mapGraphics.DrawImage(Apples[i].Img, Apples[i].X * TanksForm.sizeCell, Apples[i].Y * TanksForm.sizeCell, TanksForm.sizeCell, TanksForm.sizeCell);
            }

            for (int i = 0; i < Tanks.Count; i++)
            {
                mapGraphics.DrawImage(Tanks[i].Img, Tanks[i].X * TanksForm.sizeCell, Tanks[i].Y * TanksForm.sizeCell, TanksForm.sizeCell, TanksForm.sizeCell);
            }

            while (true)
            {
                kolobok = new Kolobok();
                if (!kolobok.CollidesWithWalls(Walls))
                {
                    break;
                }
            }

            Subscribe();
            mapGraphics.DrawImage(kolobok.Img, kolobok.X * TanksForm.sizeCell, kolobok.Y * TanksForm.sizeCell, TanksForm.sizeCell, TanksForm.sizeCell);
            map.Image = backgroundMap;
        }