using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace jigsaw_puzzle
{
public class jigsaw
{
public static int p = 0; //記錄移動次數;
public static int X; //數組br[i]=0的下標;
public static char[] br = new char[9];
public static void Load() //加載隨機數
{
char[] ar = { '0', '1', '2', '3', '4', '5', '6', '7','8' };
int n = 8;
int n1 = 0;
while (n >= 0)
{
var MyRandom = new Random();
var i1 = MyRandom.Next(0, n);
br[n1] = ar[i1];
n1++;
for (int i = i1; i < n; i++)
{
ar[i] = ar[i + 1];
}
i1--; n--;
}
for (int i = 0; i < br.Length; i++)
{
if (br[i] == '0') X = i;
}
}
public static bool doCompared() //判斷是否完成遊戲
{
var MyInfo = new String(br);
if (MyInfo == "123456780")
return false;
else
return true;
}
public static void doLift() //0左移
{
if (X == 0 || X == 3 || X == 6)
{
Console.WriteLine(" 無法右移操作無效!請重新輸入(W,S,A,D,E):");
}
else
{
br[X] = br[X - 1];
br[X - 1] = '0';
X--;
p++;
}
}
public static void doRight() //0右移
{
if (X ==2 || X == 5 || X == 8)
{
Console.WriteLine(" 無法左移操作無效!請重新輸入(W,S,A,D,E):");
}
else
{
br[X] = br[X + 1];
br[X + 1] = '0';
X++; p++;
}
}
public static void doUp() //0上移
{
if (X == 0 || X == 1 || X == 2)
{
Console.WriteLine(" 無法下移操作無效!請重新輸入(W,S,A,D,E):");
}
else
{
br[X] = br[X - 3];
br[X - 3] = '0';
X = X - 3; p++;
}
}
public static void doDown() //0下移
{
if (X == 8 || X == 6 || X == 7)
{
Console.WriteLine(" 無法上移操作無效!請重新輸入(W,S,A,D,E):");
}
else
{
br[X] = br[X +3];
br[X + 3] = '0';
X = X + 3; p++;
}
}
}
}