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;
- namespace shuffleArray
- {
- class Program
- {
- 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] = '.';
- }
- 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;
- }
- }
- if (packmanX == 0 && packmanY == 10)
- {
- Teleport(ref packmanX,ref packmanY, 10, 45, '|','@');
- // packmanY = 10;
- // packmanX = 45;
- }
- if (packmanX == 48 && packmanY == 10)
- {
- Teleport(ref packmanX,ref packmanY, 10, 3, '|', '@');
- //packmanY = 10;
- //packmanX = 3;
- }
- System.Threading.Thread.Sleep(100);
- if (map[packmanY + DY, packmanX + DX] != '#')
- {
- Teleport(ref packmanX, ref packmanY, packmanY+ DY, packmanX+ DX, ' ', '@');
- // Console.SetCursorPosition(packmanX, packmanY);
- // Console.Write(' ');
- // packmanX += DX;
- // packmanY += DY;
- // Console.SetCursorPosition(packmanX, packmanY);
- // Console.Write('@');
- if (map[packmanY, packmanX] == '.')
- {
- point++;
- map[packmanY, packmanX] = ' ';
- Console.SetCursorPosition(0, map.GetLength(0) + 5);
- Console.Write("Вы собрали " + point + "/" + maxPoint + " очков.");
- }
- }
- 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
- {
- Teleport(ref ghostX, ref ghostY, ghostY + GDY, ghostX + GDX, map[ghostY, ghostX], 'X');
- // Console.SetCursorPosition(ghostX, ghostY);
- // Console.Write(map[ghostY, ghostX]);
- // ghostX += GDX;
- // ghostY += GDY;
- // Console.SetCursorPosition(ghostX, ghostY);
- // Console.Write('X');
- if (ghostX == packmanX && ghostY == packmanY)
- die = true;
- }
- if (point == maxPoint)
- {
- win = true;
- }
- }
- if (win)
- {
- Console.Clear();
- Console.Write("Победа!");
- }
- else
- {
- Console.Clear();
- Console.Write("Поражение!");
- }
- }
- static void Teleport( ref int Xu, ref int Yu, int a, int b, char Char, char CharU)
- {
- Console.SetCursorPosition(Xu, Yu);
- Console.Write(Char);
- Yu = a;
- Xu = b;
- Console.SetCursorPosition(Xu, Yu);
- Console.Write(CharU);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement