Advertisement
VitalyD

Untitled

Jun 27th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.96 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 _1393
  8. {
  9.     class Program
  10.     {
  11.         static int[,] arraymap = {
  12.                 { 0, 0, 1, 0, 0,   0, 0, 0, 0, 0,   0, 0, 0, 0, 0 },
  13.                 { 0, 0, 0, 1, 0,   0, 0, 0, 0, 1,   0, 0, 1, 0, 0 },
  14.                 { 0, 0, 0, 0, 2,   0, 0, 0, 0, 0,   0, 0, 0, 0, 0 },
  15.                 { 0, 0, 0, 0, 2,   0, 0, 0, 3, 0,   0, 2, 0, 0, 1 },
  16.                 { 0, 0, 0, 0, 2,   2, 2, 2, 2, 2,   0, 2, 0, 0, 0 },
  17.  
  18.                 { 0, 0, 0, 0, 0,   0, 0, 0, 0, 2,   0, 2, 0, 0, 0 },
  19.                 { 0, 0, 1, 0, 0,   0, 0, 0, 0, 2,   0, 0, 0, 0, 1 },
  20.                 { 0, 0, 0, 0, 0,   0, 1, 0, 0, 0,   0, 2, 0, 0, 0 },
  21.                 { 0, 0, 0, 0, 0,   0, 0, 0, 0, 0,   0, 2, 0, 0, 0 },
  22.                 { 0, 0, 1, 0, 1,   0, 0, 0, 0, 0,   0, 2, 0, 0, 0 }
  23.             };
  24.         static int coins = 0;
  25.  
  26.         static int n = 10;
  27.         static int m = 15;
  28.  
  29.         public static void Main(string[] args)
  30.         {
  31.             Console.CursorVisible = false;
  32.  
  33.  
  34.             DrawField();
  35.             Console.WriteLine ("Деньжат собрано: " + coins);
  36.             while (true)
  37.             {
  38.                 ConsoleKeyInfo input = Console.ReadKey();
  39.                 input = Moving(input);
  40.             }
  41.         }
  42.  
  43.         static void DrawField()
  44.         {
  45.             for (int i = 0; i < n; i++)
  46.             {
  47.                 for (int j = 0; j < m; j++)
  48.                 {
  49.                     if (arraymap[i, j] == 0)
  50.                     {
  51.                         Console.Write('-');
  52.                     }
  53.                     else if (arraymap[i, j] == 1)
  54.                     {
  55.                         Console.Write('$');
  56.                     }
  57.                     else if (arraymap[i, j] == 2)
  58.                     {
  59.                         Console.Write('*');
  60.                     }
  61.                     else if (arraymap[i, j] == 3)
  62.                     {
  63.                         Console.Write('@');
  64.                     }
  65.                 }
  66.                 Console.WriteLine();
  67.             }
  68.         }
  69.  
  70.         static void MoveLeft()
  71.         {
  72.                 for (int i = 0; i < n; i++)
  73.                 {
  74.                     for (int j = 1; j < m; j++)
  75.                     {
  76.                         if (arraymap[i, j] == 3)
  77.                         {
  78.                             if (arraymap[i, j - 1] == 0)
  79.                             {
  80.                                 arraymap[i, j - 1] = 3;
  81.                                 arraymap[i, j] = 0;
  82.                             }
  83.                             else if (arraymap[i, j - 1] == 1)
  84.                             {
  85.                                 arraymap[i, j - 1] = 3;
  86.                                 arraymap[i, j] = 0;
  87.                                 coins++;
  88.                             }
  89.                         }
  90.                     }
  91.                 }
  92.         }
  93.  
  94.         static void MoveDown()
  95.         {
  96.                 for (int i = n-2 ; i >= 0; i--)
  97.                 {
  98.                     for (int j = 0; j < m; j++)
  99.                     {
  100.                         if (arraymap[i, j] == 3)
  101.                         {
  102.                             if (arraymap[i + 1, j] == 0)
  103.                             {
  104.                                 arraymap[i + 1, j] = 3;
  105.                                 arraymap[i, j] = 0;
  106.                             }
  107.                             else if (arraymap[i + 1, j] == 1)
  108.                             {
  109.                                 arraymap[i + 1, j] = 3;
  110.                                 arraymap[i, j] = 0;
  111.                                  coins++;
  112.                         }
  113.                         }
  114.                     }
  115.                 }
  116.         }
  117.  
  118.         static void MoveRight()
  119.         {  
  120.                 for (int i = 0; i < n; i++)
  121.                 {
  122.                     for (int j = m-2; j > -1; j--)
  123.                     {
  124.                         if (arraymap[i, j] == 3)
  125.                         {
  126.                             if (arraymap[i, j + 1] == 0)
  127.                             {
  128.                                 arraymap[i, j + 1] = 3;
  129.                                 arraymap[i, j] = 0;
  130.                             }
  131.                             else if (arraymap[i, j + 1] == 1)
  132.                             {
  133.                                 arraymap[i, j + 1] = 3;
  134.                                 arraymap[i, j] = 0;
  135.                                 coins++;
  136.                         }
  137.                         }
  138.                     }
  139.                 }
  140.            
  141.         }
  142.  
  143.         static void MoveUp()
  144.         {
  145.                 for (int i = 1; i < n; i++)
  146.                 {
  147.                     for (int j = 0; j < m; j++)
  148.                     {
  149.                         if (arraymap[i, j] == 3)
  150.                         {
  151.                             if (arraymap[i - 1, j] == 0)
  152.                             {
  153.                                 arraymap[i - 1, j] = 3;
  154.                                 arraymap[i, j] = 0;
  155.                             }
  156.                             else if (arraymap[i - 1, j] == 1)
  157.                             {
  158.                                 arraymap[i, j - 1] = 3;
  159.                                 arraymap[i, j] = 0;
  160.                                 coins++;
  161.                         }
  162.                         }
  163.                     }
  164.                 }
  165.         }
  166.  
  167.         private static ConsoleKeyInfo Moving(ConsoleKeyInfo input)
  168.         {
  169.             if (input.Key == ConsoleKey.LeftArrow) MoveLeft();
  170.             if (input.Key == ConsoleKey.RightArrow) MoveRight();
  171.             if (input.Key == ConsoleKey.UpArrow) MoveUp();
  172.             if (input.Key == ConsoleKey.DownArrow) MoveDown();
  173.             Console.Clear();
  174.             DrawField();
  175.             Console.WriteLine("Деньжат собрано: " + coins);
  176.             return input;
  177.         }
  178.     }
  179. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement