示例#1
0
    public void OnDrop(PointerEventData eventData)
    {
        d = eventData.pointerDrag.GetComponent <DraggableBlock>();
        if (d != null)
        {
            d.parentToReturnTo = this.transform;
        }

        //   StartCoroutine((RegisterWord()));
    }
示例#2
0
    private void SnapLocation_Highlight(GameObject snapper, bool on)
    {
        DraggableBlock draggable = snapper.GetComponent <DraggableBlock>();

        if (grid.SetHighlight(row, col, draggable, on))
        {
            grid.AnticipatedHighlight(row, col, draggable, true, snapLocation);
        }
        else
        {
            grid.AnticipatedHighlight(row, col, draggable, false, snapLocation);
        }
    }
示例#3
0
 void EnableFrontBlock()
 {
     //Check the size of queue just for safety
     if (blocksQueue.Count > 0)
     {
         // Set up the front block.
         DraggableBlock frontBlock = blocksQueue.Peek();
         frontBlock.AllowDragging(true);
         // If there is no more room for the Block on the Grid, game over.
         if (grid.CheckIfSpacesFilled(frontBlock.GetBlock()))
         {
             gameFlow.GameOver(GameFlow.GameOverCause.NoRemainingSpaces);
         }
     }
 }
示例#4
0
    //This method should be called when a DraggableBlock is dragged onto this Space.
    public void PlaceBlock(DraggableBlock block)
    {
        grid.ClearOutline();
        AudioController.Instance.PlaceTile();

        //Set position for energy gain text to pop up
        Vector3 pos    = block.transform.localPosition;
        float   width  = block.GetComponent <RectTransform>().rect.width;
        float   height = block.GetComponent <RectTransform>().rect.height;

        energyCounter.SetPopUpPos(new Vector3(pos.x + width / 2.0f, pos.y - height / 2.0f, pos.z));
        energyCounter.SetBlockTransform(block.transform);

        grid.WriteBlock(row, col, block); //We're placing this block. Apparently it's the external responsibility to make sure this will work
        grid.PlacedDraggableBlock();      // Notify the Grid that we just placed a DraggableBlock.
        grid.CheckForMatches();           //To make sure the tile clearing is finsihed before destroying the gameObject
        Destroy(block.gameObject);        //And now we're done with this GameObject - it's on the grid
    }
示例#5
0
 public void SetDraggableBlock(DraggableBlock block)
 {
     draggableBlock = block;
 }
示例#6
0
 void PositionBlockAt(DraggableBlock db, int positionIndex)
 {
     db.transform.localPosition = blockPositions[positionIndex].transform.localPosition;
 }
示例#7
0
    public void SpawnRandomBlock()
    {
        if (!enabled)
        {
            // If the component is disabled, don't spawn a block.
            return;
        }
        if (blocksQueue.Count == maxBlocksInQueue)
        {
            //if the # of elements in queue already reaches
            //max, game over
            gameFlow.GameOver(GameFlow.GameOverCause.QueueOverflow);
            return;
        }
        else
        {
            //otherwise we select a random block from the possible list,
            //then instantiate the draggable block and add it into the queue.
            Block toSpawn = null;

            if (isSpawningOneTileBlocks)
            {
                Block oneTile = new Block(1, 1);
                oneTile.Fill(0, 0, TileData.TileType.Regular);
                toSpawn = oneTile;
            }
            else if (isSpawningSameBlocks)
            {
                if (currentBlock != null)
                {
                    toSpawn = currentBlock;
                }
            }
            else
            {
                // The index of the block to choose from the bag.
                int indexInBagToChoose = -1;
                if (bag.Count == 0)
                {
                    // If the bag is empty, repopulate it.
                    List <BagBlock> viableBlocks = GetBagBlocksOfTier(tierCurrent);
                    for (int j = 0; j < viableBlocks.Count; ++j)
                    {
                        //Block bagBlock = possibleBlocks[tierCurrent][j];
                        //Block bagBlock = new Block(possibleBlocks[tierCurrent][j]);
                        BagBlock viableBlock = viableBlocks[j];
                        bag.Add(viableBlock);
                    }
                    // If a Junkyard event is starting, choose a junkyard-specific block.
                    if (junkyardEventIsStarting)
                    {
                        junkyardEventIsStarting = false;

                        List <BagBlock> junkyardBlocks = GetBagBlocksJunkyardOnlyOfTier(tierCurrent);

                        int      indexInJunkyardBlocks = Random.Range(0, junkyardBlocks.Count);
                        BagBlock junkyardBlock         = junkyardBlocks[indexInJunkyardBlocks];

                        for (int j = 0; j < bag.Count; ++j)
                        {
                            BagBlock bagBlock = bag[j];
                            if (bagBlock == junkyardBlock)
                            {
                                indexInBagToChoose = j;
                                break;
                            }
                        }

                        /*
                         * Debug.Log("Junkyard index / Bag index: " + indexInJunkyardBlocks +
                         *  " / " + indexInBagToChoose);
                         */
                    }
                    else
                    {
                        indexInBagToChoose = Random.Range(0, bag.Count);
                    }
                }
                else
                {
                    indexInBagToChoose = Random.Range(0, bag.Count);
                }
                toSpawn = bag[indexInBagToChoose].CreateBlock();
                // Remove each chosen element from the bag.
                bag.RemoveAt(indexInBagToChoose);

                // Add vestiges to the block, if applicable.
                if (isContaminationBlock)
                {
                    int             vestigesAdded = 0;
                    List <TileData> refs          = toSpawn.GetReferencesToType(TileData.TileType.Regular);

                    // Stop adding vestiges when there are no regular tiles left.
                    //Debug.Log("Vestige generation begin.");
                    while (vestigesAdded < vestigesPerBlock && refs.Count != 0)
                    {
                        int      index = Random.Range(0, refs.Count);
                        TileData v     = refs[index];
                        v.Fill(TileData.TileType.Vestige);
                        v.SetVestigeLevel(vestigeLevel);
                        refs.RemoveAt(index);
                        ++vestigesAdded;
                        //Debug.Log("vestigesAdded / vestigesPerBlock: " + vestigesAdded + " / " + vestigesPerBlock);
                        //Debug.Log("BlockSpawner: vestigeLevel: " + vestigeLevel);
                    }
                }
                //Debug.Log("Vestige generation end.");
                if (doContaminationBlocksAlternate)
                {
                    isContaminationBlock = !isContaminationBlock;
                }
            }

            // Instantiate the actual block.
            GameObject newBlock = Instantiate(prefabDraggableBlock, transform, false);
            // Initialize the DraggableBlock component.
            DraggableBlock newDraggable = newBlock.GetComponent <DraggableBlock>();
            //newDraggable.Init(toSpawn, grid, canvas);
            newDraggable.Init(toSpawn, grid, GetComponent <RectTransform>(), consoleGrid);

            newDraggable.SetScreenTapping(screenTapping);//Pass screenTapping to DraggableObject

            currentBlock = new Block(newDraggable.GetBlock());

            // Add it to the queue.
            blocksQueue.Enqueue(newDraggable);

            // If this block is the only block in queue, enable it.
            if (blocksQueue.Count == 1)
            {
                EnableFrontBlock();
            }
            else
            {
                // This block is not the only block in the queue.
                // Force the front block to be the last sibling so
                // that it is drawn above all of the other blocks.
                DraggableBlock frontBlock = blocksQueue.Peek();
                frontBlock.transform.SetAsLastSibling();
            }

            // Position new block at the next available blockPosition.
            int closestIndex = blocksQueue.Count - 1;
            PositionBlockAt(newDraggable, closestIndex);
            newDraggable.SetDefaultPosition(newBlock.transform.localPosition);

            consoleGrid.SetDraggableBlock(newDraggable); //Insert the block into the console grid
        }
    }