Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- using System.Threading;
- namespace Task6
- {
- class Program
- {
- static void Main(string[] args)
- {
- Thread thr = new Thread(new ThreadStart(MissionImp));
- thr.Start();
- int height =Console.WindowHeight;
- Console.WindowHeight=height+10;
- Console.CursorVisible = false;
- string[] NewFile = File.ReadAllLines("map.txt");
- char[,] map = new char[NewFile.Length, NewFile[1].Length];
- Random rand = new Random();
- int packmanY = 1, packmanX = 1;
- int DX = 0, DY = 0;
- int point = 0, pointMax = 0;
- bool endGame = false;
- int ghostY = 10, ghostX = 10;
- int DXG = 1, DYG = 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] == '@')
- {
- packmanY = j;
- packmanX = i;
- map[i, j] = ' ';
- }
- else if (map[i, j] == ' ')
- {
- map[i, j] = '·';
- pointMax++;
- }
- else if (map[i, j] == '%')
- {
- ghostX = i;
- ghostY = j;
- map[i, j] = '.';
- }
- Console.Write(map[i, j]);
- }
- Console.WriteLine();
- }
- ConsoleKeyInfo Key;
- while (!endGame)
- {
- if (Console.KeyAvailable)
- {
- Key = Console.ReadKey(true);
- switch (Key.Key)
- {
- case ConsoleKey.LeftArrow:
- DX = 0; DY = -1;
- break;
- case ConsoleKey.RightArrow:
- DX = 0; DY = 1;
- break;
- case ConsoleKey.UpArrow:
- DX = -1; DY = 0;
- break;
- case ConsoleKey.DownArrow:
- DX = 1; DY = 0;
- break;
- }
- }
- System.Threading.Thread.Sleep(125);
- if (map[packmanX + DX, packmanY + DY] != '#')
- {
- // pproverka()
- proverka(ref DX, ref DY,ref packmanY,ref packmanX, '@',map);
- //
- if (map[packmanX, packmanY] == '·')
- {
- point++;
- map[packmanX, packmanY] = ' ';
- Console.SetCursorPosition(0, map.GetLength(0) + 5);
- Console.Write("Собрано очков: " + point + "/" + pointMax);
- if (point == pointMax) endGame = true;
- }
- }
- if (map[ghostX + DXG, ghostY + DYG] == '#')
- {
- int ghostDir = rand.Next(1, 5);
- switch (ghostDir)
- {
- case 1:
- DXG = 0; DYG = -1;
- break;
- case 2:
- DXG = 0; DYG = 1;
- break;
- case 3:
- DXG = -1; DYG = 0;
- break;
- case 4:
- DXG = 1; DYG = 0;
- break;
- }
- }
- else
- {
- proverka(ref DXG, ref DYG, ref ghostY, ref ghostX, '%',map);
- if (ghostX == packmanX && ghostY == packmanY) endGame = true;
- }
- // переход сверху вниз слево направо
- perehod(ref DX, ref DY, ref packmanY, ref packmanX, map,'@');
- perehod(ref DXG, ref DYG, ref ghostY, ref ghostX, map,'%');
- }
- Console.SetCursorPosition(0, map.GetLength(0) + 8);
- }
- static void perehod(ref int DX,ref int DY,ref int Y, ref int X, char[,]map, char chra)
- {
- if (chra == '@')
- {
- if (DY == 1 && Y == (map.GetLength(1) - 1))
- {
- Console.SetCursorPosition(Y, X);
- Console.Write(' ');
- Y = 0;
- Console.SetCursorPosition(Y, X);
- Console.Write('@');
- }
- if (DY == -1 && Y == 0)
- {
- Console.SetCursorPosition(Y, X);
- Console.Write(' ');
- Y = map.GetLength(1) - 1;
- Console.SetCursorPosition(Y, X);
- Console.Write('@');
- }
- if (DX == -1 && X == 0)
- {
- Console.SetCursorPosition(Y, X);
- Console.Write(' ');
- X = map.GetLength(0) - 1;
- Console.SetCursorPosition(Y, X);
- Console.Write('@');
- }
- if (DX == 1 && X == (map.GetLength(0) - 1))
- {
- Console.SetCursorPosition(Y, X);
- Console.Write(' ');
- X = 0;
- Console.SetCursorPosition(Y, X);
- Console.Write('@');
- }
- }
- if (chra == '%')
- {
- if (DY == 1 && Y == (map.GetLength(1) - 1))
- {
- Console.SetCursorPosition(Y, X);
- Console.Write(map[X, Y]);
- Y = 0;
- }
- if (DY == -1 && Y == 0)
- {
- Console.SetCursorPosition(Y, X);
- Console.Write(map[X, Y]);
- Y = map.GetLength(1) - 1;
- }
- if (DX == -1 && X == 0)
- {
- Console.SetCursorPosition(Y, X);
- Console.Write(map[X, Y]);
- X = map.GetLength(0) - 1;
- }
- if (DX == 1 && X == (map.GetLength(0) - 1))
- {
- Console.SetCursorPosition(Y, X);
- Console.Write(map[X, Y]);
- X = 0;
- }
- }
- }
- static void proverka(ref int DiX,ref int DiY,ref int Y, ref int X, char chra,char[,] map)
- {
- Console.ForegroundColor = ConsoleColor.White;
- if (chra =='@')
- {
- Console.SetCursorPosition(Y, X);
- Console.Write(' ');
- Console.ForegroundColor = ConsoleColor.Yellow;
- X += DiX;
- Y += DiY;
- Console.SetCursorPosition(Y, X);
- Console.Write(chra);
- }
- if (chra =='%')
- {
- Console.SetCursorPosition(Y, X);
- Console.Write(map[X, Y]);
- X += DiX;
- Y += DiY;
- Console.ForegroundColor = ConsoleColor.Red;
- Console.SetCursorPosition(Y, X);
- Console.Write(chra);
- }
- Console.ForegroundColor = ConsoleColor.White;
- }
- public static void MissionImp()
- {
- while (true)
- {
- Console.Beep(784, 150);
- Thread.Sleep(300);
- Console.Beep(784, 150);
- Thread.Sleep(300);
- Console.Beep(932, 150);
- Thread.Sleep(150);
- Console.Beep(1047, 150);
- Thread.Sleep(150);
- Console.Beep(784, 150);
- Thread.Sleep(300);
- Console.Beep(784, 150);
- Thread.Sleep(300);
- Console.Beep(699, 150);
- Thread.Sleep(150);
- Console.Beep(740, 150);
- Thread.Sleep(150);
- Console.Beep(784, 150);
- Thread.Sleep(300);
- Console.Beep(784, 150);
- Thread.Sleep(300);
- Console.Beep(932, 150);
- Thread.Sleep(150);
- Console.Beep(1047, 150);
- Thread.Sleep(150);
- Console.Beep(784, 150);
- Thread.Sleep(300);
- Console.Beep(784, 150);
- Thread.Sleep(300);
- Console.Beep(699, 150);
- Thread.Sleep(150);
- Console.Beep(740, 150);
- Thread.Sleep(150);
- Console.Beep(932, 150);
- Console.Beep(784, 150);
- Console.Beep(587, 1200);
- Thread.Sleep(75);
- Console.Beep(932, 150);
- Console.Beep(784, 150);
- Console.Beep(554, 1200);
- Thread.Sleep(75);
- Console.Beep(932, 150);
- Console.Beep(784, 150);
- Console.Beep(523, 1200);
- Thread.Sleep(150);
- Console.Beep(466, 150);
- Console.Beep(523, 150);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement