Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp1
- {
- class Program
- {
- class Fiftins
- {
- public int[,] arr = new int[4, 4];
- int line = 3;
- int row = 3;
- public int[,] equalArr = new int[4, 4] { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 }, { 13, 14, 15, 0 } };
- public Fiftins()
- {
- int num = 0;
- for (int i = 0; i < 4; i++)
- {
- for (int j = 0; j < 4; j++)
- {
- arr[i, j] = ++num;
- }
- }
- arr[3, 3] = 0;
- //MixNumbers();
- }
- public override string ToString()
- {
- string str = null;
- for (int i = 0; i < 4; i++)
- {
- str += "---------------------------------\n";
- for (int j = 0; j < 4; j++)
- {
- if (arr[i, j] == 0)
- str += "| \t";
- else
- str += $"|{arr[i, j]}\t";
- }
- str += "|\n";
- }
- str += "---------------------------------\n";
- return str;
- }
- void MixNumbers()
- {
- for (int i = 0; i < 1; i++)
- {
- Random random = new Random();
- int temper = random.Next(1, 4);
- switch (temper)
- {
- case 1:
- Move(0, 1);
- break;
- case 2:
- Move(0, -1);
- break;
- case 3:
- Move(-1, 0);
- break;
- case 4:
- Move(1, 0);
- break;
- }
- }
- }
- public bool Move(int moveLine, int moveRow)
- {
- if (line + moveLine >= 0 && (line + moveLine) < 4 && row + moveRow >= 0 && (row + moveRow) < 4)
- {
- int tempLine = line + moveLine;
- int tempRow = row + moveRow;
- arr[row, line] = arr[tempRow, tempLine];
- arr[tempRow, tempLine] = 0;
- line = tempLine;
- row = tempRow;
- return true;
- }
- else
- return false;
- }
- public bool Win()
- {
- //bool returnValueType = false;
- if (Array.Equals(arr,equalArr))
- {
- Console.Clear();
- Console.WriteLine("YOU WIN!");
- return true;
- }
- return false;
- }
- }
- static void Main(string[] args)
- {
- Fiftins fiftins = new Fiftins();
- //while (true)
- //{
- // Console.WriteLine(fiftins.ToString());
- // ConsoleKeyInfo keyInfo = Console.ReadKey();
- // Console.Clear();
- // if (keyInfo.Key == ConsoleKey.DownArrow)
- // {
- // fiftins.Move(0, 1);
- // }
- // if (keyInfo.Key == ConsoleKey.UpArrow)
- // {
- // fiftins.Move(0, -1);
- // }
- // if (keyInfo.Key == ConsoleKey.LeftArrow)
- // {
- // fiftins.Move(-1, 0);
- // }
- // if (keyInfo.Key == ConsoleKey.RightArrow)
- // {
- // fiftins.Move(1, 0);
- // }
- // fiftins.Win();
- //}
- Console.WriteLine(fiftins.arr.Equals(fiftins.equalArr));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement