Ejemplo n.º 1
0
        protected override bool FaceTank(COORD NewPos)
        {
            COORD DimensionsLeftTop     = new COORD(NewPos.x - 2, NewPos.y - 2);
            COORD DimensionsRightBottom = new COORD(NewPos.x + 2, NewPos.y + 2);

            foreach (Tank element in Program.EnemyTanks)
            {
                foreach (COORD corner in element.Dimensions)
                {
                    if (corner.x >= DimensionsLeftTop.x && corner.x <= DimensionsRightBottom.x && corner.y >= DimensionsLeftTop.y && corner.y <= DimensionsRightBottom.y)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 2
0
 public override bool SetPosition(COORD NewPos)
 {
     if (!FaceBorder(NewPos))
     {
         if (!FaceWall(NewPos))
         {
             if (!FaceTank(NewPos))
             {
                 Position.x = NewPos.x;
                 Position.y = NewPos.y;
                 Dimensions = new COORD[] { new COORD(Position.x - 2, Position.y - 2), new COORD(Position.x + 2, Position.y + 2), new COORD(Position.x + 2, Position.y - 2), new COORD(Position.x - 2, Position.y + 2) };
                 return(true);
             }
         }
     }
     return(false);
 }
Ejemplo n.º 3
0
        protected virtual bool FaceTank()
        {
            lock (Program.ListLocker)
            {
                int counter = 0;
                switch (FriendOrFoe)
                {
                case 1:
                {
                    foreach (Tank element in Program.MyTanks)
                    {
                        COORD DimensionsLeftTop     = new COORD(element.GetPosition().x - 2, element.GetPosition().y - 2);
                        COORD DimensionsRightBottom = new COORD(element.GetPosition().x + 2, element.GetPosition().y + 2);
                        if (position.x >= DimensionsLeftTop.x && position.x <= DimensionsRightBottom.x && position.y >= DimensionsLeftTop.y && position.y <= DimensionsRightBottom.y)
                        {
                            element.Index = counter;
                            element.Hit();
                            //                                   SmallBoom Boom = new SmallBoom(direction, speed, ShotColor, position, FriendOrFoe);
                            return(true);
                        }
                        counter++;
                    }
                    break;
                }

                case 2:
                {
                    foreach (Tank element in Program.EnemyTanks)
                    {
                        COORD DimensionsLeftTop     = new COORD(element.GetPosition().x - 2, element.GetPosition().y - 2);
                        COORD DimensionsRightBottom = new COORD(element.GetPosition().x + 2, element.GetPosition().y + 2);
                        if (position.x >= DimensionsLeftTop.x && position.x <= DimensionsRightBottom.x && position.y >= DimensionsLeftTop.y && position.y <= DimensionsRightBottom.y)
                        {
                            element.Index = counter;
                            element.Hit();
                            //                                  SmallBoom Boom = new SmallBoom(direction, speed, ShotColor, position, FriendOrFoe);
                            return(true);
                        }
                        counter++;
                    }
                    break;
                }
                }
                return(false);
            }
        }
Ejemplo n.º 4
0
 public Tank(COORD StartPosition, int direction, int Armor)
 {
     CannotShoot = false;
     TankArmor   = Armor;
     Direction   = direction;
     if (StartPosition.x != 0)
     {
         Position = StartPosition;
     }
     else
     {
         do
         {
             SetPosition(Randomizer.RandomPosition());
         } while (Position == new COORD(0, 0));
     }
     Dimensions = new COORD[] { new COORD(Position.x - 2, Position.y - 2), new COORD(Position.x + 2, Position.y + 2), new COORD(Position.x + 2, Position.y - 2), new COORD(Position.x - 2, Position.y + 2) };
 }
Ejemplo n.º 5
0
        protected bool FaceTank(COORD coordinates)
        {
            lock (Program.ListLocker)
            {
                int counter = 0;
                switch (FriendOrFoe)
                {
                case 1:
                {
                    foreach (Tank element in Program.MyTanks)
                    {
                        COORD DimensionsLeftTop     = new COORD(element.GetPosition().x - 2, element.GetPosition().y - 2);
                        COORD DimensionsRightBottom = new COORD(element.GetPosition().x + 2, element.GetPosition().y + 2);
                        if (coordinates.x >= DimensionsLeftTop.x && coordinates.x <= DimensionsRightBottom.x && coordinates.y >= DimensionsLeftTop.y && coordinates.y <= DimensionsRightBottom.y)
                        {
                            element.Index = counter;
                            element.Hit();
                            return(true);
                        }
                        counter++;
                    }
                    break;
                }

                case 2:
                {
                    foreach (Tank element in Program.EnemyTanks)
                    {
                        COORD DimensionsLeftTop     = new COORD(element.GetPosition().x - 2, element.GetPosition().y - 2);
                        COORD DimensionsRightBottom = new COORD(element.GetPosition().x + 2, element.GetPosition().y + 2);
                        if (coordinates.x >= DimensionsLeftTop.x && coordinates.x <= DimensionsRightBottom.x && coordinates.y >= DimensionsLeftTop.y && coordinates.y <= DimensionsRightBottom.y)
                        {
                            element.Index = counter;
                            element.Hit();
                            return(true);
                        }
                        counter++;
                    }
                    break;
                }
                }
                return(false);
            }
        }
Ejemplo n.º 6
0
        protected override bool FaceTank(COORD NewPos)
        {
            lock (Program.ListLocker)
            {
                COORD DimensionsLeftTop     = new COORD(NewPos.x - 2, NewPos.y - 2);
                COORD DimensionsRightBottom = new COORD(NewPos.x + 2, NewPos.y + 2);

                int counter = 0;

                foreach (Tank element in Program.MyTanks)
                {
                    foreach (COORD corner in element.Dimensions)
                    {
                        if (corner.x >= DimensionsLeftTop.x && corner.x <= DimensionsRightBottom.x && corner.y >= DimensionsLeftTop.y && corner.y <= DimensionsRightBottom.y)
                        {
                            element.BlowUp();
                            Program.MyTanks.RemoveAt(0);
                            BlowUp();
                            Program.EnemyTanks.RemoveAt(Program.EnemyTanks.BinarySearch(this));
                            return(true);
                        }
                    }
                }

                foreach (Tank element in Program.EnemyTanks)
                {
                    foreach (COORD corner in element.Dimensions)
                    {
                        if (corner.x >= DimensionsLeftTop.x && corner.x <= DimensionsRightBottom.x && corner.y >= DimensionsLeftTop.y && corner.y <= DimensionsRightBottom.y)
                        {
                            counter++;
                            if (counter > 2)
                            {
                                return(true);
                            }
                        }
                    }
                }


                return(false);
            }
        }
Ejemplo n.º 7
0
 protected bool FaceWall(COORD NewPos)
 {
     lock (Program.ListLocker)
     {
         COORD DimensionsLeftTop     = new COORD(NewPos.x - 2, NewPos.y - 2);
         COORD DimensionsRightBottom = new COORD(NewPos.x + 2, NewPos.y + 2);
         foreach (Wall element in Program.Walls)
         {
             foreach (COORD corner in element.Dimensions)
             {
                 if (corner.x >= DimensionsLeftTop.x && corner.x <= DimensionsRightBottom.x && corner.y >= DimensionsLeftTop.y && corner.y <= DimensionsRightBottom.y)
                 {
                     return(true);
                 }
             }
         }
         return(false);
     }
 }
Ejemplo n.º 8
0
 protected bool FaceWall(COORD coordinates)
 {
     lock (Program.ListLocker)
     {
         int counter = 0;
         foreach (Wall element in Program.Walls)
         {
             COORD DimensionsLeftTop     = element.Dimensions[0];
             COORD DimensionsRightBottom = element.Dimensions[1];
             if (coordinates.x >= DimensionsLeftTop.x && coordinates.x <= DimensionsRightBottom.x && coordinates.y >= DimensionsLeftTop.y && coordinates.y <= DimensionsRightBottom.y)
             {
                 Program.Walls[counter].Erase();
                 Program.Walls.RemoveAt(counter);
                 return(true);
             }
             counter++;
         }
         return(false);
     }
 }
Ejemplo n.º 9
0
 protected virtual bool FaceWall()
 {
     lock (Program.ListLocker)
     {
         int counter = 0;
         foreach (Wall element in Program.Walls)
         {
             COORD DimensionsLeftTop     = element.Dimensions[0];
             COORD DimensionsRightBottom = element.Dimensions[1];
             if (position.x >= DimensionsLeftTop.x && position.x <= DimensionsRightBottom.x && position.y >= DimensionsLeftTop.y && position.y <= DimensionsRightBottom.y)
             {
                 Program.Walls[counter].Erase();
                 Program.Walls.RemoveAt(counter);
                 SmallBoom Boom = new SmallBoom(direction, speed, ShotColor, position, FriendOrFoe);
                 return(true);
             }
             counter++;
         }
         return(false);
     }
 }
Ejemplo n.º 10
0
 public Wall(int x, int y)
 {
     Position = new COORD(x, y);
     Draw();
 }
Ejemplo n.º 11
0
 public abstract bool SetPosition(COORD NewPos);
Ejemplo n.º 12
0
 protected abstract bool FaceTank(COORD NewPos);
Ejemplo n.º 13
0
        protected void BoomFly()
        {
            {
                if (Position.x != 0 && Position.y != 0)
                {
                    for (int i = -1; i < 2; i++)
                    {
                        for (int j = -1; j < 2; j++)
                        {
                            if (i == 0 && j == 0)
                            {
                                continue;
                            }
                            COORD Temp = new COORD(Position.x + i, Position.y + j);
                            if (!FaceBorder(Temp))
                            {
                                Coordinates[BoomRadius].Add(Temp);
                            }
                        }
                    }

                    FaceObstacle();
                    Draw();
                    Thread.Sleep(200);
                    BoomRadius++;
                    Coordinates.Add(new List <COORD>());
                    for (int i = -2; i <= 2; i++)
                    {
                        COORD Temp1 = new COORD(Position.x + i, Position.y - 2);
                        if (!FaceBorder(Temp1))
                        {
                            Coordinates[BoomRadius].Add(Temp1);
                        }
                        COORD Temp2 = new COORD(Position.x + i, Position.y + 2);
                        if (!FaceBorder(Temp2))
                        {
                            Coordinates[BoomRadius].Add(Temp2);
                        }
                    }
                    for (int j = -1; j < 2; j++)
                    {
                        COORD Temp1 = new COORD(Position.x - 2, Position.y + j);
                        if (!FaceBorder(Temp1))
                        {
                            Coordinates[BoomRadius].Add(Temp1);
                        }
                        COORD Temp2 = new COORD(Position.x + 2, Position.y + j);
                        if (!FaceBorder(Temp2))
                        {
                            Coordinates[BoomRadius].Add(Temp2);
                        }
                    }

                    FaceObstacle();
                    Draw();
                    Erase();
                    Thread.Sleep(200);
                    BoomRadius++;
                    Coordinates.Add(new List <COORD>());

                    for (int i = -3; i <= 3; i++)
                    {
                        COORD Temp1 = new COORD(Position.x + i, Position.y - 3);
                        if (!FaceBorder(Temp1))
                        {
                            Coordinates[BoomRadius].Add(Temp1);
                        }
                        COORD Temp2 = new COORD(Position.x + i, Position.y + 3);
                        if (!FaceBorder(Temp2))
                        {
                            Coordinates[BoomRadius].Add(Temp2);
                        }
                    }


                    for (int j = -2; j <= 2; j++)
                    {
                        COORD Temp1 = new COORD(Position.x - 3, Position.y + j);
                        if (!FaceBorder(Temp1))
                        {
                            Coordinates[BoomRadius].Add(Temp1);
                        }
                        COORD Temp2 = new COORD(Position.x + 3, Position.y + j);
                        if (!FaceBorder(Temp2))
                        {
                            Coordinates[BoomRadius].Add(Temp2);
                        }
                    }

                    FaceObstacle();
                    Draw();
                    Erase();
                    Thread.Sleep(400);
                    EraseAll();
                    BoomThread.Abort();
                }
                else
                {
                    BoomThread.Abort();
                }
            }
        }
Ejemplo n.º 14
0
 public static void WallBuilder(COORD start, COORD end)
 {
     if (start.x == end.x)
     {
         if (start.y < end.y)
         {
             for (int i = start.y; i <= end.y; i += size)
             {
                 Program.Walls.Add(new Wall(start.x, i));
             }
         }
         else
         {
             for (int i = start.y; i >= end.y; i -= size)
             {
                 Program.Walls.Add(new Wall(start.x, i));
             }
         }
     }
     else if (start.y == end.y)
     {
         if (start.x < end.x)
         {
             for (int i = start.x; i <= end.x; i += size)
             {
                 Program.Walls.Add(new Wall(i, start.y));
             }
         }
         else
         {
             for (int i = start.x; i >= end.x; i -= size)
             {
                 Program.Walls.Add(new Wall(i, start.y));
             }
         }
     }
     else
     {
         if (start.x < end.x)
         {
             if (start.y < end.y)
             {
                 for (int i = start.x, j = start.y; i <= end.x || j <= end.y; i += size, j += size)
                 {
                     Program.Walls.Add(new Wall(i, j));
                 }
             }
             else
             {
                 for (int i = start.x, j = start.y; i <= end.x || j >= end.y; i += size, j -= size)
                 {
                     Program.Walls.Add(new Wall(i, j));
                 }
             }
         }
         else
         {
             if (start.y < end.y)
             {
                 for (int i = start.x, j = start.y; i >= end.x || j <= end.y; i -= size, j += size)
                 {
                     Program.Walls.Add(new Wall(i, j));
                 }
             }
             else
             {
                 for (int i = start.x, j = start.y; i >= end.x || j >= end.y; i -= size, j -= size)
                 {
                     Program.Walls.Add(new Wall(i, j));
                 }
             }
         }
     }
 }
Ejemplo n.º 15
0
        public static COORD RandomPosition()
        {
            COORD Position = new COORD(randomizer.Next(3, Field.FieldWIDTH - 5), randomizer.Next(3, Field.FieldHEIGHT - 30));

            return(Position);
        }
Ejemplo n.º 16
0
 public MyRocket(int Direction, int Speed, ConsoleColor Color, COORD TankPosition, int FoeIdentification)
     : base(Direction, Speed, Color, TankPosition, FoeIdentification)
 {
     sign = '@';
 }
Ejemplo n.º 17
0
 public Rocket(int Direction, int Speed, ConsoleColor Color, COORD TankPosition, int FoeIdentification) : base(Direction, Speed, Color, TankPosition, FoeIdentification)
 {
     WatchRadius = 15;
     sign        = '@';
 }