Пример #1
0
        public CanBeInsertedInfo CanBeInserted(int x, int y, DetailData detail)
        {
            // Если колес уже два нельзя вставить больше
            if (detail.type == DetailType.Wheel && m_counts[DetailType.Wheel] >= 3)
            {
                return(CanBeInsertedInfo.ToMuchWheels);
            }

            // Двигатель только один
            if (detail.type == DetailType.Engine && m_counts[DetailType.Engine] >= 1)
            {
                return(CanBeInsertedInfo.ToMuchEngines);
            }

            foreach (var inserted in m_details)
            {
                if (x == inserted.x + 1 && y == inserted.y && x >= 0 && x < Width ||
                    x == inserted.x - 1 && y == inserted.y && x >= 0 && x < Width ||
                    y == inserted.y - 1 && x == inserted.x && y >= 0 && y < Height ||
                    y == inserted.y + 1 && x == inserted.x && y >= 0 && y < Height)
                {
                    return(inserted.detail.type == DetailType.Block ?
                           CanBeInsertedInfo.YesNoProblem : CanBeInsertedInfo.InvalidPosition);
                }
            }
            return(CanBeInsertedInfo.InvalidPosition);
        }
Пример #2
0
 public CDetail(DetailData data)
 {
     title    = data.title;
     sprite   = data.sprite;
     type     = data.type;
     mass     = data.mass;
     speed    = data.speed;
     fuelCap  = data.fuelCap;
     fuelCons = data.fuelCons;
 }
Пример #3
0
        public List <Vector2Int> GetAvailablePositionsForInsertion(DetailData detail)
        {
            if (detail.type == DetailType.Wheel && m_wheelsCount < 2)
            {
                return(new List <Vector2Int>()
                {
                    new Vector2Int(1, 3),
                    new Vector2Int(7, 3)
                });
            }

            if (detail.type == DetailType.Engine)
            {
                return(new List <Vector2Int>()
                {
                    new Vector2Int(6, 0)
                });
            }

            if (detail.type == DetailType.FuelBank)
            {
                return(new List <Vector2Int>()
                {
                    new Vector2Int(2, 0)
                });
            }

            List <Vector2Int> positions = new List <Vector2Int>();

            for (int i = 0; i < Height; ++i)
            {
                for (int j = 0; j < Width; ++j)
                {
                    if (CanBeInserted(j, i, detail) == CanBeInsertedInfo.YesNoProblem)
                    {
                        positions.Add(new Vector2Int(j, i));
                    }
                }
            }
            return(positions);
        }
Пример #4
0
 public void InsertDetail(int x, int y, DetailData detail)
 {
     m_details.Add(new GridItem(x, y, detail));
     UpdateDetailsCount();
 }
Пример #5
0
 public GridItem(int x, int y, DetailData detail)
 {
     this.x      = x;
     this.y      = y;
     this.detail = detail;
 }