Esempio n. 1
0
        public static void SlidePieces(HandSlot insertedPiece, HandSlot pieceUnderIt)
        {
            int oldIndex = (int)insertedPiece.Tag;
            int newIndex = (int)pieceUnderIt.Tag;

            // If pieces are adjacent
            if (Math.Abs(newIndex - oldIndex) == 1)
            {
                SwapPieces(HandSlots[oldIndex], HandSlots[newIndex]);
                return;
            }

            // If moving to the right
            if (oldIndex < newIndex)
            {
                // Find empty space to the left
                if (TryToSlideLeft(oldIndex, newIndex)) return;
                // Find empty space to the right
                if (TryToSlideRight(oldIndex, newIndex)) return;
            }
            else
            {
                // Find empty space to the right
                if (TryToSlideRight(oldIndex, newIndex)) return;
                // Find empty space to the left
                if (TryToSlideLeft(oldIndex, newIndex)) return;
            }
        }
Esempio n. 2
0
        public static void SwapPieces(HandSlot a, HandSlot b)
        {
            var aIndex = (int)a.Tag;
            var bIndex = (int)b.Tag;
            a.Tag = bIndex;
            b.Tag = aIndex;
            HandSlots[aIndex] = b;
            HandSlots[bIndex] = a;
            if (a.IsPlaced == false) a.ReturnToOriginalPosition();
            if (b.IsPlaced == false) b.ReturnToOriginalPosition();

            /*var handSlotLetter = b.Letter;
            b.SetPiece(a.Letter);
            a.SetPiece(handSlotLetter);*/
        }
Esempio n. 3
0
 public static void CreateHand(Panel container)
 {
     for (int i = 0; i < Hand.PieceLimit; i++)
     {
         // Add to visuals
         var slot = new HandSlot
         {
             Width = Board.Board.SlotSize,
             Height = Board.Board.SlotSize,
             Location = CalculateLocation(i),
             Visible = true,
             
             Tag = i
         };
         HandSlots[i] = slot;
         container.Controls.Add(slot);
         container.Controls.SetChildIndex(slot, 0);
         slot.MakeMovable();
     }
 }