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;
- namespace ConsoleApplication1
- {
- class Program
- {
- static int[] kezdopoz;
- static int[] celpoz;
- static int[,] labirintus =
- {
- {9,9,9,9,9,9,9,9,9,9},
- {9,0,0,9,0,9,0,9,0,5},
- {9,0,9,9,0,9,0,9,0,9},
- {9,0,0,0,0,9,0,0,0,9},
- {9,9,0,9,9,9,9,9,0,9},
- {9,0,0,0,0,0,0,9,0,9},
- {9,0,9,9,9,0,9,0,0,9},
- {9,0,0,0,9,0,0,0,9,9},
- {9,0,9,0,9,0,9,0,0,9},
- {9,6,9,9,9,9,9,9,9,9}
- };
- static void bejar(int[] mezo)
- {
- while (true)
- {
- if (mezo[0] == -1)
- break;
- labirintus[mezo[0], mezo[1]] = 1;
- Console.Clear();
- kiirat();
- Console.ReadKey();
- if (getLehetsegesLepes(mezo) != null)
- {
- mezo = getLehetsegesLepes(mezo);
- }
- else
- {
- labirintus[mezo[0], mezo[1]] = 2;
- mezo = visszalep(mezo);
- }
- }
- }
- static int[] visszalep(int[] mezo)
- {
- int x = mezo[0];
- int y = mezo[1];
- List<int[]> lIndexek = new List<int[]>();
- for (int i = 1; i < 5; i++)
- switch (i)
- {
- case 1:
- if (y + 1 <= 9)
- lIndexek.Add(new int[] { x, y + 1 });
- break;
- case 2:
- if (x + 1 <= 9)
- lIndexek.Add(new int[] { x + 1, y });
- break;
- case 3:
- if (y - 1 >= 0)
- lIndexek.Add(new int[] { x, y - 1 });
- break;
- case 4:
- if (x - 1 >= 0)
- lIndexek.Add(new int[] { x - 1, y });
- break;
- }
- foreach (int[] l in lIndexek)
- {
- if (labirintus[l[0], l[1]] == 1)
- return l;
- }
- return null;
- }
- static int[] getLehetsegesLepes(int[] mezo)
- {
- int x = mezo[0];
- int y = mezo[1];
- List<int[]> lIndexek = new List<int[]>();
- for (int i = 1; i < 5; i++)
- switch (i)
- {
- case 1:
- if (y + 1 <= 9)
- lIndexek.Add(new int[] { x, y + 1 });
- break;
- case 2:
- if (x + 1 <= 9)
- lIndexek.Add(new int[] { x + 1, y });
- break;
- case 3:
- if (y - 1 >= 0)
- lIndexek.Add(new int[] { x, y - 1 });
- break;
- case 4:
- if (x - 1 >= 0)
- lIndexek.Add(new int[] { x - 1, y });
- break;
- }
- foreach (int[] l in lIndexek)
- {
- if (labirintus[l[0], l[1]] == 5)
- return new int[] { -1, -1 };
- }
- foreach (int[] l in lIndexek)
- {
- if (labirintus[l[0], l[1]] == 0)
- return l;
- }
- return null;
- }
- static void keresPoz()
- {
- for (int i = 0; i < 10; i++)
- for (int j = 0; j < 10; j++)
- {
- if (labirintus[i, j] == 6)
- kezdopoz = new int[] { i, j };
- else if (labirintus[i, j] == 5)
- celpoz = new int[] { i, j };
- }
- }
- static void kiirat()
- {
- for (int i = 0; i < 10; i++)
- {
- for (int j = 0; j < 10; j++)
- {
- int mezo = labirintus[i, j];
- switch (mezo)
- {
- case 1:
- Console.BackgroundColor = ConsoleColor.Green;
- break;
- case 2:
- Console.BackgroundColor = ConsoleColor.Red;
- break;
- case 5:
- Console.BackgroundColor = ConsoleColor.Cyan;
- break;
- case 6:
- Console.BackgroundColor = ConsoleColor.Cyan;
- break;
- case 9:
- Console.BackgroundColor = ConsoleColor.DarkGray;
- break;
- default:
- break;
- }
- Console.Write("{0,2}", mezo);
- Console.BackgroundColor = ConsoleColor.Black;
- }
- Console.WriteLine();
- }
- }
- static void Main(string[] args)
- {
- keresPoz();
- bejar(kezdopoz);
- Console.WriteLine("kijutottunk");
- Console.ReadKey();
- }
- }
- }
Add Comment
Please, Sign In to add comment