Advertisement
MrVeiran

igra

Mar 18th, 2019
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 17.11 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. using System.IO;
  7. using System.Threading;
  8.  
  9. namespace ConsoleApp61
  10. {
  11.     class Program
  12.     {
  13.         static void Main(string[] args)
  14.         {
  15.  
  16.            
  17.             char[,] intro1;
  18.             sozdanieintro(out intro1,"intro1.txt");
  19.             char[,] intro2;
  20.             sozdanieintro(out intro2, "intro2.txt");
  21.             char[,] intro3;
  22.             sozdanieintro(out intro3, "intro3.txt");
  23.             char[,] intro4;
  24.             sozdanieintro(out intro4, "intro4.txt");
  25.             char[,] intro5;
  26.             sozdanieintro(out intro5, "intro5.txt");
  27.             char[,] intro6;
  28.             sozdanieintro(out intro6, "intro6.txt");
  29.             char[,] alien1;
  30.             sozdanieintro(out alien1, "alien1.txt");
  31.             char[,] alien2;
  32.             sozdanieintro(out alien2, "alien1.txt");
  33.  
  34.  
  35.  
  36.             Console.CursorVisible = false;
  37.             int width = Console.WindowWidth;
  38.             int height = Console.WindowHeight;
  39.             Console.WindowWidth = width;
  40.             Console.WindowHeight = height;
  41.             string Hello = "Медленно нажимайте Enter, чтобы прочитать интро:)";
  42.             string Hello1 = "Нажмите Enter для продолжения";
  43.  
  44.            
  45.            
  46.  
  47.             Console.SetCursorPosition(width/2-Hello.Length/2,10);
  48.             Console.Write(Hello);
  49.             Console.SetCursorPosition(width / 2 - Hello.Length / 2, 11);
  50.             Console.Write(Hello1);
  51.             Console.ReadLine();
  52.             Console.Clear();
  53.             Console.BackgroundColor = ConsoleColor.White;
  54.             Console.ForegroundColor = ConsoleColor.Black;
  55.             for (int i = 0; i < width; i++)
  56.             {
  57.                 for (int j = 0; j < height*3/2; j++)
  58.                 {
  59.                     Console.SetCursorPosition(i, j);
  60.                     Console.Write(" ");
  61.                 }
  62.                 Console.WriteLine();
  63.             }
  64.             Console.SetCursorPosition(0, 0);
  65.             Console.WriteLine();
  66.            
  67.            
  68.             Console.SetCursorPosition(0, 0);// норм расположение картинки
  69.  
  70.             Console.SetCursorPosition(50, 20);// текст
  71.             int end = 0;
  72.  
  73.             Thread thr = new Thread(new ThreadStart(Program.intro));
  74.             thr.Start();
  75.             Thread.Sleep(350);
  76.            
  77.             //приветствие
  78.             Console.SetCursorPosition(35, 20);
  79.             Console.Write("Ну здарова!");
  80.            
  81.             Console.SetCursorPosition(35, 22);
  82.             Console.Write("Зря ты появился в этом гребаном месте...");
  83.             Console.ReadLine();
  84.             Console.SetCursorPosition(35, 20);
  85.             Console.Write("                ");
  86.  
  87.             Console.SetCursorPosition(35, 22);
  88.             Console.Write("                                         ");
  89.            
  90.             Console.SetCursorPosition(35, 20);
  91.             Console.Write("Я хотел просто жрать, спать, сидеть в инете");
  92.  
  93.             Console.SetCursorPosition(35, 22);
  94.             Console.Write("Но потом явились они....");
  95.             Console.ReadLine();
  96.             Console.SetCursorPosition(35, 20);
  97.             Console.Write("                                             ");
  98.  
  99.             Console.SetCursorPosition(35, 22);
  100.             Console.Write("                                              ");
  101.  
  102.             Console.SetCursorPosition(35, 20);
  103.             Console.Write("Эти уроды отняли у меня всё что было");
  104.  
  105.             Console.SetCursorPosition(35, 22);
  106.             Console.Write("ПОРВЕМ КОЗЛОВ ЗА ИНЕТ!");
  107.             Console.ReadLine();
  108.  
  109.            
  110.             thr.Abort();
  111.             thr.Join(500);
  112.             Console.Clear();
  113.             music();
  114.             vuvodintro(intro1,0,0);
  115.             Thread.Sleep(500);
  116.             vuvodintro(intro2,0,0);
  117.             Thread.Sleep(500);
  118.             vuvodintro(intro3,0,0);
  119.             Thread.Sleep(500);
  120.             vuvodintro(intro4,0,0);
  121.             Thread.Sleep(500);
  122.             vuvodintro(intro5,0,0);
  123.             Thread.Sleep(500);
  124.             vuvodintro(intro6,0,0);
  125.             Console.Clear();
  126.             Console.SetCursorPosition(15, 6);
  127.             Console.Write("Приветствую вас. В игре надо убивать монстров");
  128.             Console.SetCursorPosition(15, 7);
  129.             Console.Write("которые двигаются либо по верхней дорожке");
  130.             Console.SetCursorPosition(15, 8);
  131.             Console.Write("либо по нижней");
  132.             Console.SetCursorPosition(15, 10);
  133.             Console.Write("Перемещаться между дорожками Up и Down, соотвественно");
  134.             Console.SetCursorPosition(15, 12);
  135.             Console.Write("Стрелять на клавишу А");
  136.             Console.SetCursorPosition(15, 14);
  137.             Console.Write("P.S. Нельзя чтобы монстры дошли до вашего оружия!");
  138.             Console.SetCursorPosition(15, 16);
  139.             Console.Write("Нажмите Enter для начала игры");
  140.             Console.ReadLine();
  141.             Console.Clear();
  142.             vuvodintro(intro6, 0, 0);
  143.             int score = 0;
  144.             Console.SetCursorPosition(0, 18);
  145.             for (int i = 0; i < width / 2 - 5; i++)
  146.             {
  147.                 Console.Write("#");
  148.             }
  149.             Console.Write(" СЧЕТ: " + score);
  150.             Console.SetCursorPosition(width / 2 + 5, 18);
  151.             Console.Write("#");
  152.             for (int i = width / 2 + 6; i < width; i++)
  153.                 Console.Write("#");
  154.  
  155.             int down = 1;
  156.             int up = 0;
  157.             int bes1 = 0;
  158.             int bes2 = 1;
  159.             ConsoleKeyInfo Key;
  160.             end = 0;
  161.             int vustrel1 = 0;
  162.             int vustrel2 = 0;
  163.             int rang1 = 1;
  164.             int rang2 = 1;
  165.             int alienX = 0;
  166.             int alienXX = 0;
  167.             Random rnd1 = new Random();//снизу или сверху
  168.             Random rnd2 = new Random();// шанс
  169.             Console.WindowHeight = height * 3 / 2;
  170.             int alienhero1 = 0;
  171.             int alienhero2 = 0;
  172.             int finish1 = 0;
  173.             int finish2 = 0;
  174.  
  175.             int we = 0;
  176.             while (end<2)
  177.             {
  178.                 if (Console.KeyAvailable)
  179.                 {
  180.                     Key = Console.ReadKey(true);
  181.                     switch (Key.Key)
  182.                     {
  183.                        
  184.                        
  185.                         case ConsoleKey.UpArrow:
  186.                             if (up == 1)
  187.                             {
  188.                                
  189.  
  190.                                 vuvodintro(intro6,0,0);
  191.                                 vuvodscore(ref score);
  192.                                 down = 1;
  193.                                 bes1 = 1;
  194.                                 up = 0;
  195.                             }
  196.                             break;
  197.                         case ConsoleKey.DownArrow:
  198.                             if( down==1)
  199.                             {
  200.                                 vuvodintro(intro6,0,20);
  201.                                 vuvodscore(ref score);
  202.                                 down = 0;
  203.                                 bes2 = 0;
  204.                                 up = 1;
  205.                             }
  206.                             break;
  207.                         case ConsoleKey.A:
  208.                             if (up == 0)
  209.                             {
  210.                                 Console.SetCursorPosition(27, 9);
  211.                                 vustrel1 = 1;
  212.  
  213.                             }
  214.                             if( down ==0)
  215.                             {
  216.                                 Console.SetCursorPosition(27, 29);
  217.                                 vustrel2 = 1; ;
  218.  
  219.                             }
  220.  
  221.                             break;
  222.                     }
  223.  
  224.                    
  225.  
  226.                 }
  227.                 if (vustrel1 == 1)
  228.                 {
  229.                     kill(ref vustrel1, ref rang1, 9, ref alienX, ref alienhero1, ref alien1,ref score);
  230.                    
  231.                 }
  232.                 if (vustrel2 == 1)
  233.                 {
  234.                     kill(ref vustrel2, ref rang2, 29, ref alienXX, ref alienhero2, ref alien2,ref score);
  235.  
  236.                 }
  237.  
  238.  
  239.  
  240.                 Thread.Sleep(30);
  241.  
  242.  
  243.  
  244.                 if (rang1 == 30 )
  245.                 {
  246.                     Console.SetCursorPosition(27 + rang1, 9);
  247.                     Console.Write(" ");
  248.                
  249.                     rang1 = 0;
  250.                     vustrel1 = 0;
  251.                    
  252.                 }
  253.                 if (rang2 == 30)
  254.                 {
  255.                     Console.SetCursorPosition(27 + rang2, 29);
  256.                     Console.Write(" ");
  257.  
  258.                     rang2 = 0;
  259.                     vustrel2 = 0;
  260.  
  261.                 }
  262.  
  263.  
  264.                 if (vustrel1 == 1 )
  265.                 {
  266.                     rang1++;
  267.                 }
  268.                 if (vustrel2 == 1)
  269.                 {
  270.                     rang2++;
  271.                 }
  272.  
  273.  
  274.  
  275.  
  276.                 if (rnd1.Next(100) < 5 && alienhero1 == 0)
  277.                 {
  278.                     poyav(ref alienhero1, ref finish1, ref alienX, ref alien1, 3);
  279.                 }
  280.                 if (rnd1.Next(100) < 5 && alienhero2 == 0)
  281.                 {
  282.                     poyav(ref alienhero2, ref finish2, ref alienXX, ref alien2, 23);
  283.                 }
  284.  
  285.  
  286.  
  287.  
  288.  
  289.                 if (alienhero1 == 1)
  290.                 {
  291.                     move(ref alienX,ref alien1, ref finish1,9);
  292.                 }
  293.                 if (alienhero2 == 1)
  294.                 {
  295.                     move(ref alienXX, ref alien2, ref finish2, 29);
  296.                 }
  297.  
  298.  
  299.  
  300.                 if (finish1 == 30)
  301.                 {
  302.                     Console.Clear();
  303.                     Console.SetCursorPosition(width / 2-20, 15);
  304.  
  305.                     Console.WriteLine("ВЫ ПРОИГРАЛИ!");
  306.                     Console.SetCursorPosition(width / 2-20, 16);
  307.                     Console.WriteLine("Количество очков которые вы набрали: " + score);
  308.                     Console.ReadLine();
  309.                     break;
  310.                 }
  311.                 if (finish2 == 30)
  312.                 {
  313.                     Console.Clear();
  314.                     Console.SetCursorPosition(width / 2-20, 15);
  315.  
  316.                     Console.WriteLine("ВЫ ПРОИГРАЛИ!");
  317.                     Console.SetCursorPosition(width / 2-20, 16);
  318.                     Console.WriteLine("Количество очков которые вы набрали: "+ score);
  319.                     Console.ReadLine();
  320.                     break;
  321.                 }
  322.  
  323.  
  324.  
  325.  
  326.                 vuvodscore(ref score);
  327.  
  328.             }
  329.            
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.  
  339.  
  340.  
  341.         }
  342.         static void move(ref int move, ref char[,] alien,ref int finish,int coor)
  343.         {
  344.             int width = Console.WindowWidth;
  345.             move--;
  346.  
  347.             for (int j = 0; j < alien.GetLength(1); j++)
  348.  
  349.             {
  350.  
  351.                 for (int i = 0; i < alien.GetLength(0); i++)
  352.                 {
  353.  
  354.                     Console.SetCursorPosition(width - 17 + i + move, coor-6 + j);
  355.                     Console.Write(alien[j, i]);
  356.                     finish = width - 17 + i + move;
  357.  
  358.  
  359.                 }
  360.  
  361.             }
  362.  
  363.         }
  364.  
  365.         static void kill(ref int shot, ref int rang, int coor, ref int move, ref int monster, ref char[,] alien,ref int score)
  366.         {
  367.             int width = Console.WindowWidth;
  368.  
  369.             //coor=9;
  370.             Console.SetCursorPosition(27 + rang, coor);
  371.             int srav1 = 27 + rang;
  372.  
  373.             if (srav1 == width - 17 + move || srav1 == width - 16 + move || srav1 == width - 15 + move)
  374.             {
  375.                 Console.SetCursorPosition(27 + rang - 1, coor);
  376.                 Console.Write(" ");
  377.                 score++;
  378.                 monster = 0;
  379.                 shot = 0;
  380.                 rang = 0;
  381.                 //исчезает монстр
  382.                 for (int j = 0; j < alien.GetLength(1); j++)
  383.  
  384.                 {
  385.  
  386.                     for (int i = 0; i < alien.GetLength(0); i++)
  387.                     {
  388.  
  389.                         Console.SetCursorPosition(width - 17 + i + move, coor-6 + j);
  390.                         Console.Write(" ");
  391.  
  392.  
  393.  
  394.                     }
  395.  
  396.                 }
  397.  
  398.             }
  399.             else
  400.             {
  401.                 Console.Write(">");
  402.                 Console.SetCursorPosition(26 + rang, coor);
  403.                 Console.Write(" ");
  404.             }
  405.  
  406.  
  407.         }
  408.  
  409.        
  410.         static void poyav(ref int monster,ref int finish,ref int move,ref char[,]alien,int coor)
  411.         {
  412.             //(ref alienhero1,ref qw,ref alienX,ref alien1);
  413.             int width = Console.WindowWidth;
  414.             monster = 1;
  415.             finish = 0;
  416.             move = 0;
  417.             for (int j = 0; j < alien.GetLength(1); j++)
  418.  
  419.             {
  420.                 for (int i = 0; i < alien.GetLength(0); i++)
  421.                 {
  422.  
  423.                     Console.SetCursorPosition(width - 17 + i, coor + j);
  424.                     Console.Write(alien[j, i]);
  425.                 }
  426.  
  427.             }
  428.  
  429.  
  430.         }
  431.  
  432.         static void vuvodscore(ref int score)
  433.         {
  434.             int width = Console.WindowWidth;
  435.             Console.SetCursorPosition(0, 18);
  436.             for (int i = 0; i < width / 2 - 5; i++)
  437.             {
  438.                 Console.Write("#");
  439.             }
  440.             Console.Write(" СЧЕТ: " + score);
  441.             Console.SetCursorPosition(width / 2 + 5, 18);
  442.             Console.Write("#");
  443.             for (int i = width / 2 + 6; i < width; i++)
  444.                 Console.Write("#");
  445.         }
  446.  
  447.         static void vuvodintro(char[,]intro,int q,int w)
  448.         {
  449.             Console.Clear();
  450.             Console.SetCursorPosition(q, w);
  451.  
  452.             for (int i = 0; i < intro.GetLength(0); i++)
  453.  
  454.             {
  455.                 for (int j = 0; j < intro.GetLength(1); j++)
  456.                 {
  457.  
  458.                     Console.Write(intro[i, j]);
  459.                 }
  460.                 Console.WriteLine();
  461.             }
  462.            
  463.  
  464.         }
  465.         static void sozdanieintro(out char[,]intro,string sre)
  466.         {
  467.             string[] NewFile = File.ReadAllLines(sre);
  468.              intro = new char[NewFile.Length, NewFile[1].Length];
  469.             for (int i = 0; i < intro.GetLength(0); i++)
  470.  
  471.             {
  472.                 for (int j = 0; j < intro.GetLength(1); j++)
  473.                 {
  474.                     intro[i, j] = NewFile[i][j];
  475.                 }
  476.  
  477.             }
  478.         }
  479.  
  480.         static void music()
  481.         {
  482.  
  483.             System.Media.SoundPlayer player = new System.Media.SoundPlayer(@"duck.wav");
  484.             player.Play();
  485.  
  486.  
  487.         }
  488.         public static void intro()
  489.         {
  490.            
  491.             string[] NewFile = File.ReadAllLines("intro1.txt");
  492.             char[,] map = new char[NewFile.Length, NewFile[1].Length];
  493.             for (int i = 0; i < map.GetLength(0); i++)
  494.  
  495.             {
  496.                 for (int j = 0; j < map.GetLength(1); j++)
  497.                 {
  498.                     map[i, j] = NewFile[i][j];
  499.                 }
  500.  
  501.             }
  502.             Console.SetCursorPosition(0, 0);
  503.             for (int i = 0; i < map.GetLength(0); i++)
  504.  
  505.             {
  506.                 for (int j = 0; j < map.GetLength(1); j++)
  507.                 {
  508.  
  509.                     Console.Write(map[i, j]);
  510.                 }
  511.                 Console.WriteLine();
  512.             }
  513.             int napr = 0;
  514.             int bok = -1;
  515.             int vverh = 0;
  516.             int end = 0;
  517.             int s4et = 0;
  518.             Random rnd4 = new Random();
  519.             while (end < 2)
  520.             {
  521.                 Console.SetCursorPosition(61 + bok, 15 + vverh);// дым начинается
  522.                 Console.WriteLine("$");
  523.  
  524.                 if (bok == -4)
  525.                 {
  526.                     napr = 1;
  527.                     s4et = 0;
  528.                 }
  529.                 if (bok == 4)
  530.                 {
  531.                     napr = 0;
  532.                    
  533.                 }
  534.  
  535.                 if (napr == 1)
  536.                     bok++;
  537.                 if (napr == 0)
  538.                     bok--;
  539.                
  540.                 vverh--;
  541.                 if (vverh == -15)
  542.                 {
  543.                     vverh = 0;
  544.                     if (napr == 1)
  545.                     {
  546.                        
  547.                         napr = 0;
  548.                     }
  549.                     if (napr == 0)
  550.                     {
  551.                        
  552.                         napr = 1;
  553.                     }
  554.                 }
  555.  
  556.  
  557.                 Thread.Sleep(250);
  558.             }
  559.         }
  560.     }
  561. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement