Ejemplo n.º 1
0
    private void MovePeg(int targetIndex, Directions dir)
    {
        bool canMoveInDir;

        if (currentPeg != null)
        {
            if (currentPeg.availableDirDict.TryGetValue(dir, out canMoveInDir))
            {
                if (canMoveInDir)
                {
                    if (!boardSlots[targetIndex].isFilled)
                    {
                        if (PegHasNeighbor(currentPeg.currentIndex, dir))
                        {
                            boardSlots[currentPeg.currentIndex].isFilled = false;
                            boardSlots[targetIndex].isFilled             = true;
                            pegLayout[currentPeg.currentIndex]           = null;

                            currentPeg.currentIndex     = targetIndex;
                            currentPeg.row              = boardSlots[targetIndex].row;
                            currentPeg.availableDirDict = boardSlots[targetIndex].moveDict;

                            boardSlots[jumpedPeg.currentIndex].isFilled = false;
                            pegLayout[jumpedPeg.currentIndex]           = null;
                            pegLayout[targetIndex] = currentPeg;

                            currentPeg.SetMoving(boardSlots[currentPeg.currentIndex].indicator.transform.position, true);
                            Destroy(jumpedPeg.gameObject);
                        }
                    }
                }
            }
            else
            {
                Debug.LogWarning("Move dictionary did not contain key for given direction.");
            }
        }
    }