Example #1
0
        public bool CanTankMove(Tank tank, List<Tank> enemies, Directions direction)
        {
            NewPosition newTankPosition = new NewPosition(tank, direction);
            bool collides = false;

            if (newTankPosition.Row >= 2 && newTankPosition.Row < Data.GetWindowHeight() - 4 &&
                newTankPosition.Column >= 0 && newTankPosition.Column < Data.GetWindowWidth() - 3)
            {
                collides = true;
            }

            for (int elemRow = 0; elemRow < mapElements.GetLength(0); elemRow++)
            {
                for (int elemCol = 0; elemCol < mapElements.GetLength(1); elemCol++)
                {
                    if (mapElements[elemRow, elemCol] != null)
                    {
                        if (DoesItCollideTank(mapElements[elemRow, elemCol], tank, newTankPosition.Row, newTankPosition.Column))
                        {
                            collides = false;
                        }
                    }
                }
            }

            if (collides)
            {
                collides = TankIsOnAtherTank(tank, enemies, newTankPosition);
            }

            return collides;
        }
Example #2
0
 private bool TankIsOnAtherTank(Tank tank, List<Tank> enemies, NewPosition newTankPosition)
 {
     bool collides = true;
     for (int i = 0; i < enemies.Count; i++)
     {
         if (tank.TankNumber != enemies[i].TankNumber)
         {
             if (IsTankColaidsAtherTank(newTankPosition, enemies[i]))
             {
                 collides = false;
                 break;
             }
         }
     }
     return collides;
 }
Example #3
0
 private static bool IsMisaleHitTank(Tank player, NewPosition newFirePosition)
 {
     return newFirePosition.Row >= player.CurrentRow &&
                             newFirePosition.Row <= (player.CurrentRow + Data.GetElementDimention() - 1) &&
                             newFirePosition.Column >= player.CurrentCol &&
                             newFirePosition.Column <= (player.CurrentCol + Data.GetElementDimention() - 1);
 }
Example #4
0
        private bool IsTankColaidsAtherTank(NewPosition newTankPosition, Tank tank)
        {
            for (int row = newTankPosition.Row; row < newTankPosition.Row + Data.GetElementDimention(); row++)
            {
                for (int col = newTankPosition.Column; col < newTankPosition.Column + Data.GetElementDimention(); col++)
                {
                    if (row >= tank.CurrentRow && row < tank.CurrentRow + tank.Dimention &&
                        col >= tank.CurrentCol && col < tank.CurrentCol + tank.Dimention)
                    {
                        return true;
                    }
                }
            }

            return false;
        }
Example #5
0
        public bool HaveShotCollision(Fire fire, Tank player, List<Tank> enemies)
        {
            // if have collision return true
            // else return false - misale continue move

            // Gencho make simple collision

            NewPosition newFirePosition = new NewPosition(fire);
            if (!CanFireMove(newFirePosition.Row, newFirePosition.Column))
            {
                return true;
            }

            if (newFirePosition.Row >= 2 && newFirePosition.Row < Data.GetWindowHeight() - 2 &&
                newFirePosition.Column >= 0 && newFirePosition.Column < Data.GetWindowWidth() - 1)
            {
                // enemy fire
                if (!fire.IsPlayerFire)
                {
                    if (IsMisaleHitTank(player, newFirePosition))
                    {
                        player.IsHited = true;
                        return true;
                    }
                }
                else
                {
                    bool haveHit = false;
                    for (int i = 0; i < enemies.Count; i++)
                    {
                        if (IsMisaleHitTank(enemies[i], newFirePosition))
                        {
                            enemies[i].IsHited = true;
                            haveHit = true;
                        }
                    }

                    if (haveHit)
                    {
                        return true;
                    }
                }

                return false;
            }

            return true;

            //if (IsFireAgainstEnemy(fire))
            //{
            //}
            //if (IsFireAgainstPlayer(fire))
            //{
            //}
            //if (IsFireAgainstTerain(fire))
            //{
            //}
        }