Esempio n. 1
0
 //--------------------------------------------------------------------------------------------------------
 public void SlideTo(Hex destHex, BoardDirection direction)
 {
     swipeDestHex   = destHex;
     swipeDestNeko  = null;
     swipeDestPos   = destHex.transform.position;
     swipeDirection = direction;
 }
Esempio n. 2
0
 //--------------------------------------------------------------------------------------------------------
 public void SlideTo(HungryNeko neko, BoardDirection direction)
 {
     swipeDestHex   = null;
     swipeDestNeko  = neko;
     swipeDestPos   = neko.transform.position;
     swipeDirection = direction;
 }
Esempio n. 3
0
 //--------------------------------------------------------------------------------------------------------
 public void Initialize(Hex dropHex, int startLevel, BlockKind blockKind)
 {
     Level          = startLevel;
     swipeDestHex   = null;
     swipeDestPos   = null;
     swipeDestNeko  = null;
     Kind           = blockKind;
     BlocksToEat    = new List <Block>();
     gameController = GameObject.Find("Game Controller").GetComponent <GameController>();
     uiCanvas       = GameObject.Find("UI Canvas");
     name           = "Block on " + dropHex.name + ", Level " + Level + " (" + Kind + ")";
     UpdateDisplayImage();
     RandomizeSpeed();
     isInitialized = true;
 }
Esempio n. 4
0
    //--------------------------------------------------------------------------------------------------------
    private void ExecuteSwipe(out bool somethingMoved)
    {
        // 'captains' are the five hexes at the edge of the board in the swiped direction. this whole
        // function generally works by starting with those captain hexes then looking backwards to see
        // which blocks need to be 'sucked' in that direction.
        IEnumerable <Hex> captains  = from h in hexes where !h.NeighborDirections.Contains(swipeDir) select h;
        BoardDirection    searchDir = Opposite(swipeDir);

        somethingMoved = false;

        foreach (Hex captain in captains)
        {
            List <Hex> column     = HexesInDirection(captain, searchDir);
            HungryNeko activeNeko = AdjacentHungryNeko(captain, searchDir);

            for (int curHex = 0; curHex < column.Count; curHex++)
            {
                if (column[curHex].CurrentLevel == 0)
                {
                    // this is an empty hex - do nothing
                    continue;
                }

                int newHex = DeliciousEmptyHex(column, curHex);

                if (newHex == 0 &&
                    activeNeko != null &&
                    activeNeko.IsHungry &&
                    activeNeko.BlockLevel == column[curHex].CurrentLevel)
                {
                    // this is a block that's about to be fed to the neko
                    activeNeko.BlocksIncoming++;
                    column[curHex].Occupant.SlideTo(activeNeko, swipeDir);
                    column[curHex].Occupant = null;
                    somethingMoved          = true;
                }
                else if (newHex > 0 &&
                         column[curHex].CurrentLevel != ImageForBlockProgression.Count && // we not max level
                         column[newHex - 1].CurrentLevel != ImageForBlockProgression.Count && // they not max level
                         (column[curHex].CurrentLevel == column[newHex - 1].CurrentLevel || // equal lvl or wild
                          column[curHex].Occupant.Kind == BlockKind.WildCard ||
                          column[newHex - 1].Occupant.Kind == BlockKind.WildCard) &&
                         (column[curHex].Occupant.Kind == BlockKind.Normal || // both not wild
                          column[newHex - 1].Occupant.Kind == BlockKind.Normal))
                {
                    // this is a block that's about to combine with another block - either both blocks are
                    // the same level or one of them is a wild card (bot not both)
                    newHex -= 1;
                    int newLevel = column[curHex].Occupant.Kind == BlockKind.WildCard
                        ? column[newHex].Occupant.Level + 1
                        : column[curHex].Occupant.Level + 1;

                    column[curHex].Occupant.SlideTo(column[newHex], swipeDir);
                    column[curHex].Occupant.BlocksToEat.Add(column[newHex].Occupant);
                    GlobalFood.Add(column[newHex].Occupant);
                    column[curHex].Occupant.Level = newLevel;
                    column[curHex].Occupant.Kind  = BlockKind.Normal;
                    column[newHex].Occupant       = column[curHex].Occupant;
                    column[curHex].Occupant       = null;
                    somethingMoved = true;
                }
                else if (newHex < curHex)
                {
                    // this is a block that's just sliding with no interaction
                    column[newHex].Occupant = column[curHex].Occupant;
                    column[curHex].Occupant = null;
                    column[newHex].Occupant.SlideTo(column[newHex], swipeDir);
                    somethingMoved = true;
                }
                else if (newHex == curHex)
                {
                    // this block has nowhere to go
                    column[newHex].Occupant.SlideTo(column[newHex], swipeDir);
                }
            }
        }

        // if we have a hungry neko interval and no currently hungry nekos, increment our counter
        if (somethingMoved && CurrentHungryNekoInterval != -1 && !IsAnyNekoHungry())
        {
            MovesSinceLastHungryNeko++;

            if (MovesSinceLastHungryNeko > CurrentHungryNekoInterval)   // ignore this bs off-by-one err
            {
                MakeRandomNekoHungry();
            }
        }

        swipeDir = BoardDirection.Null;
    }