Esempio n. 1
0
    // void nextFigure()

    void Update()
    {
        bool hasBlocksInInputArea = GameObject.FindGameObjectsWithTag("Block")
                                    .Any(o => o.transform.parent.parent == figures && // ~= is it visible
                                         o.transform.position.x >= 0 && o.transform.position.x < levelHoleSize &&
                                         o.transform.position.y >= levelHeight && o.transform.position.y < levelHeight + levelHoleSize + 1);

        if (!hasBlocksInInputArea && visibleFigures.Count > 0)
        {
            visibleFigures.Dequeue(); // remove the one that was dragged out
            foreach (var figure in visibleFigures)
            {
                figure.transform.localPosition += (Vector3) new Vector2(-levelHoleSize, 0);
            }
            if (remainingShapes.Count > 0)
            {
                var desc      = remainingShapes.Dequeue();
                var newFigure = Figure.Create(FigureFactory.GetTemplate(desc.templateId), desc.blockType);
                newFigure.transform.SetParent(figures);
                newFigure.transform.localPosition = visiblePipePositions.Last();
                visibleFigures.Enqueue(newFigure);
            }
            else
            {
                // TODO: PUT YOU WIN MESSAGE HERE
            }
        }

        shapeCounter.text = remainingShapes.Count.ToString();
    }
Esempio n. 2
0
    void Start()
    {
        figures      = GameObject.Find("Figures").transform;
        shapeCounter = GameObject.Find("ShapeCounter").GetComponent <Text>();

        generateLevel();

        // for (int i = 0; i < FigureFactory.TemplatesCount; i++) {
        //     var blockType = BlockType.Green;
        //     if (i % 2 == 1) {
        //         blockType = i % 4 == 1 ? BlockType.Blue : BlockType.Red;
        //     }
        //     allFigures.Enqueue(Figure.Create(FigureFactory.GetTemplate(i), blockType));
        // }
        for (int i = 0; i < visiblePipePositions.Count && remainingShapes.Count > 0; i++)
        {
            // var figure = allFigures.Dequeue();
            // var figure = Figure.Create(FigureFactory.GetTemplate(i), BlockType.Green);
            var desc   = remainingShapes.Dequeue();
            var figure = Figure.Create(FigureFactory.GetTemplate(desc.templateId), desc.blockType);
            figure.transform.SetParent(figures);
            figure.transform.localPosition = visiblePipePositions[i];
            visibleFigures.Enqueue(figure);
        }

        float yMin = -3.5f;
        float yMax = levelHeight + levelHoleSize + 1 + 0.5f;

        Camera.main.transform.position = new Vector3(levelWidth * 0.5f, 0.5f * (yMin + yMax), -10.0f);
        Camera.main.orthographicSize   = 0.5f * (yMax - yMin);
    }