//public Boolean finish() //{ // int a = 0; // int b = 0; // return true; //} public void Shift(int value, Game3 games) { try { if (value < 0 || value > 15) { throw new ArgumentException(); } if (Math.Abs(GetSum(value) - GetSum(0)) == 1) { int tmp; int valueLoction = GetLocation(value); int zeroLocation = GetLocation(0); tmp = items[zeroLocation].value; items[zeroLocation].value = items[valueLoction].value; items[valueLoction].value = tmp; games.History(value); } else { throw new Exception(); } } catch (ArgumentException) { Console.WriteLine("Нет такого числа. "); Console.WriteLine(); } catch (Exception) { Console.WriteLine("Некуда двигать. "); Console.WriteLine(); } }
public void Shift(int value, Game3 games) { try { // Console.WriteLine(value); if (value < 0 || value > 15) { throw new ArgumentException(); } int zeroLoctionX = GetLoc(0).x; int zeroLoctionY = GetLoc(0).y; int ValueX = GetLoc(value).x; int ValueY = GetLoc(value).y; if ((ValueX == zeroLoctionX && (ValueY == zeroLoctionY - 1 || ValueY == zeroLoctionY + 1)) || (ValueY == zeroLoctionY && (ValueX == zeroLoctionX - 1 || ValueX == zeroLoctionX + 1))) { ItemsNew[zeroLoctionX, zeroLoctionY] = value; ItemsNew[ValueX, ValueY] = 0; var vere = ItemsValue[0]; ItemsValue[0] = ItemsValue[value]; ItemsValue[value] = vere; games.History(value); } else { throw new Exception(); } } catch (ArgumentException) { Console.WriteLine("Нет такого числа. "); Console.WriteLine(); } catch (Exception) { Console.WriteLine("Некуда двигать. "); Console.WriteLine(); } }