Example #1
0
 private void onMouseUp()
 {
     fruitCellUp = GetFruiteCellFromMousePos(Input.mousePosition);
     //ScoreScript.myMovesAmout++; script to increase the player score.
     if (fruitCellUp == null)
     {
         //Prevents the player from droping powerUp tokens out of bounds.
         fruitCellDown.foodSprite.gameObject.transform.localPosition = Vector3.zero;
     }
     if (fruitCellUp.IsNeiborCell(fruitCellDown.gridPos))
     {
         if (fruitCellDown == null)
         {
             return;
         }
         //swaps the foodtype.
         FoodCell.TokenType temp = fruitCellDown.typeOfToken;
         fruitCellDown.typeOfToken = fruitCellUp.typeOfToken;
         fruitCellUp.typeOfToken   = temp;
         //swaps the sprites.
         Sprite tempSprite = fruitCellDown.foodSprite.sprite;
         fruitCellDown.foodSprite.sprite = fruitCellUp.foodSprite.sprite;
         fruitCellUp.foodSprite.sprite   = tempSprite;
         //sets the picked up fruit sprite back into it's cell.
         fruitCellDown.foodSprite.gameObject.transform.localPosition = Vector3.zero;
     }
     else
     {
         //fruitCellDown.foodSprite.gameObject.transform.localPosition = Vector3.zero;
         Health.life -= 1;
     }
     gridSolvedTimesInARow = 0;
     StartCoroutine(WaitAndSolveGrid());
     StartCoroutine(WaitAndDamagePlayer());
 }
Example #2
0
 private void onMouseUp()
 {
     if (Time.timeScale != 0)
     {
         fruitCellUp = GetFruiteCellFromMousePos(Input.mousePosition);
         Debug.Log(fruitCellUp);
         //ScoreScript.myMovesAmout++; script to increase the player score.
         if (fruitCellUp == null)
         {
             //Prevents the player from droping powerUp tokens out of bounds.
             fruitCellDown.foodSprite.gameObject.transform.localPosition = Vector3.zero;
         }
         if (fruitCellUp.IsNeiborCell(fruitCellDown.gridPos))
         {
             if (fruitCellDown == null)
             {
                 return;
             }
             //swaps the foodtype.
             FoodCell.TokenType temp = fruitCellDown.typeOfToken;
             fruitCellDown.typeOfToken = fruitCellUp.typeOfToken;
             fruitCellUp.typeOfToken   = temp;
             //swaps the sprites.
             Sprite tempSprite = fruitCellDown.foodSprite.sprite;
             fruitCellDown.foodSprite.sprite = fruitCellUp.foodSprite.sprite;
             fruitCellUp.foodSprite.sprite   = tempSprite;
             //sets the picked up fruit sprite back into it's cell.
             fruitCellDown.foodSprite.gameObject.transform.localPosition = Vector3.zero;
             if (FirstSolveGridHasPassed)
             {
                 //Instantiate(gemOne, gemSpawnOne.position, gemSpawnOne.rotation);
                 //Instantiate(gemTwo, gemSpawnTwo.position, gemSpawnTwo.rotation);
                 //Instantiate(gemThree, gemSpawnThree.position, gemSpawnThree.rotation);
             }
         }
         else
         {
             fruitCellDown.foodSprite.gameObject.transform.localPosition = Vector3.zero;
             //Health.life -= 1;
         }
         gridSolvedTimesInARow = 0;
         StartCoroutine(WaitAndSolveGrid());
         StartCoroutine(WaitAndDamagePlayer());
     }
 }
Example #3
0
 private void onMouseUp()
 {
     fruitCellUp = GetFruiteCellFromMousePos(Input.mousePosition);
     Debug.Log("fruit cell up: " + fruitCellUp);
     if (fruitCellUp == null && fruitCellDown)
     {
         //Prevents the player from droping powerUp tokens out of bounds.
         fruitCellDown.foodSprite.gameObject.transform.localPosition = Vector3.zero;
     }
     if (fruitCellUp.IsNeiborCell(fruitCellDown.gridPos))
     {
         if (fruitCellDown == null)
         {
             return;
         }
         //swaps the foodtype.
         FoodCell.TokenType temp = fruitCellDown.typeOfToken;
         fruitCellDown.typeOfToken = fruitCellUp.typeOfToken;
         fruitCellUp.typeOfToken   = temp;
         //swaps the sprites.
         Sprite tempSprite = fruitCellDown.foodSprite.sprite;
         fruitCellDown.foodSprite.sprite = fruitCellUp.foodSprite.sprite;
         fruitCellUp.foodSprite.sprite   = tempSprite;
         //sets the picked up fruit sprite back into it's cell.
         fruitCellDown.foodSprite.gameObject.transform.localPosition = Vector3.zero;
     }
     else
     {
         fruitCellDown.foodSprite.gameObject.transform.localPosition = Vector3.zero;
     }
     gridSolvedTimesInARow = 0;
     if (waitAndReturnTile >= 1)
     {
         fruitCellDown.foodSprite.gameObject.transform.localPosition = Vector3.zero;
     }
     StartCoroutine(WaitAndSolveGrid());
 }
Example #4
0
    //this function solves the grid but looping using for loops to cheak every cell and cheak weather the cells beside or on the bottom or top of the cell match the cell.
    private void SolveGrid()
    {
        gridSolvedTimesInARow += 1;
        FoodCell.TokenType TokenTypeForPowerUpDrop;
        //Debug.Log("solveGrid");
        //two for loops used to cheak through every grid cell
        for (int i = 0; i < widthOfBoard; i++)
        {
            for (int j = 0; j < heightOfBoard; j++)
            {
                //Debug.Log("cheaking cell " + i + "," + j);
                FoodCell.TokenType tempFood                = tiles[i, j].typeOfToken;
                FoodCell           currentFruitCell        = tiles[i, j];
                List <FoodCell>    matchingCellsToTheRight = new List <FoodCell>();
                List <FoodCell>    matchingCellsUp         = new List <FoodCell>();
                FoodCell           neiborFruitCell         = currentFruitCell.getNeiborRight(tiles);
                //uses a while loop to cheak keep cheaking for matches as long as their is a neiboring Cell to the one being cheaked.
                while (neiborFruitCell != null)
                {
                    //if statment used to cheak if cell being cheaked has a match with a horizontal cell.
                    if (currentFruitCell.typeOfToken == neiborFruitCell.typeOfToken)
                    {
                        //Debug.Log("H-match- " + neiborFruitCell.gridPos);
                        matchingCellsToTheRight.Add(neiborFruitCell);
                        neiborFruitCell = neiborFruitCell.getNeiborRight(tiles);
                    }
                    //breaks out of the stament if their is no match.
                    else
                    {
                        break;
                    }
                }
                neiborFruitCell = currentFruitCell.getNeiborUp(tiles);
                while (neiborFruitCell != null)
                {
                    if (currentFruitCell.typeOfToken == neiborFruitCell.typeOfToken)
                    {
                        //if statment used to cheak if cell being cheaked has a match with a vertical cell.
                        //Debug.Log("V-match- " + neiborFruitCell.gridPos);
                        matchingCellsUp.Add(neiborFruitCell);
                        neiborFruitCell = neiborFruitCell.getNeiborUp(tiles);
                    }
                    else
                    {
                        break;
                    }
                }
                //uses bools to tell game if the food in a cell needs to be replaced by another food when a match is found
                bool horizontalSolved = false;
                bool verticalSolved   = false;
                if (matchingCellsToTheRight.Count >= 2)
                {
                    horizontalSolved = true;
                    //iterate over this list and replace the food type with a new food type.
                    for (int b = 0; b < matchingCellsToTheRight.Count; b++)
                    {
                        FoodCell fruitCellToSolve = matchingCellsToTheRight[b];
                        //Debug.Log("cells to the right match");
                        StartCoroutine(fruitCellToSolve.DoSolveFruit(this));
                    }
                }
                if (matchingCellsUp.Count >= 2)
                {
                    verticalSolved = true;
                    //iterate over this list and replace the food type with a new food type.
                    for (int b = 0; b < matchingCellsUp.Count; b++)
                    {
                        FoodCell fruitCellToSolve = matchingCellsUp[b];
                        //Debug.Log("cells up match");
                        StartCoroutine(fruitCellToSolve.DoSolveFruit(this));
                    }
                }
                //if we solved any fruit cells above or to the right thne break out of this
                if (horizontalSolved || verticalSolved)
                {
                    thereWasSomethingToSolveInTheGrid = true;
                    //randomFoodSelection called to change food that matches.
                    //this uses a coroutine from FruitCell.
                    StartCoroutine(currentFruitCell.DoSolveFruit(this));
                    //uses myScoreValue from ScoreScript to change the score when grid is solved
                    //ScoreScript.myScoreValue++;
                    //restarts the solving prosses.
                    StartCoroutine(WaitAndSolveGrid());
                    TokenTypeForPowerUpDrop = currentFruitCell.typeOfToken;
                    int probabilityOfPowerUpDrop = Random.Range(0, 2);
                    if (probabilityOfPowerUpDrop == 1 && FirstSolveGridHasPassed)
                    {
                        switch (TokenTypeForPowerUpDrop)
                        {
                        case FoodCell.TokenType.Undefined:
                            break;

                        case FoodCell.TokenType.Armour:
                            Instantiate(armour, powerUpSpawnPos, powerUpRotation);
                            break;

                        case FoodCell.TokenType.Sword:
                            Instantiate(swordWeapon, powerUpSpawnPos, powerUpRotation);
                            break;

                        case FoodCell.TokenType.Cherry:
                            Instantiate(cherryPowerUp, powerUpSpawnPos, powerUpRotation);
                            break;

                        case FoodCell.TokenType.Apple:
                            Instantiate(applePowerUp, powerUpSpawnPos, powerUpRotation);
                            break;

                        case FoodCell.TokenType.InvisibilityPotion:
                            Instantiate(invisablePotion, powerUpSpawnPos, powerUpRotation);
                            break;
                        }
                    }
                    break;
                }
                else
                {
                    thereWasSomethingToSolveInTheGrid = false;
                }
            }
        }
    }
Example #5
0
 //this function solves the grid but looping using for loops to cheak every cell and cheak weather the cells beside or on the bottom or top of the cell match the cell.
 private void SolveGrid()
 {
     gridSolvedTimesInARow += 1;
     //Debug.Log("solveGrid");
     //two for loops used to cheak through every grid cell
     for (int i = 0; i < widthOfBoard; i++)
     {
         for (int j = 0; j < heightOfBoard; j++)
         {
             //Debug.Log("cheaking cell " + i + "," + j);
             FoodCell.TokenType tempFood                = tiles[i, j].typeOfToken;
             FoodCell           currentFruitCell        = tiles[i, j];
             List <FoodCell>    matchingCellsToTheRight = new List <FoodCell>();
             List <FoodCell>    matchingCellsUp         = new List <FoodCell>();
             FoodCell           neiborFruitCell         = currentFruitCell.getNeiborRight(tiles);
             //uses a while loop to cheak keep cheaking for matches as long as their is a neiboring Cell to the one being cheaked.
             while (neiborFruitCell != null)
             {
                 //if statment used to cheak if cell being cheaked has a match with a horizontal cell.
                 if (currentFruitCell.typeOfToken == neiborFruitCell.typeOfToken)
                 {
                     //Debug.Log("H-match- " + neiborFruitCell.gridPos);
                     matchingCellsToTheRight.Add(neiborFruitCell);
                     neiborFruitCell = neiborFruitCell.getNeiborRight(tiles);
                 }
                 //breaks out of the stament if their is no match.
                 else
                 {
                     break;
                 }
             }
             neiborFruitCell = currentFruitCell.getNeiborUp(tiles);
             while (neiborFruitCell != null)
             {
                 if (currentFruitCell.typeOfToken == neiborFruitCell.typeOfToken)
                 {
                     //if statment used to cheak if cell being cheaked has a match with a vertical cell.
                     //Debug.Log("V-match- " + neiborFruitCell.gridPos);
                     matchingCellsUp.Add(neiborFruitCell);
                     neiborFruitCell = neiborFruitCell.getNeiborUp(tiles);
                 }
                 else
                 {
                     break;
                 }
             }
             //uses bools to tell game if the food in a cell needs to be replaced by another food when a match is found
             bool horizontalSolved = false;
             bool verticalSolved   = false;
             if (matchingCellsToTheRight.Count >= 2)
             {
                 horizontalSolved = true;
                 //iterate over this list and replace the food type with a new food type.
                 for (int b = 0; b < matchingCellsToTheRight.Count; b++)
                 {
                     FoodCell fruitCellToSolve = matchingCellsToTheRight[b];
                     //Debug.Log("cells to the right match");
                     StartCoroutine(fruitCellToSolve.doSolveFruitTwo(this));
                 }
             }
             if (matchingCellsUp.Count >= 2)
             {
                 verticalSolved = true;
                 //iterate over this list and replace the food type with a new food type.
                 for (int b = 0; b < matchingCellsUp.Count; b++)
                 {
                     FoodCell fruitCellToSolve = matchingCellsUp[b];
                     //Debug.Log("cells up match");
                     StartCoroutine(fruitCellToSolve.doSolveFruitTwo(this));
                 }
             }
             //if we solved any fruit cells above or to the right thne break out of this
             if (horizontalSolved || verticalSolved)
             {
                 thereWasSomethingToSolveInTheGrid = true;
                 //randomFoodSelection called to change food that matches.
                 //this uses a coroutine from FruitCell.
                 StartCoroutine(currentFruitCell.doSolveFruitTwo(this));
                 //restarts the solving prosses.
                 myShipFuel.FuelAmount += 0.2f;
                 StartCoroutine(WaitAndSolveGrid());
             }
             else
             {
                 thereWasSomethingToSolveInTheGrid = false;
             }
         }
     }
 }