Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- namespace shuffleArray
- {
- class Program
- {
- static void Redraw(ref int posX, ref int posY, char[,] array, int DX, int DY, char symbol)
- {
- Console.SetCursorPosition(posX, posY);
- Console.Write(array[posY, posX]);
- posX += DX;
- posY += DY;
- Console.SetCursorPosition(posX, posY);
- Console.Write(symbol);
- }
- static void Main(string[] args)
- {
- Console.CursorVisible = false;
- Random rand = new Random();
- int maxPoint = 0;
- int point = 0;
- string[] newFile = File.ReadAllLines("map.txt");
- char[,] map = new char[newFile.Length, newFile[1].Length];
- int packmanX = 0, packmanY = 0;
- int DX = 1, DY = 0;
- bool die = false;
- bool win = false;
- int ghostX = 0, ghostY = 0;
- int GDX = 1, GDY = 0;
- int ghostDir = 0;
- for (int i = 0; i < map.GetLength(0); i++)
- for (int j = 0; j < map.GetLength(1); j++)
- map[i, j] = newFile[i][j];
- for (int i = 0; i < map.GetLength(0); i++)
- {
- for (int j = 0; j < map.GetLength(1); j++)
- {
- if (map[i, j] == '@')
- {
- packmanX = j;
- packmanY = i;
- map[i, j] = ' ';
- }
- else if (map[i, j] == ' ')
- {
- map[i, j] = '.';
- maxPoint++;
- }
- else if (map[i, j] == 'X')
- {
- ghostX = j;
- ghostY = i;
- map[i, j] = '.';
- maxPoint++;
- }
- Console.Write(map[i, j]);
- }
- Console.WriteLine();
- }
- ConsoleKeyInfo key;
- while (!win && !die)
- {
- if (Console.KeyAvailable)
- {
- key = Console.ReadKey(true);
- switch (key.Key)
- {
- case ConsoleKey.UpArrow:
- DX = 0; DY = -1;
- break;
- case ConsoleKey.DownArrow:
- DX = 0; DY = 1;
- break;
- case ConsoleKey.LeftArrow:
- DX = -1; DY = 0;
- break;
- case ConsoleKey.RightArrow:
- DX = 1; DY = 0;
- break;
- }
- }
- System.Threading.Thread.Sleep(100);
- if (map[packmanY + DY, packmanX + DX] != '#')
- {
- Redraw(ref packmanX,ref packmanY, map, DX,DY, '☺');
- if (map[packmanY, packmanX] == '.')
- {
- point++;
- map[packmanY, packmanX] = ' ';
- Console.SetCursorPosition(0, map.GetLength(0) + 5);
- Console.Write("Вы собрали " + point + "/" + maxPoint + " очков.");
- }
- }
- if (map[packmanY, packmanX] == 'O')
- {
- if (packmanX<map.GetLength(0))
- {
- Console.SetCursorPosition(packmanX, packmanY);
- Console.Write(map[packmanY, packmanX]);
- packmanX = map.GetLength(1) - 1;
- }
- else
- packmanX = 1;
- Redraw(ref packmanX, ref packmanY, map, DX, DY, '☺');
- }
- if (map[ghostY + GDY, ghostX + GDX] == '#')
- {
- ghostDir = rand.Next(1, 5);
- switch (ghostDir)
- {
- case 1:
- GDX = 0; GDY = -1;
- break;
- case 2:
- GDX = 0; GDY = 1;
- break;
- case 3:
- GDX = -1; GDY = 0;
- break;
- case 4:
- GDX = 1; GDY = 0;
- break;
- }
- }
- else
- {
- Redraw(ref ghostX, ref ghostY, map, GDX, GDY, '☻');
- if (ghostX == packmanX && ghostY == packmanY)
- die = true;
- }
- if (point == maxPoint)
- {
- win = true;
- }
- }
- if (win)
- {
- Console.Clear();
- Console.Write("Победа!");
- }
- else
- {
- Console.Clear();
- Console.Write("Поражение!");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment