Ejemplo n.º 1
0
    public void debug()
    {
        string output = "";

        for (int r = row - 1; r >= 0; r--)
        {
            for (int c = 0; c < col; c++)
            {
                if (!tiles[r][c])
                {
                    output += "-,";
                }
                else if (tiles[r][c] is TransparentWall)
                {
                    output += "X,";
                }
                else if (tiles[r][c] is Wall)
                {
                    output += "= ";
                }
                else
                {
                    WordTile wordTile = (WordTile)tiles[r][c];
                    output += wordTile.symbol + ",";
                }
            }
            output += "\r\n";
        }
        Debug.Log(output);
    }
Ejemplo n.º 2
0
//  public void randomlyGenerateBonus() {
//    bonus = 0;
//    this.transform.Find("Bonus2x").gameObject.SetActive(false);
//    this.transform.Find("Bonus4x").gameObject.SetActive(false);
//    this.transform.Find("Bonus8x").gameObject.SetActive(false);
//
//    if (Random.Range(0, 20) == 0) {
//      int v = Random.Range(0, 6);
//      if (v < 4) {
//        bonus = 2;
//        this.transform.Find("Bonus2x").gameObject.SetActive(true);
//      } else if (v < 6) {
//        bonus = 4;
//        this.transform.Find("Bonus4x").gameObject.SetActive(true);
//      } else {
//        bonus = 8;
//        this.transform.Find("Bonus8x").gameObject.SetActive(true);
//      }
//    }
//  }

    public static WordTile createGameObject(GameObject parent, int r, int c, string val = null, int bonus = 0)
    {
        GameObject g = Instantiate(Resources.Load("WordTile")) as GameObject;

        g.transform.SetParent(parent.transform);

        WordTile tile = g.GetComponent <WordTile>();

        tile.init(r, c);
        if (val != null)
        {
            tile.setSymbol(val);
            tile.render();
        }

        if (bonus == 2)
        {
            tile.transform.Find("Bonus2x").gameObject.SetActive(true);
        }
        else if (bonus == 4)
        {
            tile.transform.Find("Bonus4x").gameObject.SetActive(true);
        }
        else if (bonus == 8)
        {
            tile.transform.Find("Bonus8x").gameObject.SetActive(true);
        }

        return(tile);
    }
Ejemplo n.º 3
0
    public string getSymbolsFromTiles(List <WordTile> tiles)
    {
        StringBuilder connectedWord = new StringBuilder();

        for (int i = 0; i < tiles.Count; i++)
        {
            WordTile tile = (WordTile)tiles[i];
            connectedWord.Append(tile.symbol);
        }
        return(connectedWord.ToString());
    }
Ejemplo n.º 4
0
    private WordTile setTileBlastDirection(List <Tile> tiles)
    {
        WordTile t        = (WordTile)tiles[tiles.Count - 1];
        WordTile lastTile = (WordTile)tiles[tiles.Count - 2];

        if (Mathf.Abs(lastTile.getRow() - t.getRow()) + Math.Abs(lastTile.getCol() - t.getCol()) > 1)
        {
            if (tiles.Count == 5)
            {
                if ((lastTile.getRow() - t.getRow() == 1 && (lastTile.getCol() - t.getCol() == 1)) || (lastTile.getRow() - t.getRow() == -1 && (lastTile.getCol() - t.getCol() == -1)))
                {
                    t.blasterDirection = 3;
                }
                else
                {
                    t.blasterDirection = 4;
                }
            }
            else if (tiles.Count == 6)
            {
                t.blasterDirection = 6;
            }
            else
            {
                t.blasterDirection = 7;
            }
        }
        else
        {
            if (tiles.Count == 5)
            {
                if (Mathf.Abs(lastTile.getRow() - t.getRow()) > 0)
                {
                    t.blasterDirection = 2;
                }
                else
                {
                    t.blasterDirection = 1;
                }
            }
            else if (tiles.Count == 6)
            {
                t.blasterDirection = 5;
            }
            else
            {
                t.blasterDirection = 7;
            }
        }
        return(t);
    }
Ejemplo n.º 5
0
    // Drag the tile
    void drag(GameObject gameObject)
    {
        // gameObject is the tile to be dragged
        WordTile tile = gameObject.GetComponent <WordTile>(); // find the tile in the data

        if (tile is Wall)                                     // do nothing if the tile is a wall
        {
            return;
        }

        if (connectedTiles.Count > 0 && !isNeighbor(tile, connectedTiles[connectedTiles.Count - 1])) // if the tile is part of a chain,
        {
            return;                                                                                  // do nothing
        }

        if (!connectedTiles.Contains(tile))                                                               // if the tile is a
        {
            connectedTiles.Add(tile);                                                                     // add the tile to the chain of tiles
            tile.setConnected(true);                                                                      // set the tile to be connected
            AudioClip clip = Resources.Load("Sounds/" + Math.Min(13, connectedTiles.Count)) as AudioClip; // select the sound to play
            AudioSource.PlayClipAtPoint(clip, Vector3.zero);                                              // play a sound indicating that tile was connected
            tile.tileBounce();                                                                            // play animation for tile jiggling
        }
        else // otherwise if the tiles are connected,
        {
            for (int i = connectedTiles.Count - 1; i > connectedTiles.IndexOf(tile); i--) // for every tile that is in the chain
            {
                connectedTiles[i].setConnected(false);                                    // set the tile to be disconnected
                connectedTiles.RemoveAt(i);                                               // remove the tile object from the chain
                tile.tileBounce();                                                        // play animation for tile jiggling
            }
        }

        bool valid = this.validation(connectedTiles);      // Check if the connected word is valid

        if (valid)                                         // If the word is valid.
        {
            for (int i = 0; i < connectedTiles.Count; i++) // for every tile making up the word,
            {
                connectedTiles[i].setCorrectWord(true);    // Set every tile to be part of a valid word
            }
        }
        else // otherwise, if word in invalid,
        {
            for (int i = 0; i < connectedTiles.Count; i++) // for every tile making the word
            {
                connectedTiles[i].setCorrectWord(false); // set every tile to be invalid
            }
        }
        updateText(); // update all words that are connected
    }
Ejemplo n.º 6
0
    private void consumeCrown(WordTile tile)
    {
        if (tile.crown)
        {
            List <Anchor> anchors      = getAnchors();
            List <Ice>    ice          = getIce();
            Ice           iceAboveTile = (Ice)getIceTile(tile.getRow(), tile.getCol());

            if (ice.Count > 0 && iceAboveTile != null)
            {
                ice.Remove(iceAboveTile);
            }

            if (anchors.Count > 0) // pop Tile below anchor
            {
                Anchor pickedAnchor = (anchors[UnityEngine.Random.Range(0, anchors.Count)]);
                for (int n = 0; n < pickedAnchor.getRow(); n++)
                {
                    Tile t = getTile(n, pickedAnchor.getCol());
                    if (t is WordTile && t != tile)
                    {
                        popCrown(tile, t);
                        break;
                    }
                }
            }
            else if (ice.Count > 0) //pop tile with ice
            {
                int      random      = UnityEngine.Random.Range(0, ice.Count);
                Ice      pickedIce   = (ice[random]);
                WordTile abovePicked = (WordTile)getTile(pickedIce.getRow(), pickedIce.getCol());
                popCrown(tile, abovePicked);
            }
            else //pop random tile
            {
                List <WordTile> wordTilesList = getWordTiles();
                for (int a = 0; a < wordTilesList.Count; a++)
                {
                    Tile t = wordTilesList[UnityEngine.Random.Range(0, wordTilesList.Count())];
                    if (t is WordTile && t != tile)
                    {
                        popCrown(tile, t);
                        break;
                    }
                }
            }
        }
    }
Ejemplo n.º 7
0
    /// <summary>
    /// Raises the drop event.
    /// If a word tile from the sentence is dropped, it is deleted.
    /// A word tile from the word bank is not deleted by the trash can.
    /// </summary>
    /// <param name="eventData">Event data.</param>
    public void OnDrop(PointerEventData eventData)
    {
        GameObject draggedObject = eventData.pointerDrag;

        if (draggedObject != null)
        {
            WordTile wordTile = draggedObject.GetComponent <WordTile> ();

            // If word tile was dragged from sentence and dropped on trash can then delete it
            if (wordTile != null && wordTile.draggedFromSentence)
            {
                wordTile.delete();
                transform.GetComponent <Image> ().rectTransform.sizeDelta = defaultSize;
            }
        }
    }
Ejemplo n.º 8
0
    // If crown exists in word, places connected crown bonus object onto random tile
    protected override void popCrown(WordTile from, Tile to)
    {
        GameObject    g      = from.getCrown();                                      // Find the crown within the word
        RectTransform rt     = g.GetComponent <RectTransform>();                     // Find the location of the crown
        Vector3       offset = g.GetComponent <RectTransform>().anchoredPosition3D;  // extract the coordinates of the crown

        offset.x = offset.x * g.GetComponent <RectTransform>().localScale.x;         // extract x coordinate of crown
        offset.y = offset.y * g.GetComponent <RectTransform>().localScale.y;         // extract y coordinate of crown
        offset.z = offset.z * g.GetComponent <RectTransform>().localScale.z;         // extract z coordinate of crown
        g.transform.SetParent(this.transform);                                       // Set crown position to be relative to whole grid, instead of current location
        g.SetActive(true);                                                           // activate the crown bonus object
        g.transform.SetAsLastSibling();                                              // move the crown to bottom of priority list

        Vector3 pos = to.GetComponent <RectTransform>().anchoredPosition3D + offset; // find the position to which crown will be moved

        base.popCrown(from, to);                                                     // remove crown fro current position
        rt.DOAnchorPos3D(pos, 0.5f).SetEase(Ease.InQuart).OnStepComplete(() => {     // gradually animate crown in new position
            g.SetActive(false);                                                      // inactivate crown object
        });
    }
Ejemplo n.º 9
0
    private void generateCrown(List <Tile> tiles)
    {
        if (tiles.Count == 4)
        {
            List <WordTile> wordTilesList = getWordTiles();

            for (int i = 0; i < tiles.Count; i++)
            {
                if (wordTilesList.Contains((WordTile)tiles[i]))
                {
                    wordTilesList.Remove((WordTile)tiles[i]);
                }
            }

            for (int i = wordTilesList.Count - 1; i >= 0; i--)
            {
                if (wordTilesList[i].crown)
                {
                    wordTilesList.Remove(wordTilesList[i]);
                }
            }
            if (wordTilesList.Count == 0)
            {
                return;
            }

            WordTile crownTile = (wordTilesList[UnityEngine.Random.Range(0, wordTilesList.Count)]);

            if (crownTile is WordTile)
            {
                WordTile k = (WordTile)crownTile;
                k.setCrown(true);
            }
            else
            {
                generateCrown(tiles);
            }
        }
    }
Ejemplo n.º 10
0
 public bool popRemainingSpecialTiles() // pop one at a time
 {
     for (int r = 0; r < row; r++)
     {
         for (int c = 0; c < col; c++)
         {
             Tile tile = getTile(r, c);
             if (tile is WordTile)
             {
                 WordTile t = (WordTile)tile;
                 if (t.crown || t.blasterDirection > 0)
                 {
                     popAndMoveDown(new List <Tile>()
                     {
                         t
                     });
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
Ejemplo n.º 11
0
    private void _popAndMoveDown(List <Tile> tiles) //all tiles should be wordtiles
    {
        if (tiles == null)
        {
            return;
        }

        for (int i = 0; i < tiles.Count; i++)
        {
            pop(tiles[i]);
        }

        if (tiles.Count > 4)
        {
            WordTile t = setTileBlastDirection(tiles);
            t.appear();
            setTile(t, t.getRow(), t.getCol());//put back t
        }

        bool moved = true;

        while (moved)
        {
            moved = this.moveDown();
            for (int c = 0; c < col; c++)
            {
                for (int r = row - 1; r >= 0; r--)
                {
                    if (getTile(r, c) == null)
                    {
                        float n = UnityEngine.Random.Range(0, 100 * 100) / 100;
                        Dictionary <string, object> anchorRule = level.getAnchorTargetRule();
                        if (!level.isTutorial)
                        {
                            if (anchorRule != null && getColWithoutWall().Contains(c) && n < (double)anchorRule["probability"] * 100)
                            {
                                Tile tile = Anchor.createGameObject(this.gameObject, r, c);
                                setTile(tile, r, c);
                            }
                            else
                            {
                                Tile tile = WordTile.createGameObject(this.gameObject, r, c);
                                setTile(tile, r, c);
                            }
                        }
                    }
                }
            }
        }

        for (int r = 0; r < row; r++)
        {
            for (int c = 0; c < col; c++)
            {
                Tile tile = getTile(r, c);
                if (tile)
                {
                    tile.gravity();
                }
            }
        }

        this.InvokeCallback(1.0f, () => {
            bool popped = popAnchor();
            //Debug.Log("sinkedAnchorCount: " + sinkedAnchorCount);
            if (popped)
            {
                _popAndMoveDown(new List <Tile>());
            }
            else
            {
                //finally done.
                List <WordTile> specialPop = new List <WordTile>();
                for (int i = 0; i < tilePoppedThisTurn.Count; i++)
                {
                    if (!tiles.Contains(tilePoppedThisTurn[i]))
                    {
                        specialPop.Add(tilePoppedThisTurn[i]);
                    }
                }

                int total = calculateScoreFromConnectedTiles(tiles.Cast <WordTile>().ToList()) +
                            calculateScoreFromBlastedTiles(specialPop.Cast <WordTile>().ToList());

                userScore += total;
                finishAllPopAndMoveDown(tiles.Cast <WordTile>().ToList(), specialPop.Cast <WordTile>().ToList(), total);
            }
            updateScore();
            tilePoppedThisTurn.Clear();
        });
    }
Ejemplo n.º 12
0
 protected virtual void popCrown(WordTile from, Tile to)
 {
     pop(to);
 }
Ejemplo n.º 13
0
    private void pop(Tile t)
    {
        if (t == null)
        {
            return;
        }

        Ice iceAboveTile = (Ice)getIceTile(t.getRow(), t.getCol());

        if (iceAboveTile != null && !iceAboveTile.isBreakable())
        {
            iceTiles[t.getRow()][t.getCol()] = null;
            iceAboveTile.pop();
            poppedIceCount += 1;
        }

        if (!(t is WordTile))
        {
            return;
        }

        if (t is RootedTile)
        {
            RootedTile tile = (RootedTile)t;
            tile.pop();
            if (!tile.isBreakable())
            {
                return;
            }
        }

        WordTile k = (WordTile)t;

        if (k.crown)
        {
            consumeCrown(k);
        }

        k.disappear();
        tilePoppedThisTurn.Add(k);
        setTile(null, k.getRow(), k.getCol());

        if (k.blasterDirection == 1) //Horizontal
        {
            k.blasterAnimation();
            for (int c = 0; c < col; c++)
            {
                pop(getTile(k.getRow(), c));
            }
        }
        else if (k.blasterDirection == 2) //Vertical
        {
            k.blasterAnimation();
            for (int r = 0; r < row; r++)
            {
                pop(getTile(r, k.getCol()));
            }
        }
        else if (k.blasterDirection == 3) //diagonalArrow1
        {
            k.blasterAnimation();
            for (int i = 0; i < row; i++)
            {
                pop(getTile((k.getRow() + i), (k.getCol() + i)));
                pop(getTile((k.getRow() - i), (k.getCol() - i)));
            }
        }
        else if (k.blasterDirection == 4) //diagonalArrow2
        {
            k.blasterAnimation();
            for (int i = 0; i < row; i++)
            {
                pop(getTile((k.getRow() + i), (k.getCol() - i)));
                pop(getTile((k.getRow() - i), (k.getCol() + i)));
            }
        }
        else if (k.blasterDirection == 5) //UpDown
        {
            k.blasterAnimation();
            for (int c = 0; c < col; c++)
            {
                pop(getTile(k.getRow(), c));
            }
            for (int r = 0; r < row; r++)
            {
                pop(getTile(r, k.getCol()));
            }
        }
        else if (k.blasterDirection == 6) //Corner
        {
            k.blasterAnimation();
            for (int i = 0; i < row; i++)
            {
                pop(getTile((k.getRow() + i), (k.getCol() - i)));
                pop(getTile((k.getRow() - i), (k.getCol() + i)));
                pop(getTile((k.getRow() + i), (k.getCol() + i)));
                pop(getTile((k.getRow() - i), (k.getCol() - i)));
            }
        }
        else if (k.blasterDirection == 7) //allDirection
        {
            k.blasterAnimation();
            for (int i = 0; i < row; i++)
            {
                pop(getTile((k.getRow() + i), (k.getCol() - i)));
                pop(getTile((k.getRow() - i), (k.getCol() + i)));
                pop(getTile((k.getRow() + i), (k.getCol() + i)));
                pop(getTile((k.getRow() - i), (k.getCol() - i)));
            }
            for (int c = 0; c < col; c++)
            {
                pop(getTile(k.getRow(), c));
            }
            for (int r = 0; r < row; r++)
            {
                pop(getTile(r, k.getCol()));
            }
        }
    }
Ejemplo n.º 14
0
    // Initializes the Grid
    public void init(Level level)
    {
        // level contains the level data
        base.init(level);                                                  // Passes the level to the game controller to begin the game
        List <Dictionary <string, object> > levelBoard = level.getBoard(); // Contains information for each game tile

        if (levelBoard != null)                                            // If there is game data, generate tiles corresponding to the data; Otherwise tiles are randomly generated
        {
            for (int i = 0; i < levelBoard.Count; i++)                     // For every tile in level data
            {
                Dictionary <string, object> tileData = levelBoard[i];      // Pull out tile data

                int    c   = (int)tileData["x"];                           // Pull columns out of tile data
                int    r   = (int)tileData["y"];                           // Pull rows out
                string val = (string)tileData["val"];                      // pull val out
                if (String.IsNullOrEmpty(val))                             // if the tile has no data, do nothing
                {
                }
                else if (val == "%" || val == "Ice")                                            // if tile is ice,
                {
                    iceTiles[r][c] = Ice.createGameObject(iceGrid, r, c);                       // create ice tile on grid at tile coordinates
                }
                else if (val == "#" || val == "TransparentWall")                                // if tile is transparent wall,
                {
                    tiles[r][c] = TransparentWall.createGameObject(this.gameObject, r, c);      // insert transparent wall on grid.
                }
                else if (val == "=" || val == "Wall")                                           // if tile is wall,
                {
                    tiles[r][c] = Wall.createGameObject(this.gameObject, r, c);                 // insert wall on grid.
                }
                else if (val == "*" || val == "Anchor")                                         // if tile is anchor
                {
                    tiles[r][c] = Anchor.createGameObject(this.gameObject, r, c);               // insert anchor on grid.
                }
                else if (val == "&" || val == "RootedTile")                                     // if tile is rooted,
                {
                    tiles[r][c] = RootedTile.createGameObject(this.gameObject, r, c);           // insert rooted tile on grid
                }
                else if (val[0] >= 'a' && val[0] <= 'z')                                        // if the tile is an alphabet letter,
                {
                    int bonus = 0;                                                              // will contain bonus multiplier
                    if (tileData.ContainsKey("bonus"))                                          // if level data contains a bonus,
                    {
                        bonus = (int)tileData["bonus"];                                         // store bonus data
                    }
                    tiles[r][c] = WordTile.createGameObject(this.gameObject, r, c, val, bonus); // insert bonus at row and column location on grid

                    if (tileData.ContainsKey("crown"))                                          // if level data contains crown special objects
                    {
                        ((WordTile)tiles[r][c]).setCrown(true);                                 // insert crown in game grid
                    }
                }
            }
        }

        for (int r = 0; r < row; r++)
        {
            for (int c = 0; c < col; c++)
            {
                // for every grid tile,
                if (tiles[r][c] == null)                                            // if the tile has no data,
                {
                    tiles[r][c] = WordTile.createGameObject(this.gameObject, r, c); // generate a game tile piece with random properties
                }
            }
        }

        for (int r = 0; r < row; r++)
        {
            for (int c = 0; c < col; c++)
            {
                // for every grid tile,
                Tile tile = getTile(r, c);                                                                                             // pull the tile data
                if (tile.isMovable() || level.isTutorial)                                                                              // if tile can be moved or the level is a tutorial,
                {
                    TileBackground tb = (Instantiate(Resources.Load("TileBackground")) as GameObject).GetComponent <TileBackground>(); // create a tile background object; non-movable tiles do not get backgrounds
                    tb.transform.SetParent(gridBackground.transform);                                                                  // attach the background object to the tile
                    tb.init(r, c);                                                                                                     // begin rendering the background object
                }
            }
        }
        updateMoveUI();    // update the number of moves left in the level
        updateBoardSize(); // change the board size? Function is not implemented
        updateText();      // update all words that are connected
        updateScore();     // update the user score
        gameController.user.logger(new Dictionary <string, object> {
            { "d1", "levelStart" }, { "d2", level.level }
        });                                                                                              // create a log for debugging purposes
    }