Exemple #1
0
        private bool check_for_enemy()
        {
            get_our_tank_location();
            int   x         = our_tank_location[0];
            int   y         = our_tank_location[1];
            Block our_tank  = blocks[x, y]; // our tank
            int   direction = our_tank.get_direction();

            if (direction == 0) // up
            {
                for (int i = y - 1; i > -1; i--)
                {
                    Block enemy = blocks[x, i];
                    if (enemy.get_type() == 6 || enemy.get_type() == 1) // if it is a tank or brick
                    {
                        return(true);
                    }
                }
            }
            else if (direction == 2) // down
            {
                for (int i = y + 1; i < grid_size; i++)
                {
                    Block enemy = blocks[x, i];
                    if (enemy.get_type() == 6 || enemy.get_type() == 1) // if it is a tank or brick
                    {
                        return(true);
                    }
                }
            }
            else if (direction == 1) // right
            {
                for (int i = x + 1; i < grid_size; i++)
                {
                    Block enemy = blocks[i, y];
                    if (enemy.get_type() == 6 || enemy.get_type() == 1) // if it is a tank or brick
                    {
                        return(true);
                    }
                }
            }
            else // left
            {
                for (int i = x - 1; i >= 0; i--)
                {
                    Block enemy = blocks[i, y];
                    if (enemy.get_type() == 6 || enemy.get_type() == 1) // if it is a tank or brick
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }