상속: MonoBehaviour
예제 #1
0
    /// <summary>
    /// Generate a new puzzle with some rows. This assumes the puzzle is empty.
    /// </summary>
    public void InitializeNewPuzzle(int initialRows, LevelConfig config)
    {
        int width  = DefaultPuzzleWidth;
        int height = DefaultPuzzleHeight;

        // Create a new puzzle.
        PuzzleGrid = new PuzzleTile[width, 1000];
        ResetPuzzle();

        // Set some of the variables from the config.
        VerticalScrollSpeed = config.ScrollSpeed;
        m_shouldSpawnJunk   = config.SpawnJunkTiles;
        m_shouldSpawnAlarms = config.SpawnAlarmTiles;
        ScoreToWin          = config.ScoreToWin;
        GameManager.Instance.GameCanvas.UpdateTargetScore(ScoreToWin);
        m_junkDropRate = config.JunkDropRateSeconds;

        // Row 0 is the top, the bottom at the start is equal to the height. Generate 1 row past that.
        int bottomRow = height + 1;

        // Iterate through the first few initial rows.
        int rowsToAdd = initialRows;

        for (int row = bottomRow - rowsToAdd; row <= bottomRow; row++)
        {
            bool isLastRow = row >= bottomRow;
            GenerateRow(row, width, isLastRow);
        }
    }
    private PuzzleTile CheckIfWeCanMove(int Xpos, int Ypos, PuzzleTile thisTile)
    {
        // check each movement direction
        if (CheckMoveLeft(Xpos, Ypos, thisTile) != thisTile)
        {
            return(CheckMoveLeft(Xpos, Ypos, thisTile));
        }

        if (CheckMoveRight(Xpos, Ypos, thisTile) != thisTile)
        {
            return(CheckMoveRight(Xpos, Ypos, thisTile));
        }

        if (CheckMoveDown(Xpos, Ypos, thisTile) != thisTile)
        {
            return(CheckMoveDown(Xpos, Ypos, thisTile));
        }

        if (CheckMoveUp(Xpos, Ypos, thisTile) != thisTile)
        {
            return(CheckMoveUp(Xpos, Ypos, thisTile));
        }

        return(thisTile);
    }
예제 #3
0
    /// <summary>
    /// Spawn a cool looking loading bar.
    /// </summary>
    private void CreateTransmittingBar(PuzzleTile tile)
    {
        var barObject = GameObject.Instantiate(TransmittingBarPrefab);

        barObject.transform.position = tile.transform.position;
        barObject.GetComponent <TransmittingBar>().SetLifetime(TileTransmitTime);
    }
예제 #4
0
    //interfaces

    public void DropPuzzle(int col, PuzzleTile p)
    {
        p.SetContainer(this);
        dropPuzzleCache.Add(p);
        p.transform.position = new Vector3(col, cacheHeight[col] + height + 3f, 0f) + puzzleOffset;
        cacheHeight[col]++;
        textDropCount.UpdateText(dropPuzzleCache.Count.ToString());
    }
예제 #5
0
    public bool canPlayerClickTile(PuzzleTile t)
    {
        //when the player clicks a tile during the tutorial, this function is called
        //if the tutorial is at the right stage to process that input, it is processed here
        int chosenNumber = gameManager.selectedNumber;

        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                int tileNum = (i * 3) + j;
                if (gameManager.puzzleGenerator.tilesArray[i, j] == t)
                {
                    if (advanceRequirement == "add building of height " + chosenNumber + " to tile " + tileNum)
                    {
                        return(true);
                    }
                    if (skipRequirement == "add building of height " + chosenNumber + " to tile " + tileNum)
                    {
                        return(true);
                    }
                }
            }
        }
        if (advanceRequirement == "add buildings of height 3 to tiles 2 and 6")
        {
            PuzzleTile[,] ts = gameManager.puzzleGenerator.tilesArray;
            if (gameManager.selectedNumber == 3)
            {
                if (ts[0, 2] == t || ts[2, 0] == t)
                {
                    return(true);
                }
            }
        }
        if (skipRequirement == "add buildings of height 3 to tiles 2 and 6")
        {
            PuzzleTile[,] ts = gameManager.puzzleGenerator.tilesArray;
            if (gameManager.selectedNumber == 3)
            {
                if (ts[0, 2] == t || ts[2, 0] == t)
                {
                    return(true);
                }
            }
        }
        if (advanceRequirement == "complete the city")
        {
            if (t.shownNumber == 0)
            {
                if (t.solution == gameManager.selectedNumber)
                {
                    return(true);
                }
            }
        }
        return(false);
    }
예제 #6
0
    void DropPuzzle()
    {
        int        c = randomPuzzleColTable.Get();
        PuzzleTile p = Instantiate(samplePuzzle, transform.position, Quaternion.identity, container.transform).GetComponent <PuzzleTile>();

        p.col = c;
        p.SetPuzzleType((PuzzleTile.PType)randomPuzzleTypeTable.Get());
        container.DropPuzzle(c, p);
    }
예제 #7
0
    private void HandleRecursiveTilesWhenFallingComplete(PuzzleTile fallingTile, int comboDepth)
    {
        // Now evaluate all matches on the board from falling blocks as a result of these matches.
        HashSet <PuzzleTile> recursivelyMatchedTiles = new HashSet <PuzzleTile>();
        var matchesForFallingTile = GetMatchesFromTypeAtPosition(fallingTile.PuzzleTileType, fallingTile.X, fallingTile.Y);

        matchesForFallingTile.ForEach(v => recursivelyMatchedTiles.Add(PuzzleGrid[(int)v.x, (int)v.y]));
        HandleMatches(new List <PuzzleTile>(recursivelyMatchedTiles), comboDepth + 1);
    }
예제 #8
0
    private PuzzleTile GetTileFromDirection(PuzzleTile _tile1, Vector2 _direction)
    {
        if (_tile1 == null)
        {
            return(null);
        }

        int tile1Index   = _tile1.transform.GetSiblingIndex();
        int parent1Index = _tile1.transform.parent.GetSiblingIndex();

        if (Mathf.Abs(_direction.x) > Mathf.Abs(_direction.y))
        {
            // Move horizontally
            if (_direction.x > 0)
            {
                if (tile1Index >= cols - 1)
                {
                    return(null);
                }
                // (Move right) Get the PuzzleTile of the next sibbiling object
                return(_tile1.transform.parent.GetChild(tile1Index + 1).GetComponent <PuzzleTile>());
            }
            else
            {
                if (tile1Index <= 0)
                {
                    return(null);
                }
                // (Move left) Get the PuzzleTile of the previous sibbiling object
                return(_tile1.transform.parent.GetChild(tile1Index - 1).GetComponent <PuzzleTile>());
            }
        }
        else
        {
            // Move vertically
            if (_direction.y > 0)
            {
                if (parent1Index <= 0)
                {
                    return(null);
                }
                // (Move up) Get the PuzzleTile of the previous parent with the same sibbiling object
                return(_tile1.transform.parent.parent.GetChild(parent1Index - 1).GetChild(tile1Index).GetComponent <PuzzleTile>());
            }
            else
            {
                if (parent1Index >= rows - 1)
                {
                    return(null);
                }
                // (Move down) Get the PuzzleTile of the next parent with the same sibbiling object
                return(_tile1.transform.parent.parent.GetChild(parent1Index + 1).GetChild(tile1Index).GetComponent <PuzzleTile>());
            }
        }
    }
    private PuzzleTile CheckMoveRight(int Xpos, int Ypos, PuzzleTile thisTile)
    {
        // move right
        if ((Xpos + 1) < Width)
        {
            // we can move right, is the space currently being used?
            return(GetTileAtThisGridLocation(Xpos + 1, Ypos, thisTile));
        }

        return(thisTile);
    }
    private PuzzleTile CheckMoveUp(int Xpos, int Ypos, PuzzleTile thisTile)
    {
        // move up
        if ((Ypos + 1) < Height)
        {
            // we can move up, is the space currently being used?
            return(GetTileAtThisGridLocation(Xpos, Ypos + 1, thisTile));
        }

        return(thisTile);
    }
예제 #11
0
 private PuzzleTile[] reverseList(PuzzleTile[] original)
 {
     //reverses a list
     PuzzleTile[] newList = new PuzzleTile[size];
     for (int i = 0; i < original.Length; i++)
     {
         int oppositeIndex = original.Length - i;
         newList[i] = original[oppositeIndex - 1];
     }
     return(newList);
 }
    private PuzzleTile CheckMoveLeft(int Xpos, int Ypos, PuzzleTile thisTile)
    {
        // move left
        if ((Xpos - 1) >= 0)
        {
            // we can move left, is the space currently being used?
            return(GetTileAtThisGridLocation(Xpos - 1, Ypos, thisTile));
        }

        return(thisTile);
    }
예제 #13
0
 private void removeRedBoxesAroundTiles()
 {
     //removes all red borders around all tiles
     for (int i = 0; i < 3; i++)
     {
         for (int j = 0; j < 3; j++)
         {
             PuzzleTile t = gameManager.puzzleGenerator.tilesArray[i, j];
             t.removeRedBorder();
         }
     }
 }
    private void CreatePuzzleTiles()
    {
        // using the width and height variables create an array.
        TileDisplayArray = new GameObject[Width, Height];

        // set the scale and position values for this puzzle.
        Scale = new Vector3(1.0f / Width, 1.0f, 1.0f / Height);
        Tile.transform.localScale = Scale;

        // used to count the number of tiles and assign each tile a correct value.
        int TileValue = 0;

        // spawn the tiles into an array.
        for (int j = Height - 1; j >= 0; j--)
        {
            for (int i = 0; i < Width; i++)
            {
                // calculate the position of this tile all centred around Vector3(0.0f, 0.0f, 0.0f).
                Position = new Vector3(((Scale.x * (i + 0.5f)) - (Scale.x * (Width / 2.0f))) * (10.0f + SeperationBetweenTiles),
                                       0.0f,
                                       ((Scale.z * (j + 0.5f)) - (Scale.z * (Height / 2.0f))) * (10.0f + SeperationBetweenTiles));

                // set this location on the display grid.
                DisplayPositions.Add(Position);

                // spawn the object into play.
                TileDisplayArray[i, j] = Instantiate(Tile, new Vector3(0.0f, 0.0f, 0.0f), Quaternion.Euler(90.0f, -180.0f, 0.0f)) as GameObject;
                TileDisplayArray[i, j].gameObject.transform.parent = this.transform;

                // set and increment the display number counter.
                PuzzleTile thisTile = TileDisplayArray[i, j].GetComponent <PuzzleTile>();
                thisTile.ArrayLocation = new Vector2(i, j);
                thisTile.GridLocation  = new Vector2(i, j);
                thisTile.LaunchPositionCoroutine(Position);
                TileValue++;

                // create a new material using the defined shader.
                Material thisTileMaterial = new Material(PuzzleShader);

                // apply the puzzle image to it.
                thisTileMaterial.mainTexture = PuzzleImage;

                // set the offset and tile values for this material.
                thisTileMaterial.mainTextureOffset = new Vector2(1.0f / Width * i, 1.0f / Height * j);
                thisTileMaterial.mainTextureScale  = new Vector2(1.0f / Width, 1.0f / Height);

                // assign the new material to this tile for display.
                TileDisplayArray[i, j].GetComponent <Renderer>().material = thisTileMaterial;
            }
        }
    }
예제 #15
0
    public void RemovePuzzle(int col, int row)
    {
        List <PuzzleTile> l = puzzleMap[col];

        if (l.Count > row && l[row] != null)
        {
            PuzzleTile p = l[row];

            l[row] = null;
            p.Kill();

            puzzleDirty = true;
        }
    }
예제 #16
0
    public void clickedTile(PuzzleTile t)
    {
        //some stages require the player to input a specific number into a specific tile
        //some stages require the player to input several numbers in sequence to advance
        int chosenNumber = gameManager.selectedNumber;

        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                int tileNum = (i * 3) + j;
                if (gameManager.puzzleGenerator.tilesArray[i, j] == t)
                {
                    if (advanceRequirement == "add building of height " + chosenNumber + " to tile " + tileNum)
                    {
                        advanceStage();
                    }
                    if (skipRequirement == "add building of height " + chosenNumber + " to tile " + tileNum)
                    {
                        skipStage();
                    }
                }
            }
        }

        if (advanceRequirement == "add buildings of height 3 to tiles 2 and 6")
        {
            PuzzleTile[,] ts = gameManager.puzzleGenerator.tilesArray;
            if (ts[0, 2].shownNumber == 3 && ts[2, 0].shownNumber == 3)
            {
                advanceStage();
            }
        }
        if (skipRequirement == "add buildings of height 3 to tiles 2 and 6")
        {
            PuzzleTile[,] ts = gameManager.puzzleGenerator.tilesArray;
            if (ts[0, 2].shownNumber == 3 && ts[2, 0].shownNumber == 3)
            {
                skipStage();
            }
        }
        if (advanceRequirement == "complete the city")
        {
            if (gameManager.puzzleGenerator.checkPuzzle())
            {
                advanceStage();
            }
        }
    }
    IEnumerator Laser()
    {
        LineRenderer line           = weaver.GetComponent <LineRenderer> ();
        float        laserExtension = 0;

        while (laserExtension < 100)
        {
            laserExtension = Mathf.Lerp(laserExtension, 250, 0.5f);
            line.SetPosition(1, new Vector3(0, 0, laserExtension));
            yield return(null);
        }
        float laserTimer = 0;

        while (laserActive)
        {
            Ray        ray = new Ray(weaver.transform.position, weaver.transform.forward);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, 100))
            {
                if (hit.transform.tag == "Tile")
                {
                    PuzzleTile tile = hit.transform.GetComponent <PuzzleTile> ();
                    tile.currentAlpha += Time.deltaTime * 2;
                }
                else if (hit.transform.tag == "CMW")
                {
                    CMW_Controllers c = hit.transform.GetComponent <CMW_Controllers> ();
                    c.SendInput();
                    print("Ray hit CMW");
                }
            }
            laserTimer += Time.deltaTime;
            if (laserTimer > 1.3f)
            {
                laserActive = false;
            }
            yield return(null);
        }

        while (laserExtension > 0.05f)
        {
            laserExtension = Mathf.Lerp(laserExtension, 0, 0.5f);
            line.SetPosition(1, new Vector3(0, 0, laserExtension));
            yield return(null);
        }

        laserRoutine = null;
        yield break;
    }
 void OnTriggerEnter(Collider other)
 {
     if (other.tag == "Laser")
     {
         Kill();
     }
     else if (other.tag == "Tile")
     {
         PuzzleTile tile = other.GetComponent <PuzzleTile> ();
         if (tile.myType == PuzzleTile.Type.Death)
         {
             Kill();
         }
     }
 }
예제 #19
0
 private void addRedBoxAroundTile(int spaceNum)
 {
     //adds a red border around a PuzzleTile, to draw attention to that tile
     for (int i = 0; i < 3; i++)
     {
         for (int j = 0; j < 3; j++)
         {
             if (((i * 3) + j) == spaceNum)
             {
                 PuzzleTile t = gameManager.puzzleGenerator.tilesArray[i, j];
                 t.addRedBorder();
             }
         }
     }
 }
예제 #20
0
    /// <summary>
    /// Handle actually destroying the object and triggering alarms and such.
    /// </summary>
    /// <param name="tile"></param>
    private void DestroyTileAfterMatch(PuzzleTile tile)
    {
        if (tile.IsOffscreen)
        {
            Debug.Log("Destroying Offscreen Tile");
        }
        if (tile.PuzzleTileType == PuzzleTileType.Alarm)
        {
            TriggerAlarm();
        }

        if (tile != null)
        {
            GameObject.Destroy(tile.gameObject);
        }
    }
예제 #21
0
 private void fillInSpace(int spaceNum, int value)
 {
     //the first few stages fill in some basic puzzle numbers for you automatically as you proceed
     //takes a number corresponding to the relevant space, and a value to fill it with, and adds that number to that space
     for (int i = 0; i < 3; i++)
     {
         for (int j = 0; j < 3; j++)
         {
             if (((i * 3) + j) == spaceNum)
             {
                 PuzzleTile t = gameManager.puzzleGenerator.tilesArray[i, j];
                 t.toggleNumber(value);
             }
         }
     }
 }
예제 #22
0
    public bool Move(PuzzleTile _tile1, Vector2 _direction)
    {
        // If the two tiles exist
        PuzzleTile _tile2 = GetTileFromDirection(_tile1, _direction);

        if (_tile1 == null || _tile2 == null)
        {
            return(false);
        }

        // One of the two tiles need to be the empty one
        if (!_tile1.IsLast() && !_tile2.IsLast())
        {
            return(false);
        }

        // invert parent and Sibling Index
        Transform tile1Transform    = _tile1.transform.parent;
        Transform tile2Transform    = _tile2.transform.parent;
        int       tile1SiblingIndex = _tile1.transform.GetSiblingIndex();
        int       tile2SiblingIndex = _tile2.transform.GetSiblingIndex();

        _tile1.transform.SetParent(tile2Transform);
        _tile2.transform.SetParent(tile1Transform);
        _tile1.transform.SetSiblingIndex(tile2SiblingIndex);
        _tile2.transform.SetSiblingIndex(tile1SiblingIndex);

        // invert index
        int tile1Index = _tile1.GetIndex();
        int tile2Index = _tile2.GetIndex();

        _tile1.SetCurrentIndex(tile2Index);
        _tile2.SetCurrentIndex(tile1Index);

        // Setup animation
        tile1ForAnimation         = _tile1;
        tile2ForAnimation         = _tile2;
        tile1PositionForAnimation = _tile1.transform.position;
        tile2PositionForAnimation = _tile2.transform.position;
        //tile1ForAnimation.transform.position = tile1PositionForAnimation;
        //tile2ForAnimation.transform.position = tile2PositionForAnimation;
        currentAnimationSpeed = 0;
        currentGameStatus     = gameStatus.Moving;

        return(true);
    }
예제 #23
0
    public bool RemovePuzzle(int col, int row, PuzzleTile.PType t)
    {
        List <PuzzleTile> l = puzzleMap[col];

        if (l.Count > row && l[row] != null)
        {
            PuzzleTile p = l[row];
            if (p.puzzleType == t)
            {
                l[row] = null;
                p.Kill();
                puzzleDirty = true;
                return(true);
            }
        }
        return(false);
    }
예제 #24
0
 /// <summary>
 /// Generate all of the tiles in a new row.
 /// </summary>
 private void GenerateRow(int row, int width, bool isOffscreen = false, PuzzleTileType overrideType = PuzzleTileType.None)
 {
     // Iterate all of the tiles in this row and create them.
     for (int x = 0; x < width; x++)
     {
         PuzzleTileType tileType = overrideType;
         if (tileType == PuzzleTileType.None)
         {
             tileType = ChooseRandomNonMatchingTile(x, row);
         }
         PuzzleTile newTile = GenerateTile(tileType, x, row);
         newTile.IsOffscreen = isOffscreen;
     }
     if (row > m_lastAddedRow)
     {
         m_lastAddedRow = row;
     }
 }
예제 #25
0
    public void InsertPuzzle()
    {
        float yOffset = -1f;

        while (insertQuery > 0)
        {
            for (int i = 0; i < width; i++)
            {
                PuzzleTile p = Instantiate(samplePuzzle, puzzleOffset + new Vector3(i, yOffset, 0f), Quaternion.identity, transform);
                p.SetPuzzleType((PuzzleTile.PType)randomTable.Get());
                p.SetContainer(this);
                puzzleMap[i].Insert(0, p);
            }
            yOffset -= 1f;
            insertQuery--;
        }
        textInsertCount.UpdateText(insertQuery.ToString());
    }
예제 #26
0
    /// <summary>
    /// Generate a tile from the type.
    /// </summary>
    private PuzzleTile GenerateTile(PuzzleTileType tileType, int x, int y)
    {
        GameObject resource   = Resources.Load(PuzzleTileResourceMap[tileType]) as GameObject;
        GameObject tileObject = GameObject.Instantiate(resource);
        PuzzleTile puzzleTile = tileObject.GetComponent <PuzzleTile>();

        m_createdTiles.Add(puzzleTile);

        PuzzleGrid[x, y]          = puzzleTile;
        puzzleTile.X              = x;
        puzzleTile.Y              = y;
        puzzleTile.PuzzleTileType = tileType;

        // Set the position and check if it should fall.
        puzzleTile.transform.localPosition = GetLocalPositionOfTileCoordinate(x, y);
        CheckUnderBlockAndFall(puzzleTile.X, puzzleTile.Y);

        puzzleTile.transform.SetParent(TileContainer.transform, false);

        return(puzzleTile);
    }
    private PuzzleTile GetTileAtThisGridLocation(int x, int y, PuzzleTile thisTile)
    {
        for (int j = Height - 1; j >= 0; j--)
        {
            for (int i = 0; i < Width; i++)
            {
                // check if this tile has the correct grid display location.
                if ((TileDisplayArray[i, j].GetComponent <PuzzleTile>().GridLocation.x == x) &&
                    (TileDisplayArray[i, j].GetComponent <PuzzleTile>().GridLocation.y == y))
                {
                    if (TileDisplayArray[i, j].GetComponent <PuzzleTile>().Active == false)
                    {
                        // return this tile active property.
                        return(TileDisplayArray[i, j].GetComponent <PuzzleTile>());
                    }
                }
            }
        }

        return(thisTile);
    }
    public Vector3 GetTargetLocation(PuzzleTile thisTile)
    {
        // check if we can move this tile and get the position we can move to.
        PuzzleTile MoveTo = CheckIfWeCanMove((int)thisTile.GridLocation.x, (int)thisTile.GridLocation.y, thisTile);

        if (MoveTo != thisTile)
        {
            // get the target position for this new tile.
            Vector3 TargetPos    = MoveTo.TargetPosition;
            Vector2 GridLocation = thisTile.GridLocation;
            thisTile.GridLocation = MoveTo.GridLocation;

            // move the empty tile into this tiles current position.
            MoveTo.LaunchPositionCoroutine(thisTile.TargetPosition);
            MoveTo.GridLocation = GridLocation;

            // return the new target position.
            return(TargetPos);
        }

        // else return the tiles actual position (no movement).
        return(thisTile.TargetPosition);
    }
예제 #29
0
    /// <summary>
    /// Get the neighbors of a tile.
    /// </summary>
    private List <PuzzleTile> GetAllNeighborsOfTile(PuzzleTile tile)
    {
        List <PuzzleTile> neighbors = new List <PuzzleTile>();

        if (tile.X > 0)
        {
            neighbors.Add(PuzzleGrid[tile.X - 1, tile.Y]);
        }
        if (tile.X < DefaultPuzzleWidth - 1)
        {
            neighbors.Add(PuzzleGrid[tile.X + 1, tile.Y]);
        }
        if (tile.Y > 0)
        {
            neighbors.Add(PuzzleGrid[tile.X, tile.Y - 1]);
        }
        if (tile.Y < 1000)
        {
            neighbors.Add(PuzzleGrid[tile.X, tile.Y + 1]);
        }

        return(neighbors);
    }
예제 #30
0
    public void SwapWithNull(PuzzleTile draggedTile, int mouseX, int mouseY)
    {
        int currentX = draggedTile.X;
        int currentY = draggedTile.Y;

        // Only drag off edges next to the tile.
        if (Mathf.Abs(mouseX - currentX) != 1)
        {
            return;
        }

        // Move the tile to the null space.
        var slidingTile = MoveTileToNullPosition(currentX, currentY, mouseX, currentY);

        slidingTile.transform.localPosition = GetLocalPositionOfTileCoordinate(mouseX, currentY);

        // Drop the dragged tile.
        CheckUnderBlockAndFall(mouseX, currentY);

        // Drop all tiles above the null space.
        if (PuzzleGrid[currentX, currentY - 1] != null)
        {
            for (int y = currentY - 1; y > 0; y--)
            {
                if (PuzzleGrid[currentX, y] == null)
                {
                    break;
                }

                // Move the tile down one and continue to the next tile.
                int newY        = y + 1;
                var fallingTile = MoveTileToNullPosition(currentX, y, currentX, newY);
                fallingTile.TargetFallingLocalPosition = GetLocalPositionOfTileCoordinate(currentX, newY);
                fallingTile.FallIntoPosition(HandleRecursiveTilesWhenFallingComplete, 1);
            }
        }
    }