Advertisement
Timtsa

Untitled

May 3rd, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.26 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp1
  8. {
  9.     class Program
  10.     {
  11.         class Fiftins
  12.         {
  13.           public  int[,] arr = new int[4, 4];
  14.             int line = 3;
  15.             int row = 3;
  16.             public int[,] equalArr = new int[4, 4] { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 }, { 13, 14, 15, 0 } };
  17.             public Fiftins()
  18.             {
  19.                 int num = 0;
  20.                 for (int i = 0; i < 4; i++)
  21.                 {
  22.                     for (int j = 0; j < 4; j++)
  23.                     {
  24.                         arr[i, j] = ++num;
  25.                     }
  26.                 }
  27.                 arr[3, 3] = 0;
  28.                 //MixNumbers();
  29.             }
  30.                        
  31.             public override string ToString()
  32.             {
  33.                 string str = null;
  34.                 for (int i = 0; i < 4; i++)
  35.                 {
  36.  
  37.                     str += "---------------------------------\n";
  38.  
  39.                     for (int j = 0; j < 4; j++)
  40.                     {
  41.                         if (arr[i, j] == 0)
  42.                             str += "| \t";
  43.                         else    
  44.                         str += $"|{arr[i, j]}\t";
  45.                     }
  46.                     str += "|\n";
  47.  
  48.                 }
  49.                 str += "---------------------------------\n";
  50.                 return str;
  51.  
  52.             }
  53.  
  54.             void MixNumbers()
  55.             {
  56.                 for (int i = 0; i < 1; i++)
  57.                 {
  58.  
  59.                     Random random = new Random();
  60.                     int temper = random.Next(1, 4);
  61.                     switch (temper)
  62.                     {
  63.                         case 1:
  64.                             Move(0, 1);
  65.  
  66.  
  67.                             break;
  68.                         case 2:
  69.                             Move(0, -1);
  70.  
  71.                             break;
  72.  
  73.                         case 3:
  74.  
  75.                             Move(-1, 0);
  76.                             break;
  77.  
  78.                         case 4:
  79.  
  80.                             Move(1, 0);
  81.  
  82.                             break;
  83.                     }
  84.  
  85.                 }
  86.             }
  87.  
  88.             public bool Move(int moveLine, int moveRow)
  89.             {
  90.                 if (line + moveLine >= 0 && (line + moveLine) < 4 && row + moveRow >= 0 && (row + moveRow) < 4)
  91.                 {
  92.                     int tempLine = line + moveLine;
  93.                     int tempRow = row + moveRow;
  94.                     arr[row, line] = arr[tempRow, tempLine];
  95.                     arr[tempRow, tempLine] = 0;
  96.                     line = tempLine;
  97.                     row = tempRow;
  98.  
  99.  
  100.                     return true;
  101.                 }
  102.                 else
  103.                     return false;
  104.             }
  105.  
  106.             public bool Win()
  107.             {
  108.  
  109.                 //bool returnValueType = false;
  110.                 if (Array.Equals(arr,equalArr))
  111.                 {
  112.                     Console.Clear();
  113.                     Console.WriteLine("YOU WIN!");
  114.                     return true;
  115.                 }
  116.  
  117.                 return false;
  118.             }
  119.  
  120.         }
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.         static void Main(string[] args)
  129.         {
  130.  
  131.             Fiftins fiftins = new Fiftins();
  132.             //while (true)
  133.             //{
  134.             //    Console.WriteLine(fiftins.ToString());
  135.  
  136.             //    ConsoleKeyInfo keyInfo = Console.ReadKey();
  137.             //    Console.Clear();
  138.  
  139.             //    if (keyInfo.Key == ConsoleKey.DownArrow)
  140.             //    {
  141.             //        fiftins.Move(0, 1);
  142.             //    }
  143.  
  144.             //    if (keyInfo.Key == ConsoleKey.UpArrow)
  145.             //    {
  146.             //        fiftins.Move(0, -1);
  147.             //    }
  148.  
  149.             //    if (keyInfo.Key == ConsoleKey.LeftArrow)
  150.             //    {
  151.             //        fiftins.Move(-1, 0);
  152.             //    }
  153.  
  154.             //    if (keyInfo.Key == ConsoleKey.RightArrow)
  155.             //    {
  156.             //       fiftins.Move(1, 0);
  157.             //    }
  158.             //    fiftins.Win();
  159.  
  160.             //}
  161.            
  162.             Console.WriteLine(fiftins.arr.Equals(fiftins.equalArr));
  163.         }
  164.     }
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement