Advertisement
Vadim_Rogulev

Untitled

Apr 20th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.05 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.  
  8. namespace shuffleArray
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             Console.CursorVisible = false;
  15.             Random rand = new Random();
  16.  
  17.  
  18.  
  19.             int maxPoint = 0;
  20.             int point = 0;
  21.  
  22.             string[] newFile = File.ReadAllLines("map.txt");
  23.             char[,] map = new char[newFile.Length, newFile[1].Length];
  24.  
  25.             int packmanX = 0, packmanY = 0;
  26.             int DX = 1, DY = 0;
  27.             bool die = false;
  28.             bool win = false;
  29.  
  30.             int ghostX = 0, ghostY = 0;
  31.             int GDX = 1, GDY = 0;
  32.             int ghostDir = 0;
  33.  
  34.             for (int i = 0; i < map.GetLength(0); i++)
  35.                 for (int j = 0; j < map.GetLength(1); j++)
  36.                     map[i, j] = newFile[i][j];
  37.  
  38.             for (int i = 0; i < map.GetLength(0); i++)
  39.             {
  40.                 for (int j = 0; j < map.GetLength(1); j++)
  41.                 {
  42.                     if (map[i, j] == '@')
  43.                     {
  44.                         packmanX = j;
  45.                         packmanY = i;
  46.                         map[i, j] = ' ';
  47.                     }
  48.                     else if (map[i, j] == ' ')
  49.                     {
  50.                         map[i, j] = '.';
  51.                         maxPoint++;
  52.                     }
  53.                     else if (map[i, j] == 'X')
  54.                     {
  55.                         ghostX = j;
  56.                         ghostY = i;
  57.                         map[i, j] = '.';
  58.                     }
  59.                     Console.Write(map[i, j]);
  60.                 }
  61.                 Console.WriteLine();
  62.             }
  63.            
  64.  
  65.             ConsoleKeyInfo key;
  66.  
  67.             while (!win && !die)
  68.             {
  69.                 if (Console.KeyAvailable)
  70.                 {
  71.                     key = Console.ReadKey(true);
  72.                     switch (key.Key)
  73.                     {
  74.                         case ConsoleKey.UpArrow:
  75.                             DX = 0; DY = -1;
  76.                             break;
  77.                         case ConsoleKey.DownArrow:
  78.                             DX = 0; DY = 1;
  79.                             break;
  80.                         case ConsoleKey.LeftArrow:
  81.                             DX = -1; DY = 0;
  82.                             break;
  83.                         case ConsoleKey.RightArrow:
  84.                             DX = 1; DY = 0;
  85.                             break;
  86.                     }
  87.                 }
  88.                 if (packmanX == 0 && packmanY == 10)
  89.                 {
  90.                     Teleport(ref packmanX,ref packmanY, 10, 45, '|','@');
  91.                    // packmanY = 10;
  92.                   // packmanX = 45;
  93.                 }
  94.                 if (packmanX == 48 && packmanY == 10)
  95.                 {
  96.                    
  97.                     Teleport(ref packmanX,ref packmanY, 10, 3, '|', '@');
  98.                     //packmanY = 10;
  99.                     //packmanX = 3;
  100.                 }
  101.  
  102.                 System.Threading.Thread.Sleep(100);
  103.  
  104.                 if (map[packmanY + DY, packmanX + DX] != '#')
  105.                 {
  106.                     Teleport(ref packmanX, ref packmanY, packmanY+ DY, packmanX+ DX, ' ', '@');
  107.                     // Console.SetCursorPosition(packmanX, packmanY);
  108.                     // Console.Write(' ');
  109.                     // packmanX += DX;
  110.                     // packmanY += DY;
  111.                     // Console.SetCursorPosition(packmanX, packmanY);
  112.                     // Console.Write('@');
  113.  
  114.                     if (map[packmanY, packmanX] == '.')
  115.                     {
  116.                         point++;
  117.                         map[packmanY, packmanX] = ' ';
  118.                         Console.SetCursorPosition(0, map.GetLength(0) + 5);
  119.                         Console.Write("Вы собрали " + point + "/" + maxPoint + " очков.");
  120.                     }
  121.                 }
  122.  
  123.                 if (map[ghostY + GDY, ghostX + GDX] == '#')
  124.                 {
  125.                     ghostDir = rand.Next(1, 5);
  126.  
  127.                     switch (ghostDir)
  128.                     {
  129.                         case 1:
  130.                             GDX = 0; GDY = -1;
  131.                             break;
  132.                         case 2:
  133.                             GDX = 0; GDY = 1;
  134.                             break;
  135.                         case 3:
  136.                             GDX = -1; GDY = 0;
  137.                             break;
  138.                         case 4:
  139.                             GDX = 1; GDY = 0;
  140.                             break;
  141.                     }
  142.                 }
  143.                 else
  144.                 {
  145.                     Teleport(ref ghostX, ref ghostY, ghostY + GDY, ghostX + GDX, map[ghostY, ghostX], 'X');
  146.                    // Console.SetCursorPosition(ghostX, ghostY);
  147.                    // Console.Write(map[ghostY, ghostX]);
  148.                    // ghostX += GDX;
  149.                    // ghostY += GDY;
  150.                    // Console.SetCursorPosition(ghostX, ghostY);
  151.                    // Console.Write('X');
  152.                     if (ghostX == packmanX && ghostY == packmanY)
  153.                         die = true;
  154.  
  155.                 }
  156.  
  157.                 if (point == maxPoint)
  158.                 {
  159.                     win = true;
  160.                 }
  161.  
  162.             }
  163.  
  164.             if (win)
  165.             {
  166.                 Console.Clear();
  167.                 Console.Write("Победа!");
  168.             }
  169.             else
  170.             {
  171.                 Console.Clear();
  172.                 Console.Write("Поражение!");
  173.             }
  174.  
  175.         }
  176.          static void Teleport( ref int Xu, ref int Yu, int a, int b, char Char, char CharU)
  177.         {
  178.             Console.SetCursorPosition(Xu, Yu);
  179.             Console.Write(Char);
  180.             Yu = a;
  181.             Xu = b;
  182.             Console.SetCursorPosition(Xu, Yu);
  183.             Console.Write(CharU);
  184.            
  185.            
  186.            
  187.         }
  188.  
  189.     }
  190. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement