Advertisement
Guest User

САША ГЕЙ

a guest
Sep 17th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.43 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. namespace ConsoleApplication4
  8. {
  9.     class Program
  10.     {
  11.         static string n;
  12.         static int x = 1, y = 2, d=15;
  13.         static int cookieX, cookieY, enemyX, enemyY, enemyX1, enemyY1, enemyX2, enemyY2, enemyX3, enemyY3, enemyX4, enemyY4;
  14.         static string hero = "o", hero1, hero2;
  15.         static string enemy, enemy1, enemy2, enemy3, enemy4;
  16.  
  17.  
  18.  
  19.         static Random rand = new Random();
  20.  
  21.         static void GenerateCookie()
  22.         {
  23.                 cookieX = 5 + rand.Next(34);
  24.                 cookieY = 5 + rand.Next(14);
  25.             return ;
  26.         }
  27.  
  28.         static void GenerateEnemy()
  29.         {
  30.             enemyX = 5 + rand.Next(34);
  31.             enemyY = 5 + rand.Next(14);
  32.             enemyX1 = 5 + rand.Next(34);
  33.             enemyY1 = 5 + rand.Next(14);
  34.             enemyX2 = 5 + rand.Next(34);
  35.             enemyY2 = 5 + rand.Next(14);
  36.             enemyX3 = 5 + rand.Next(34);
  37.             enemyY3 = 5 + rand.Next(14);
  38.             enemyX4 = 5 + rand.Next(34);
  39.             enemyY4 = 5 + rand.Next(14);
  40.             return;
  41.         }
  42.  
  43.         static void Main(string[] args)
  44.         {
  45.             StartScreen();
  46.             GameScreen();
  47.            
  48.             Console.ReadKey();
  49.         }
  50.  
  51.         static void StartScreen()
  52.         {
  53.             Console.WriteLine("Введите свое имя: ");
  54.            n = Console.ReadLine();
  55.         }
  56.  
  57.         static void GameScreen()
  58.         {
  59.             GenerateEnemy();
  60.             Console.CursorVisible = false;
  61.             bool isEnd = false;
  62.             GenerateCookie();
  63.             while (!isEnd)
  64.             {  // isEnd - переменная-признак конца игры
  65.                 DrawWorld();
  66.                 ReadInputs();
  67.             }
  68.         }
  69.  
  70.         static void DrawWorld()
  71.         {
  72.             Console.Clear();
  73.             int i = 0, j = 0;
  74.             Console.Clear();
  75.            
  76.             Console.Clear();
  77.             Console.WriteLine($"Name: {n} | Score: {d}");
  78.  
  79.             for (i = 0; i < 20; i++)
  80.             {
  81.                 for (j = 0; j < 40; j++)
  82.                 {
  83.                     if (i == 0 || i == 19)
  84.                     {
  85.                         Console.Write("-");
  86.                     }
  87.                     else if (j == 0 || j == 39)
  88.                     {
  89.                         Console.Write("|");
  90.                     }
  91.                     else Console.Write(" ");
  92.                 }
  93.                 Console.WriteLine();
  94.  
  95.             }
  96.             Console.SetCursorPosition(cookieX, cookieY);
  97.             Console.Write("P");
  98.  
  99.             Console.SetCursorPosition(x, y);
  100.             Console.WriteLine(hero);
  101.             Console.SetCursorPosition(x, y + 1);
  102.             Console.WriteLine(hero1);
  103.             Console.SetCursorPosition(x, y + 2);
  104.             Console.WriteLine(hero2);
  105.             Console.SetCursorPosition(enemyX, enemyY);
  106.             Console.WriteLine(enemy);
  107.             Console.SetCursorPosition(enemyX1, enemyY1);
  108.             Console.WriteLine(enemy1);
  109.             Console.SetCursorPosition(enemyX2, enemyY2);
  110.             Console.WriteLine(enemy2);
  111.             Console.SetCursorPosition(enemyX3, enemyY3);
  112.             Console.WriteLine(enemy3);
  113.             Console.SetCursorPosition(enemyX4, enemyY4);
  114.             Console.WriteLine(enemy4);
  115.  
  116.             if (d >= 3 && d < 6)
  117.             {
  118.                 hero = "0";
  119.                 enemy = "X";
  120.  
  121.                 if (x == cookieX && y == cookieY)
  122.                 {
  123.                     GenerateCookie();
  124.                     d++;
  125.                 }
  126.  
  127.             } else if (d >= 6 && d < 9)
  128.             {
  129.                 hero = "/\\";
  130.                 hero1 = "\\/";
  131.                 if (x <= cookieX && y <= cookieY && x + 2 > cookieX && y + 2 > cookieY)
  132.                 {
  133.                     GenerateCookie();
  134.                     d++;
  135.                 }
  136.                 enemy1 = "X";
  137.             } else if (d >=9 && d < 12)
  138.             {
  139.                 hero = "/-\\";
  140.                 hero1 = "\\-/";
  141.                 if (x <= cookieX && y <= cookieY && x + 3 > cookieX && y + 2 > cookieY)
  142.                 {
  143.                     GenerateCookie();
  144.                     d++;
  145.                 }
  146.                 enemy2 = "X";
  147.             } else if (d >= 12 && d < 15)
  148.             {
  149.                 hero = "/-\\";
  150.                 hero1 = "|*|";
  151.                 hero2 = "\\-/";
  152.                 if (x <= cookieX && y <= cookieY && x + 2 > cookieX && y + 2 > cookieY)
  153.                 {
  154.                     GenerateCookie();
  155.                     d++;
  156.                 }
  157.                 enemy3 = "X";
  158.             } else if (d >=15 && d < 18)
  159.             {
  160.                 hero = "/--\\";
  161.                 hero1 = "|**|";
  162.                 hero2 = "\\--/";
  163.                 if (x <= cookieX && y <= cookieY && x + 4 > cookieX && y + 3 > cookieY)
  164.                 {
  165.                     GenerateCookie();
  166.                     d++;
  167.                 }
  168.                 enemy4 = "X";
  169.             } else if (d >= 18)
  170.             {
  171.                 hero = "/---\\";
  172.                 hero1 = "|***|";
  173.                 hero2 = "\\---/";
  174.                 enemy = "X";
  175.                 if (x <= cookieX && y <= cookieY && x + 5 > cookieX && y + 3 > cookieY)
  176.                 {
  177.                     GenerateCookie();
  178.                     d++;
  179.                 }
  180.             } else
  181.             {
  182.                 if (x == cookieX && y == cookieY)
  183.                 {
  184.                     GenerateCookie();
  185.                     d++;
  186.                 }
  187.             }
  188.         }
  189.  
  190.         static void ReadInputs()
  191.         {
  192.      
  193.             var key = Console.ReadKey();
  194.             switch (key.Key)
  195.             {
  196.                 case ConsoleKey.LeftArrow:
  197.                     if (x > 1) x--;
  198.                     else x = 38;
  199.                     break;
  200.  
  201.                 case ConsoleKey.RightArrow:
  202.                     if (x < 38) x++;
  203.                     else x = 1;
  204.  
  205.  
  206.                     break;
  207.  
  208.                 case ConsoleKey.UpArrow:
  209.                     if (y > 2) y--;
  210.                     else y = 19;
  211.                     break;
  212.  
  213.                 case ConsoleKey.DownArrow:
  214.                     if (y < 19) y++;
  215.                     else y = 2;
  216.                     break;
  217.             }
  218.            
  219.         }
  220.     }
  221. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement