protected override void PopulateTile(DrugTile newTile)
    {
        // with a % chance, or always if either the board is empty or the number of drug families is greater than a certain amount
        if ((Random.Range(0f, 1f) > 0.5f && tilesOnScreen.Count != 0) || (GetDrugFamilyCount() > maxDrugFamilies))
        {
            // create a unique set of tiles on the board
            List <string> names = new List <string>();
            foreach (DrugTile tile in tilesOnScreen)
            {
                if (!names.Contains(tile.drugName))
                {
                    names.Add(tile.drugName);
                }
            }

            // pick a name from the set
            string newName = names[Random.Range(0, names.Count)];
            newTile.drugMatches = drugnameToMatches[newName];
            newTile.drugName    = FewerOccurrences(newTile.drugMatches[0], newTile.drugMatches[1]);
        }
        else //otherwise add a random card
        {
            List <string> drugFamily = drugs[Random.Range(0, drugs.Count)];
            newTile.drugMatches = drugFamily;
            newTile.drugName    = drugFamily[Random.Range(0, drugFamily.Count)];
        }
        SetColor(newTile);
    }
 // slides each tile on the board in the passed direction
 void Slide(SlideController.Direction dir)
 {
     timeSinceSlide = 0f;
     if (!CanMove(dir))
     {
         return;
     }
     foreach (Transform cell in GetCells())                                                                                 // for each cell on the board
     {
         GridPosition pos = cell.GetComponentInParent <GridPosition>();                                                     // get its grid position
         if (!pos.GetNext(dir))                                                                                             // if this position is on the edge (has no next cell in the passed direction)
         {
             for (GridPosition nextMover = pos.GetOpposite(dir); nextMover != null; nextMover = nextMover.GetOpposite(dir)) // for each position, traveling in the opposite direction
             {
                 DrugTile tileToMove = nextMover.gameObject.transform.GetComponentInChildren <DrugTile>();
                 if (tileToMove != null)
                 {
                     if (tileToMove.Slide(dir)) // returns true if tile matched
                     {
                         IncrementScore(1);
                     }
                 }
             }
         }
     }
     CreateCard(dir); // create a card at the opposite direction of the swipe
     if (CheckGameOver())
     {
         Invoke("GameOver", 1);
     }
 }
    protected void TryMatch()
    {
        if (firstSelected.CheckMatch(secondSelected))
        {
            IncrementScore(1);
            UpdateSpawnTime();

            tilesOnScreen.Remove(firstSelected);
            tilesOnScreen.Remove(secondSelected);

            MatchSFX.Play();
            firstSelected.GenerateMatchParticles();
            secondSelected.GenerateMatchParticles();
            Destroy(firstSelected.gameObject);
            Destroy(secondSelected.gameObject);
        }
        else
        {
            Debug.Log("no");
            firstSelected.UnSelect();
            secondSelected.UnSelect();
        }
        firstSelected  = null;
        secondSelected = null;
    }
Beispiel #4
0
 // returns true if this drug matches another drugtile
 public bool CheckMatch(DrugTile other)
 {
     if (drugMatches.Contains(other.nameLabelTMP.text) && nameLabelTMP.text != other.nameLabelTMP.text)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
    // populate a new drug tile with a new drug
    // can be overloaded for different behavior in various game modes
    protected virtual void PopulateTile(DrugTile newTile)
    {
        int    index   = Random.Range(0, currentDrugs.Count);
        string newName = currentDrugs[index];

        currentDrugs.RemoveAt(index);
        if (currentDrugs.Count == 0)
        {
            currentDrugs = SampleDrugs(8);
        }
        newTile.drugName    = newName;
        newTile.drugMatches = drugnameToMatches[newName];
        SetColor(newTile);
    }
Beispiel #6
0
 public override void CardTapped(DrugTile card)
 {
     if (firstSelected == null)
     {
         firstSelected = card;
         firstSelected.Select();
     }
     else
     {
         secondSelected = card;
         secondSelected.Select();
         TryMatch();
     }
 }
 // returns true if a move in the given direction is valid, false otherwise
 bool CanMove(SlideController.Direction dir)
 {
     foreach (Transform cell in GetCells())                                                                                 // for each cell on the board
     {
         GridPosition pos = cell.GetComponentInParent <GridPosition>();                                                     // get its grid position
         if (pos && !pos.GetNext(dir))                                                                                      // if this position is on the edge (has no next cell in the passed direction)
         {
             for (GridPosition nextMover = pos.GetOpposite(dir); nextMover != null; nextMover = nextMover.GetOpposite(dir)) // for each position, traveling in the opposite direction
             {
                 DrugTile tileToMove = nextMover.gameObject.transform.GetComponentInChildren <DrugTile>();
                 if (tileToMove != null)
                 {
                     if (tileToMove.CanSlide(dir))
                     {
                         return(true);
                     }
                 }
             }
         }
     }
     return(false);
 }
Beispiel #8
0
    protected void TryMatch()
    {
        if (firstSelected.CheckMatch(secondSelected))
        {
            IncrementScore(1);

            tilesOnScreen.Remove(firstSelected);
            tilesOnScreen.Remove(secondSelected);

            firstSelected.markedToDestroy  = true;
            secondSelected.markedToDestroy = true;

            MatchSFX.Play();
            firstSelected.GenerateMatchParticles();
            secondSelected.GenerateMatchParticles();
            Destroy(firstSelected.gameObject);
            Destroy(secondSelected.gameObject);

            CreateCard();
            CreateCard();
        }
        else
        {
            if (firstSelected.drugName != secondSelected.drugName)
            {
                livesLeft    -= 1;
                secondaryText = "Lives: " + livesLeft;
                if (livesLeft == 0)
                {
                    Invoke("GameOver", 1);
                }
            }
            firstSelected.UnSelect();
            secondSelected.UnSelect();
        }
        firstSelected  = null;
        secondSelected = null;
    }
 public void SetColor(DrugTile tile)
 {
     tile.GetComponent <Image>().color = drugnameToColor[tile.drugName];
 }
Beispiel #10
0
 public virtual void CardTapped(DrugTile card)
 {
     // Debug.Log("wrong");
 }