void SlotClicked(EmptySlot slot) { int midSlotIndex = (_currentPeg.Slot.Index + slot.Index) / 2; EmptySlot midSlot = Slots[midSlotIndex]; //Debug.Log("start index: " + _currentPeg.Slot.Index + " target index: " + slot.Index + " middle slot: " + midSlotIndex); if (CanMove(_currentPeg.Slot, midSlot, slot)) { _currentPeg.Slot.ClearPeg(); slot.SetPeg(_currentPeg); _currentPeg.SetInactive(); midSlot.ClearPeg(); _pegCount--; if (_pegCount == PEGS_LEFT_TO_WIN) { EndGame(true); } else if (CheckForNoMoreMoves()) { EndGame(false); } } }
public void Restart() { int index = 0; EmptySlot slot = null; for (index = 0; index < Slots.Length; index++) { slot = Slots[index]; slot.Index = index; slot.ClearPeg(); } Peg peg = null; _pegCount = 0; for (index = Slots.Length - 1; index > 0; index--) { peg = Pegs[_pegCount]; peg.SetInactive(); Slots[index].SetPeg(peg); _pegCount++; } }