Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApp4
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.CursorVisible = false;
- char[,] map1 =
- {
- {'#','#','#','#','#','#','#','#','#','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#','#','#','#','#','#','#','#','#','#' }
- };
- char[,] map3 =
- {
- {'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#' }
- };
- char[,] map2 =
- {
- {'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#' }
- };
- string[] MenuItems = { "10 на 10", "20 на 20", "30 на 30" };
- int MenuPos = 0;
- Console.WriteLine("Это классическая змейка");
- Menu(MenuItems, MenuPos);
- PickOut(MenuPos, MenuItems, ref map2, ref map3, ref map1);
- }
- static void Menu(string[] MenuItems, int MenuPos)
- {
- Console.Clear();
- for (int i = 0; i < MenuItems.Length; i++)
- {
- if (i == MenuPos)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine(MenuItems[i]);
- Console.ForegroundColor = ConsoleColor.White;
- }
- else
- Console.WriteLine(MenuItems[i]);
- }
- }
- static void Switch(int MenuPos, ref char[,] map2, ref char[,] map3, ref char[,] map1)
- {
- switch (MenuPos)
- {
- case 0:
- Ten(ref map3);
- break;
- case 1:
- Twenty(ref map2);
- break;
- case 2:
- Thirty(ref map1);
- break;
- default:
- Switch(MenuPos, ref map2, ref map3, ref map1);
- break;
- }
- }
- static void PickOut(int MenuPos, string[] MenuItems, ref char[,] map2, ref char[,] map1, ref char[,] map3)
- {
- while (true)
- {
- var key = Console.ReadKey().Key;
- switch (key)
- {
- case ConsoleKey.UpArrow:
- if (MenuPos > 0)
- {
- MenuPos--;
- Menu(MenuItems, MenuPos);
- }
- break;
- case ConsoleKey.DownArrow:
- if (MenuPos < MenuItems.Length - 1)
- {
- MenuPos++;
- Menu(MenuItems, MenuPos);
- }
- break;
- case ConsoleKey.Enter:
- {
- Switch(MenuPos, ref map2, ref map3, ref map1);
- break;
- }
- default:
- Menu(MenuItems, MenuPos);
- break;
- }
- Console.SetCursorPosition(0, 3);
- }
- }
- static void Twenty(ref char[,] map2)
- {
- Console.Clear();
- int userY = 6, userX = 6;
- map2[userX, userY] = '@';
- int k = 0;
- int m = 0;
- int n = 0;
- int WIN = 0;
- link1:
- for (int i = 0; i < map2.GetLength(0); i++)
- {
- for (int j = 0; j < map2.GetLength(1); j++)
- {
- Random rnd = new Random();
- int a = rnd.Next(50);
- if (a == 16 && k == 0 && map2[i, j] != '#')
- {
- n = i;
- m = j;
- map2[i, j] = '*';
- Console.Write(map2[i, j]);
- k++;
- }
- else
- Console.Write(map2[i, j]);
- }
- Console.WriteLine();
- }
- if (k == 0)
- {
- Console.Clear();
- goto link1;
- }
- while (WIN != 1)
- {
- Console.SetCursorPosition(userY, userX);
- Console.Write('@');
- ConsoleKeyInfo charKey = Console.ReadKey();
- switch (charKey.Key)
- {
- case ConsoleKey.UpArrow:
- if (map2[userX - 1, userY] != '#' && map2[userX - 1, userY] != '@')
- {
- userX--;
- map2[userX, userY] = '@';
- }
- break;
- case ConsoleKey.DownArrow:
- if (map2[userX + 1, userY] != '#' && map2[userX + 1, userY] != '@')
- userX++;
- map2[userX, userY] = '@';
- break;
- case ConsoleKey.LeftArrow:
- if (map2[userX, userY - 1] != '#' && map2[userX, userY - 1] != '@')
- userY--;
- map2[userX, userY] = '@';
- break;
- case ConsoleKey.RightArrow:
- if (map2[userX, userY + 1] != '#' && map2[userX, userY + 1] != '@')
- userY++;
- map2[userX, userY] = '@';
- break;
- }
- int g = 0;
- Console.SetCursorPosition(0, 0);
- link2:
- if (map2[n, m] == map2[userX, userY] && k == 1)
- {
- for (int i = 0; i < map2.GetLength(0); i++)
- {
- for (int j = 0; j < map2.GetLength(1); j++)
- {
- Random rnd = new Random();
- int a = rnd.Next(50);
- if (a == 0 && k == 1 && map2[i, j] != '#' && map2[i, j] != '@' && g >= 0)
- {
- n = i;
- m = j;
- map2[i, j] = '*';
- Console.Write(map2[i, j]);
- k++;
- g++;
- }
- else
- Console.Write(map2[i, j]);
- }
- Console.WriteLine();
- }
- if (k == 1)
- {
- Console.Clear();
- goto link2;
- }
- }
- link3:
- if (map2[n, m] == map2[userX, userY] && k == 2)
- {
- g = 1;
- for (int i = 0; i < map2.GetLength(0); i++)
- {
- for (int j = 0; j < map2.GetLength(1); j++)
- {
- Random rnd = new Random();
- int a = rnd.Next(50);
- if (a == 0 && k == 2 && map2[i, j] != '#' && map2[i, j] != '@' && g >= 0)
- {
- n = i;
- m = j;
- map2[i, j] = '*';
- Console.Write(map2[i, j]);
- k++;
- g++;
- }
- else
- Console.Write(map2[i, j]);
- }
- Console.WriteLine();
- }
- if (k == 2 )
- {
- Console.Clear();
- goto link3;
- }
- if (k == 3 && g == 2 && map2[n, m] == map2[userX, userY])
- WIN++;
- }
- Console.SetCursorPosition(0, 0);
- for (int i = 0; i < map2.GetLength(0); i++)
- {
- for (int j = 0; j < map2.GetLength(1); j++)
- {
- Console.Write(map2[i, j]);
- }
- Console.WriteLine();
- }
- }
- Console.WriteLine("Ты выйграл в змейку.");
- }
- static void Ten(ref char[,] map3)
- {
- Console.Clear();
- int userY = 6, userX = 6;
- map3[userX, userY] = '@';
- int k = 0;
- int m = 0;
- int n = 0;
- int WIN = 0;
- link1:
- for (int i = 0; i < map3.GetLength(0); i++)
- {
- for (int j = 0; j < map3.GetLength(1); j++)
- {
- Random rnd = new Random();
- int a = rnd.Next(50);
- if (a == 16 && k == 0 && map3[i, j] != '#')
- {
- n = i;
- m = j;
- map3[i, j] = '*';
- Console.Write(map3[i, j]);
- k++;
- }
- else
- Console.Write(map3[i, j]);
- }
- Console.WriteLine();
- }
- if (k == 0)
- {
- Console.Clear();
- goto link1;
- }
- while (WIN != 1)
- {
- Console.SetCursorPosition(userY, userX);
- Console.Write('@');
- ConsoleKeyInfo charKey = Console.ReadKey();
- switch (charKey.Key)
- {
- case ConsoleKey.UpArrow:
- if (map3[userX - 1, userY] != '#' && map3[userX - 1, userY] != '@')
- {
- userX--;
- map3[userX, userY] = '@';
- }
- break;
- case ConsoleKey.DownArrow:
- if (map3[userX + 1, userY] != '#' && map3[userX +1, userY] != '@')
- userX++;
- map3[userX, userY] = '@';
- break;
- case ConsoleKey.LeftArrow:
- if (map3[userX, userY - 1] != '#' && map3[userX, userY - 1] != '@')
- userY--;
- map3[userX, userY] = '@';
- break;
- case ConsoleKey.RightArrow:
- if (map3[userX, userY + 1] != '#' && map3[userX, userY + 1] != '@')
- userY++;
- map3[userX, userY] = '@';
- break;
- }
- int g = 0;
- Console.SetCursorPosition(0, 0);
- link2:
- if (map3[n, m] == map3[userX, userY] && k == 1)
- {
- for (int i = 0; i < map3.GetLength(0); i++)
- {
- for (int j = 0; j < map3.GetLength(1); j++)
- {
- Random rnd = new Random();
- int a = rnd.Next(50);
- if (a == 0 && k == 1 && map3[i, j] != '#' && map3[i, j] != '@' && g >= 0)
- {
- n = i;
- m = j;
- map3[i, j] = '*';
- Console.Write(map3[i, j]);
- k++;
- g++;
- }
- else
- Console.Write(map3[i, j]);
- }
- Console.WriteLine();
- }
- if (k == 1)
- {
- Console.Clear();
- goto link2;
- }
- }
- link3:
- if (map3[n, m] == map3[userX, userY] && k == 2)
- {
- g = 1;
- for (int i = 0; i < map3.GetLength(0); i++)
- {
- for (int j = 0; j < map3.GetLength(1); j++)
- {
- Random rnd = new Random();
- int a = rnd.Next(50);
- if (a == 0 && k == 2 && map3[i, j] != '#' && map3[i, j] != '@' && g >= 0)
- {
- n = i;
- m = j;
- map3[i, j] = '*';
- Console.Write(map3[i, j]);
- k++;
- WIN++;
- }
- else
- Console.Write(map3[i, j]);
- }
- Console.WriteLine();
- }
- if (k == 2)
- {
- Console.Clear();
- goto link3;
- }
- }
- Console.SetCursorPosition(0, 0);
- for (int i = 0; i < map3.GetLength(0); i++)
- {
- for (int j = 0; j < map3.GetLength(1); j++)
- {
- Console.Write(map3[i, j]);
- }
- Console.WriteLine();
- }
- if (g == 3 && k == 3)
- WIN = 1;
- }
- Console.WriteLine("Ты выйграл в змейку.");
- }
- static void Thirty(ref char[,] map1)
- {
- Console.Clear();
- int userY = 6, userX = 6;
- map1[userX, userY] = '@';
- int k = 0;
- int m = 0;
- int n = 0;
- int WIN = 0;
- link1:
- for (int i = 0; i < map1.GetLength(0); i++)
- {
- for (int j = 0; j < map1.GetLength(1); j++)
- {
- Random rnd = new Random();
- int a = rnd.Next(50);
- if (a == 16 && k == 0 && map1[i, j] != '#')
- {
- n = i;
- m = j;
- map1[i, j] = '*';
- Console.Write(map1[i, j]);
- k++;
- }
- else
- Console.Write(map1[i, j]);
- }
- Console.WriteLine();
- }
- if (k == 0)
- {
- Console.Clear();
- goto link1;
- }
- while (WIN != 1)
- {
- Console.SetCursorPosition(userY, userX);
- Console.Write('@');
- ConsoleKeyInfo charKey = Console.ReadKey();
- switch (charKey.Key)
- {
- case ConsoleKey.UpArrow:
- if (map1[userX - 1, userY] != '#' && map1[userX - 1, userY] != '@')
- {
- userX--;
- map1[userX, userY] = '@';
- }
- break;
- case ConsoleKey.DownArrow:
- if (map1[userX + 1, userY] != '#' && map1[userX + 1, userY] != '@')
- userX++;
- map1[userX, userY] = '@';
- break;
- case ConsoleKey.LeftArrow:
- if (map1[userX, userY - 1] != '#' && map1[userX, userY - 1] != '@')
- userY--;
- map1[userX, userY] = '@';
- break;
- case ConsoleKey.RightArrow:
- if (map1[userX, userY + 1] != '#' && map1[userX, userY + 1] != '@')
- userY++;
- map1[userX, userY] = '@';
- break;
- }
- int g = 0;
- Console.SetCursorPosition(0, 0);
- link2:
- if (map1[n, m] == map1[userX, userY] && k == 1)
- {
- for (int i = 0; i < map1.GetLength(0); i++)
- {
- for (int j = 0; j < map1.GetLength(1); j++)
- {
- Random rnd = new Random();
- int a = rnd.Next(50);
- if (a == 0 && k == 1 && map1[i, j] != '#' && map1[i, j] != '@' && g >= 0)
- {
- n = i;
- m = j;
- map1[i, j] = '*';
- Console.Write(map1[i, j]);
- k++;
- g++;
- }
- else
- Console.Write(map1[i, j]);
- }
- Console.WriteLine();
- }
- if (k == 1)
- {
- Console.Clear();
- goto link2;
- }
- }
- link3:
- if (map1[n, m] == map1[userX, userY] && k == 2)
- {
- g = 1;
- for (int i = 0; i < map1.GetLength(0); i++)
- {
- for (int j = 0; j < map1.GetLength(1); j++)
- {
- Random rnd = new Random();
- int a = rnd.Next(50);
- if (a == 0 && k == 2 && map1[i, j] != '#' && map1[i, j] != '@' && g >= 0)
- {
- n = i;
- m = j;
- map1[i, j] = '*';
- Console.Write(map1[i, j]);
- k++;
- WIN++;
- }
- else
- Console.Write(map1[i, j]);
- }
- Console.WriteLine();
- }
- if (k == 2)
- {
- Console.Clear();
- goto link3;
- }
- }
- Console.SetCursorPosition(0, 0);
- for (int i = 0; i < map1.GetLength(0); i++)
- {
- for (int j = 0; j < map1.GetLength(1); j++)
- {
- Console.Write(map1[i, j]);
- }
- Console.WriteLine();
- }
- if (g == 3 && k == 3)
- WIN = 1;
- }
- Console.WriteLine("Ты выйграл в змейку.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement