public void CreateShotTank(MovingObject sender)
        {
            switch (sender.MovementDirection)
            {
            case (int)Direction.DOWN:
            {
                ShotsTanks.Add(new ShotView(sender.X, sender.Y + 1, sender.MovementDirection, sender));
                break;
            }

            case (int)Direction.LEFT:
            {
                ShotsTanks.Add(new ShotView(sender.X - 1, sender.Y, sender.MovementDirection, sender));
                break;
            }

            case (int)Direction.RIGHT:
            {
                ShotsTanks.Add(new ShotView(sender.X + 1, sender.Y, sender.MovementDirection, sender));
                break;
            }

            case (int)Direction.UP:
            {
                ShotsTanks.Add(new ShotView(sender.X, sender.Y - 1, sender.MovementDirection, sender));
                break;
            }

            default:
                break;
            }

            var index = ShotsTanks.Last().InteractWithFixedObjects(Obstacles);

            if (index > 0)
            {
                mapGraphics.FillRectangle(Brushes.Black, Obstacles[index].X * MainForm.sizeCell, Obstacles[index].Y * MainForm.sizeCell, MainForm.sizeCell, MainForm.sizeCell);
                Obstacles.RemoveAt(index);
                ShotsTanks.RemoveAt(ShotsTanks.Count - 1);
            }
        }
Esempio n. 2
0
        public void CreateShotTank(MovebleObj sender)
        {
            switch (sender.DirectionTo)
            {
            case (int)Direction.Down:
            {
                ShotsTanks.Add(new Shot(sender.X, sender.Y + 1, sender.DirectionTo, sender));
                break;
            }

            case (int)Direction.Left:
            {
                ShotsTanks.Add(new Shot(sender.X - 1, sender.Y, sender.DirectionTo, sender));
                break;
            }

            case (int)Direction.Right:
            {
                ShotsTanks.Add(new Shot(sender.X + 1, sender.Y, sender.DirectionTo, sender));
                break;
            }

            case (int)Direction.Up:
            {
                ShotsTanks.Add(new Shot(sender.X, sender.Y - 1, sender.DirectionTo, sender));
                break;
            }

            default:
                break;
            }
            if (ShotsTanks.Last().CollidesWithWalls(Walls))
            {
                ShotsTanks.RemoveAt(ShotsTanks.Count - 1);
            }
        }
        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;
        }
        public void StepOfShots()
        {
            while (DeltaShots != MainForm.sizeCell + 5)
            {
                for (int i = 0; i < ShotsKolobok.Count; i++)
                {
                    Move(ShotsKolobok[i], DeltaShots);
                }

                for (int i = 0; i < ShotsTanks.Count; i++)
                {
                    Move(ShotsTanks[i], DeltaShots);
                }

                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 < Obstacles.Count; i++)
                {
                    if (Obstacles[i].Ability == 1)
                    {
                        mapGraphics.DrawImage(Obstacles[i].Img, Obstacles[i].X * MainForm.sizeCell, Obstacles[i].Y * MainForm.sizeCell, MainForm.sizeCell, MainForm.sizeCell);
                    }
                }

                DeltaShots += 5;
                map.Image   = backgroundMap;
                return;
            }


            DeltaShots = 5;

            for (int j = 0; j < ShotsTanks.Count; j++)
            {
                if (kolobok.Collide(ShotsTanks[j]))
                {
                    gameOver = true;
                    break;
                }
            }

            for (int i = 0; i < Tanks.Count; i++)
            {
                for (int j = 0; j < ShotsKolobok.Count; j++)
                {
                    if (Tanks[i].Collide(ShotsKolobok[j]))
                    {
                        mapGraphics.FillRectangle(Brushes.Black, Tanks[i].PrevX * MainForm.sizeCell, Tanks[i].PrevY * MainForm.sizeCell, MainForm.sizeCell, MainForm.sizeCell);
                        mapGraphics.FillRectangle(Brushes.Black, ShotsKolobok[j].X * MainForm.sizeCell, ShotsKolobok[j].Y * MainForm.sizeCell, MainForm.sizeCell, MainForm.sizeCell);
                        mapGraphics.FillRectangle(Brushes.Black, Tanks[i].X * MainForm.sizeCell, Tanks[i].Y * MainForm.sizeCell, MainForm.sizeCell, MainForm.sizeCell);
                        mapGraphics.FillRectangle(Brushes.Black, ShotsKolobok[j].PrevX * MainForm.sizeCell, ShotsKolobok[j].PrevY * MainForm.sizeCell, MainForm.sizeCell, MainForm.sizeCell);
                        Tanks.RemoveAt(i);
                        ShotsKolobok.RemoveAt(j);
                        i--;
                        j--;
                        break;
                    }
                }
            }


            for (int i = 0; i < ShotsKolobok.Count; i++)
            {
                ShotsKolobok[i].Move();
                var index = ShotsKolobok[i].InteractWithFixedObjects(Obstacles);
                if (index > 0)
                {
                    mapGraphics.FillRectangle(Brushes.Black, ShotsKolobok[i].PrevX * MainForm.sizeCell, ShotsKolobok[i].PrevY * MainForm.sizeCell, MainForm.sizeCell, MainForm.sizeCell);
                    mapGraphics.FillRectangle(Brushes.Black, Obstacles[index].X * MainForm.sizeCell, Obstacles[index].Y * MainForm.sizeCell, MainForm.sizeCell, MainForm.sizeCell);
                    Obstacles.RemoveAt(index);
                    ShotsKolobok.RemoveAt(i);
                }
            }

            for (int i = 0; i < ShotsTanks.Count; i++)
            {
                ShotsTanks[i].Move();

                /*if (ShotsTanks[i].CollideWithFixedObjects(Obstacles))
                 * {
                 *  mapGraphics.FillRectangle(Brushes.Black, ShotsTanks[i].PrevX * MainForm.sizeCell, ShotsTanks[i].PrevY * MainForm.sizeCell, MainForm.sizeCell, MainForm.sizeCell);
                 *  ShotsTanks.RemoveAt(i);
                 *  i--;
                 *  continue;
                 * }*/
                var index = ShotsTanks[i].InteractWithFixedObjects(Obstacles);
                if (index > 0)
                {
                    mapGraphics.FillRectangle(Brushes.Black, ShotsTanks[i].PrevX * MainForm.sizeCell, ShotsTanks[i].PrevY * MainForm.sizeCell, MainForm.sizeCell, MainForm.sizeCell);
                    mapGraphics.FillRectangle(Brushes.Black, Obstacles[index].X * MainForm.sizeCell, Obstacles[index].Y * MainForm.sizeCell, MainForm.sizeCell, MainForm.sizeCell);
                    Obstacles.RemoveAt(index);
                    ShotsTanks.RemoveAt(i);
                    i--;
                    continue;
                }
                if (kolobok.Collide(ShotsTanks[i]))
                {
                    gameOver = true;
                    break;
                }
            }


            for (int i = 0; i < Tanks.Count; i++)
            {
                for (int j = 0; j < ShotsKolobok.Count; j++)
                {
                    if (Tanks[i].Collide(ShotsKolobok[j]))
                    {
                        mapGraphics.FillRectangle(Brushes.Black, Tanks[i].PrevX * MainForm.sizeCell, Tanks[i].PrevY * MainForm.sizeCell, MainForm.sizeCell, MainForm.sizeCell);
                        mapGraphics.FillRectangle(Brushes.Black, ShotsKolobok[j].X * MainForm.sizeCell, ShotsKolobok[j].Y * MainForm.sizeCell, MainForm.sizeCell, MainForm.sizeCell);
                        mapGraphics.FillRectangle(Brushes.Black, Tanks[i].X * MainForm.sizeCell, Tanks[i].Y * MainForm.sizeCell, MainForm.sizeCell, MainForm.sizeCell);
                        mapGraphics.FillRectangle(Brushes.Black, ShotsKolobok[j].PrevX * MainForm.sizeCell, ShotsKolobok[j].PrevY * MainForm.sizeCell, MainForm.sizeCell, MainForm.sizeCell);
                        Tanks.RemoveAt(i);
                        ShotsKolobok.RemoveAt(j);
                        i--;
                        j--;
                        break;
                    }
                }
            }



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

            RespOfApples();
            DeltaShots += 5;
            map.Image   = backgroundMap;
        }
Esempio n. 5
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;
        }
Esempio n. 6
0
        public void StepOfShots()
        {
            while (DeltaShots != TanksForm.sizeCell + 5)
            {
                for (int i = 0; i < ShotsKolobok.Count; i++)
                {
                    Move(ShotsKolobok[i], DeltaShots);
                }

                for (int i = 0; i < ShotsTanks.Count; i++)
                {
                    Move(ShotsTanks[i], DeltaShots);
                }



                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);
                }

                DeltaShots += 5;
                map.Image   = backgroundMap;
                return;
            }


            DeltaShots = 5;



            for (int j = 0; j < ShotsTanks.Count; j++)
            {
                if (kolobok.CollidesWith(ShotsTanks[j]))
                {
                    gameOver = true;
                    break;
                }
            }

            for (int i = 0; i < Tanks.Count; i++)
            {
                for (int j = 0; j < ShotsKolobok.Count; j++)
                {
                    if (Tanks[i].CollidesWith(ShotsKolobok[j]))
                    {
                        mapGraphics.FillRectangle(Brushes.Black, Tanks[i].OldX * TanksForm.sizeCell, Tanks[i].OldY * TanksForm.sizeCell, TanksForm.sizeCell, TanksForm.sizeCell);
                        mapGraphics.FillRectangle(Brushes.Black, ShotsKolobok[j].X * TanksForm.sizeCell, ShotsKolobok[j].Y * TanksForm.sizeCell, TanksForm.sizeCell, TanksForm.sizeCell);
                        mapGraphics.FillRectangle(Brushes.Black, Tanks[i].X * TanksForm.sizeCell, Tanks[i].Y * TanksForm.sizeCell, TanksForm.sizeCell, TanksForm.sizeCell);
                        mapGraphics.FillRectangle(Brushes.Black, ShotsKolobok[j].OldX * TanksForm.sizeCell, ShotsKolobok[j].OldY * TanksForm.sizeCell, TanksForm.sizeCell, TanksForm.sizeCell);
                        Tanks.RemoveAt(i);
                        ShotsKolobok.RemoveAt(j);
                        i--;
                        j--;
                        break;
                    }
                }
            }


            for (int i = 0; i < ShotsKolobok.Count; i++)
            {
                ShotsKolobok[i].Move();
                if (ShotsKolobok[i].CollidesWithWalls(Walls))
                {
                    mapGraphics.FillRectangle(Brushes.Black, ShotsKolobok[i].OldX * TanksForm.sizeCell, ShotsKolobok[i].OldY * TanksForm.sizeCell, TanksForm.sizeCell, TanksForm.sizeCell);
                    ShotsKolobok.RemoveAt(i);
                    i--;
                }
            }

            for (int i = 0; i < ShotsTanks.Count; i++)
            {
                ShotsTanks[i].Move();
                if (ShotsTanks[i].CollidesWithWalls(Walls))
                {
                    mapGraphics.FillRectangle(Brushes.Black, ShotsTanks[i].OldX * TanksForm.sizeCell, ShotsTanks[i].OldY * TanksForm.sizeCell, TanksForm.sizeCell, TanksForm.sizeCell);
                    ShotsTanks.RemoveAt(i);
                    i--;
                    continue;
                }
                if (kolobok.CollidesWith(ShotsTanks[i]))
                {
                    gameOver = true;
                    break;
                }
            }


            for (int i = 0; i < Tanks.Count; i++)
            {
                for (int j = 0; j < ShotsKolobok.Count; j++)
                {
                    if (Tanks[i].CollidesWith(ShotsKolobok[j]))
                    {
                        mapGraphics.FillRectangle(Brushes.Black, Tanks[i].OldX * TanksForm.sizeCell, Tanks[i].OldY * TanksForm.sizeCell, TanksForm.sizeCell, TanksForm.sizeCell);
                        mapGraphics.FillRectangle(Brushes.Black, ShotsKolobok[j].X * TanksForm.sizeCell, ShotsKolobok[j].Y * TanksForm.sizeCell, TanksForm.sizeCell, TanksForm.sizeCell);
                        mapGraphics.FillRectangle(Brushes.Black, Tanks[i].X * TanksForm.sizeCell, Tanks[i].Y * TanksForm.sizeCell, TanksForm.sizeCell, TanksForm.sizeCell);
                        mapGraphics.FillRectangle(Brushes.Black, ShotsKolobok[j].OldX * TanksForm.sizeCell, ShotsKolobok[j].OldY * TanksForm.sizeCell, TanksForm.sizeCell, TanksForm.sizeCell);
                        Tanks.RemoveAt(i);
                        ShotsKolobok.RemoveAt(j);
                        i--;
                        j--;
                        break;
                    }
                }
            }



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

            SpawnApples();
            DeltaShots += 5;
            map.Image   = backgroundMap;
        }