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;
- /*
- * 1 5 3 4 3 6 7 1 1 6
- 4 4 3 4 2 6 2 6 2 5
- 1 3 9 4 5 2 4 2 9 5
- 5 2 3 5 5 6 4 6 2 4
- 1 3 3 2 5 6 5 2 3 2
- 2 5 2 5 5 6 4 8 6 1
- 9 2 3 6 5 6 2 2 2 *
- */
- namespace Kereses_beadando
- {
- class Elem
- {
- public int ertek;
- public bool lose;
- public String nyerout;
- public Elem(char ertek)
- {
- if (Char.IsDigit(ertek))
- {
- this.ertek = (int)Char.GetNumericValue(ertek);
- this.lose = false;
- }
- else
- {
- this.ertek = 0;
- this.lose = true;
- this.nyerout = null;
- }
- }
- } // Elem típus létrehozása (int érték, bool win?)
- class Program {
- static void populateArray(char[][] array)
- {
- array[0] = new char[] { '1', '5', '3', '4', '3', '6', '7', '1', '1', '6' };
- array[1] = new char[] { '4', '4', '3', '4', '2', '6', '2', '6', '2', '5' };
- array[2] = new char[] { '1', '3', '9', '4', '5', '2', '4', '2', '9', '5' };
- array[3] = new char[] { '5', '2', '3', '5', '5', '6', '4', '6', '2', '4' };
- array[4] = new char[] { '1', '3', '3', '2', '5', '6', '5', '2', '3', '2' };
- array[5] = new char[] { '2', '5', '2', '5', '5', '6', '4', '8', '6', '1' };
- array[6] = new char[] { '9', '2', '3', '6', '5', '6', '2', '2', '2', '*' };
- }
- static void populateTomb(Elem[][] tomb, char[][] array)
- {
- for (int i = 0; i < 7; i++)
- {
- tomb[i] = new Elem[10];
- for (int j = 0; j < 10; j++)
- {
- tomb[i][j] = new Elem(array[i][j]);
- }
- }
- }
- static void checkWhereLoseHappens(Elem[][] tomb)
- {
- for (int k = 0; k < 7 * 10; k++)
- { // 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
- for (int i = 6; i >= 0; i--)
- {
- for (int j = 9; j >= 0; j--)
- {
- String temp;
- if (tomb[i][j].ertek == 0)
- {
- tomb[i][j].nyerout = "(" + (i + 1) + ", " + (j + 1) + ")";
- continue;
- }
- else
- {
- if (i - tomb[i][j].ertek >= 0 && j - tomb[i][j].ertek >= 0) // Upper row check
- {
- if (tomb[i - tomb[i][j].ertek][j - tomb[i][j].ertek].lose == true)
- {
- tomb[i][j].nyerout = tomb[i - tomb[i][j].ertek][j - tomb[i][j].ertek].nyerout + "-> (" + (i + 1) + ", " + (j + 1) + ")";
- tomb[i][j].lose = true;
- goto kilep;
- }
- }
- else if (i - tomb[i][j].ertek >= 0)
- {
- if (tomb[i - tomb[i][j].ertek][j].lose == false)
- {
- temp = tomb[i - tomb[i][j].ertek][j].nyerout + "-> (" + (i + 1) + ", " + (j + 1) + ")";
- tomb[i][j].nyerout = temp;
- tomb[i][j].lose = true;
- goto kilep;
- }
- }
- else if (i - tomb[i][j].ertek >= 0 && j + tomb[i][j].ertek < 10)
- {
- if (tomb[i - tomb[i][j].ertek][j + tomb[i][j].ertek].lose == false)
- {
- temp = tomb[i - tomb[i][j].ertek][j + tomb[i][j].ertek].nyerout + "-> (" + (i + 1) + ", " + (j + 1) + ")";
- tomb[i][j].nyerout = temp;
- tomb[i][j].lose = true;
- goto kilep;
- }
- }
- else if (j - tomb[i][j].ertek >= 0) // Current row check
- {
- if (tomb[i][j - tomb[i][j].ertek].lose == false)
- {
- temp = tomb[i][j - tomb[i][j].ertek].nyerout + "-> (" + (i + 1) + ", " + (j + 1) + ")";
- tomb[i][j].nyerout = temp;
- tomb[i][j].lose = true;
- goto kilep;
- }
- }
- else if (j + tomb[i][j].ertek < 10)
- {
- if (tomb[i][j + tomb[i][j].ertek].lose == false)
- {
- temp = tomb[i][j + tomb[i][j].ertek].nyerout + "-> (" + (i + 1) + ", " + (j + 1) + ")";
- tomb[i][j].nyerout = temp;
- tomb[i][j].lose = true;
- goto kilep;
- }
- }
- else if (i + tomb[i][j].ertek < 7 && j - tomb[i][j].ertek >= 0) // Below row check
- {
- if (tomb[i + tomb[i][j].ertek][j - tomb[i][j].ertek].lose == false)
- {
- temp = tomb[i + tomb[i][j].ertek][j - tomb[i][j].ertek].nyerout + "-> (" + (i + 1) + ", " + (j + 1) + ")";
- tomb[i][j].nyerout = temp;
- tomb[i][j].lose = true;
- goto kilep;
- }
- }
- else if (i + tomb[i][j].ertek < 7)
- {
- if (tomb[i + tomb[i][j].ertek][j].lose == false)
- {
- tomb[i][j].nyerout = tomb[i + tomb[i][j].ertek][j].nyerout + "-> (" + (i + 1) + ", " + (j + 1) + ")";
- tomb[i][j].lose = true;
- goto kilep;
- }
- }
- else if (i + tomb[i][j].ertek < 7 && j + tomb[i][j].ertek < 10)
- {
- if (tomb[i + tomb[i][j].ertek][j + tomb[i][j].ertek].lose == false)
- {
- temp = tomb[i + tomb[i][j].ertek][j + tomb[i][j].ertek] + "-> (" + (i + 1) + ", " + (j + 1) + ")";
- tomb[i][j].nyerout = temp;
- tomb[i][j].lose = true;
- goto kilep;
- }
- }
- kilep:;
- } // Lose check row by row, then col by col
- }
- }
- }
- }
- static void Main(string[] args)
- {
- char[][] array = new char[7][];
- populateArray(array);
- Elem[][] tomb = new Elem[7][];
- populateTomb(tomb, array);
- checkWhereLoseHappens(tomb);
- for (int i = 0; i < 7; i++)
- {
- if(i == 0)
- Console.WriteLine("\t1\t2\t3\t4\t5\t6\t7\t8\t9\t10\n----------------------------------------------------------------------------------");
- Console.Write((i+1) + ". |\t");
- for (int j = 0; j < 10; j++)
- {
- Console.Write(array[i][j] + "\t");
- }
- Console.WriteLine();
- } // (char[][]) Array kiíratása
- /*
- Console.WriteLine("Adjon meg egy sor, mely egy elemere kivancsi: ");
- int a = Int32.Parse(Console.ReadLine());
- Console.WriteLine("Adja meg a sor egy elemét, amelyre kivancsi: ");
- int b = Int32.Parse(Console.ReadLine());
- */
- for (int j = 0; j < 10; j++)
- {
- for (int i = 0; i < 7; i++)
- {
- 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);
- }
- Console.WriteLine();
- }
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment