kokusz19

MestInt.Kereses.17

May 24th, 2018
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 9.27 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. /*
  8.  *     1 5 3 4 3 6 7 1 1 6
  9.        4 4 3 4 2 6 2 6 2 5
  10.        1 3 9 4 5 2 4 2 9 5
  11.        5 2 3 5 5 6 4 6 2 4
  12.        1 3 3 2 5 6 5 2 3 2
  13.        2 5 2 5 5 6 4 8 6 1
  14.        9 2 3 6 5 6 2 2 2 *
  15. */
  16.  
  17. namespace Kereses_beadando
  18. {
  19.     class Elem
  20.     {
  21.         public int ertek;
  22.         public bool lose;
  23.         public String nyerout;
  24.  
  25.         public Elem(char ertek)
  26.         {
  27.             if (Char.IsDigit(ertek))
  28.             {
  29.                 this.ertek = (int)Char.GetNumericValue(ertek);
  30.                 this.lose = false;
  31.             }
  32.             else
  33.             {
  34.                 this.ertek = 0;
  35.                 this.lose = true;
  36.                 this.nyerout = null;
  37.             }
  38.         }
  39.     }                                                   // Elem típus létrehozása (int érték, bool win?)
  40.  
  41.     class Program {    
  42.        
  43.      
  44.         static void populateArray(char[][] array)
  45.         {
  46.             array[0] = new char[] { '1', '5', '3', '4', '3', '6', '7', '1', '1', '6' };
  47.             array[1] = new char[] { '4', '4', '3', '4', '2', '6', '2', '6', '2', '5' };
  48.             array[2] = new char[] { '1', '3', '9', '4', '5', '2', '4', '2', '9', '5' };
  49.             array[3] = new char[] { '5', '2', '3', '5', '5', '6', '4', '6', '2', '4' };
  50.             array[4] = new char[] { '1', '3', '3', '2', '5', '6', '5', '2', '3', '2' };
  51.             array[5] = new char[] { '2', '5', '2', '5', '5', '6', '4', '8', '6', '1' };
  52.             array[6] = new char[] { '9', '2', '3', '6', '5', '6', '2', '2', '2', '*' };
  53.         }
  54.  
  55.         static void populateTomb(Elem[][] tomb, char[][] array)
  56.         {
  57.             for (int i = 0; i < 7; i++)
  58.             {
  59.                 tomb[i] = new Elem[10];
  60.                 for (int j = 0; j < 10; j++)
  61.                 {
  62.                     tomb[i][j] = new Elem(array[i][j]);
  63.                 }
  64.             }
  65.         }
  66.  
  67.         static void checkWhereLoseHappens(Elem[][] tomb)
  68.         {
  69.             for (int k = 0; k < 7 * 10; k++)
  70.             {   // annyiszor fusson le a program, ahány eleme van a táblának, hogy az utolsó elem (win?) lefrissülése után frissítsen az összes elemen egyet
  71.  
  72.                 for (int i = 6; i >= 0; i--)
  73.                 {
  74.                     for (int j = 9; j >= 0; j--)
  75.                     {
  76.                         String temp;
  77.                         if (tomb[i][j].ertek == 0)
  78.                         {
  79.                             tomb[i][j].nyerout = "(" + (i + 1) + ", " + (j + 1) + ")";
  80.                             continue;
  81.                         }
  82.  
  83.                         else
  84.                         {
  85.                             if (i - tomb[i][j].ertek >= 0 && j - tomb[i][j].ertek >= 0)             // Upper row check
  86.                             {
  87.                                 if (tomb[i - tomb[i][j].ertek][j - tomb[i][j].ertek].lose == true)
  88.                                 {
  89.                                     tomb[i][j].nyerout = tomb[i - tomb[i][j].ertek][j - tomb[i][j].ertek].nyerout + "-> (" + (i + 1) + ", " + (j + 1) + ")";
  90.                                     tomb[i][j].lose = true;
  91.                                     goto kilep;
  92.                                 }
  93.                             }
  94.                             else if (i - tomb[i][j].ertek >= 0)
  95.                             {
  96.                                 if (tomb[i - tomb[i][j].ertek][j].lose == false)
  97.                                 {
  98.                                     temp = tomb[i - tomb[i][j].ertek][j].nyerout + "-> (" + (i + 1) + ", " + (j + 1) + ")";
  99.                                     tomb[i][j].nyerout = temp;
  100.                                     tomb[i][j].lose = true;
  101.                                     goto kilep;
  102.                                 }
  103.                             }
  104.                             else if (i - tomb[i][j].ertek >= 0 && j + tomb[i][j].ertek < 10)
  105.                             {
  106.                                 if (tomb[i - tomb[i][j].ertek][j + tomb[i][j].ertek].lose == false)
  107.                                 {
  108.                                     temp = tomb[i - tomb[i][j].ertek][j + tomb[i][j].ertek].nyerout + "-> (" + (i + 1) + ", " + (j + 1) + ")";
  109.                                     tomb[i][j].nyerout = temp;
  110.                                     tomb[i][j].lose = true;
  111.                                     goto kilep;
  112.                                 }
  113.                             }
  114.  
  115.                             else if (j - tomb[i][j].ertek >= 0)                                     // Current row check
  116.                             {
  117.                                 if (tomb[i][j - tomb[i][j].ertek].lose == false)
  118.                                 {
  119.                                     temp = tomb[i][j - tomb[i][j].ertek].nyerout + "-> (" + (i + 1) + ", " + (j + 1) + ")";
  120.                                     tomb[i][j].nyerout = temp;
  121.                                     tomb[i][j].lose = true;
  122.                                     goto kilep;
  123.                                 }
  124.                             }
  125.                             else if (j + tomb[i][j].ertek < 10)
  126.                             {
  127.                                 if (tomb[i][j + tomb[i][j].ertek].lose == false)
  128.                                 {
  129.                                     temp = tomb[i][j + tomb[i][j].ertek].nyerout + "-> (" + (i + 1) + ", " + (j + 1) + ")";
  130.                                     tomb[i][j].nyerout = temp;
  131.                                     tomb[i][j].lose = true;
  132.                                     goto kilep;
  133.                                 }
  134.                             }
  135.  
  136.                             else if (i + tomb[i][j].ertek < 7 && j - tomb[i][j].ertek >= 0)         // Below row check
  137.                             {
  138.                                 if (tomb[i + tomb[i][j].ertek][j - tomb[i][j].ertek].lose == false)
  139.                                 {
  140.                                     temp = tomb[i + tomb[i][j].ertek][j - tomb[i][j].ertek].nyerout + "-> (" + (i + 1) + ", " + (j + 1) + ")";
  141.                                     tomb[i][j].nyerout = temp;
  142.                                     tomb[i][j].lose = true;
  143.                                     goto kilep;
  144.                                 }
  145.                             }
  146.                             else if (i + tomb[i][j].ertek < 7)
  147.                             {
  148.                                 if (tomb[i + tomb[i][j].ertek][j].lose == false)
  149.                                 {
  150.                                     tomb[i][j].nyerout = tomb[i + tomb[i][j].ertek][j].nyerout + "-> (" + (i + 1) + ", " + (j + 1) + ")";
  151.                                     tomb[i][j].lose = true;
  152.                                     goto kilep;
  153.                                 }
  154.                             }
  155.                             else if (i + tomb[i][j].ertek < 7 && j + tomb[i][j].ertek < 10)
  156.                             {
  157.                                 if (tomb[i + tomb[i][j].ertek][j + tomb[i][j].ertek].lose == false)
  158.                                 {
  159.                                     temp = tomb[i + tomb[i][j].ertek][j + tomb[i][j].ertek] + "-> (" + (i + 1) + ", " + (j + 1) + ")";
  160.                                     tomb[i][j].nyerout = temp;
  161.                                     tomb[i][j].lose = true;
  162.                                     goto kilep;
  163.                                 }
  164.                             }
  165.  
  166.                         kilep:;
  167.                         }       // Lose check row by row, then col by col
  168.                     }
  169.                 }
  170.             }
  171.         }
  172.  
  173.         static void Main(string[] args)
  174.         {
  175.             char[][] array = new char[7][];
  176.             populateArray(array);
  177.  
  178.             Elem[][] tomb = new Elem[7][];
  179.             populateTomb(tomb, array);
  180.            
  181.             checkWhereLoseHappens(tomb);
  182.            
  183.  
  184.  
  185.             for (int i = 0; i < 7; i++)
  186.             {
  187.                 if(i == 0)
  188.                     Console.WriteLine("\t1\t2\t3\t4\t5\t6\t7\t8\t9\t10\n----------------------------------------------------------------------------------");
  189.                 Console.Write((i+1) + ". |\t");
  190.                 for (int j = 0; j < 10; j++)
  191.                 {
  192.                     Console.Write(array[i][j] + "\t");
  193.                 }
  194.                 Console.WriteLine();
  195.             }       // (char[][]) Array kiíratása
  196.            
  197.            
  198.            
  199.             /*
  200.             Console.WriteLine("Adjon meg egy sor, mely egy elemere kivancsi: ");
  201.             int a = Int32.Parse(Console.ReadLine());
  202.             Console.WriteLine("Adja meg a sor egy elemét, amelyre kivancsi: ");
  203.             int b = Int32.Parse(Console.ReadLine());
  204.             */
  205.  
  206.             for (int j = 0; j < 10; j++)
  207.             {
  208.                 for (int i = 0; i < 7; i++)
  209.                 {
  210.                     Console.WriteLine("Sor: " + (i+1) + "\t Oszlop: " + (j+1) + "\tWin: " + !tomb[i][j].lose + "\tErtek: " + tomb[i][j].ertek + " Nyero ut: " + tomb[i][j].nyerout);
  211.                 }
  212.                 Console.WriteLine();
  213.             }
  214.  
  215.             Console.ReadKey();
  216.         }
  217.     }                          
  218. }
Advertisement
Add Comment
Please, Sign In to add comment