Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
3.5 kB
3
Indexable
Never
using System.Data;

char playerChar = '*';
ConsoleColor playerColor = ConsoleColor.Green;

int statPlayerPositionX = 1;
int statPlayerPositionY = 1;

int currectPlayerPositionX = statPlayerPositionX;
int currectPlayerPositionY = statPlayerPositionY;

int pointAmount = 0;
int targetPoint = 3;

bool isWon = false; // Состояние победы

char[,] map = new char[10, 10]
{
    { '#','#','#','#','#','#','#','#','#','#', },
    { '#',' ','#',' ',' ',' ',' ','#',' ','#', },
    { '#',' ','#',' ','#',' ',' ','#',' ','#', },
    { '#',' ','#',' ','#',' ',' ','#',' ','#', },
    { '#',' ','#',' ','#',' ',' ','#',' ','#', },
    { '#',' ','$',' ','#','$',' ','#',' ','#', },
    { '#',' ',' ',' ','#',' ',' ','#',' ','#', },
    { '#',' ',' ',' ','#',' ','$',' ',' ','#', },
    { '#',' ',' ','$','#',' ',' ',' ','$','#', },
    { '#','#','#','#','#','#','#','#','#','#', },
};

while (true)
{
    Render(map);
    Input(); 

    if (isWon) // or if(isWon == true)
    {
        Console.WriteLine();
        Console.WriteLine("Поздравляю вы победили");
        break;
    }
}

void Render(char[,] map)
{
    Console.Clear();

    for (int i = 0; i < map.GetLength(0); i++)
    {
        for (int j = 0; j < map.GetLength(1); j++)
        {
            if (i == currectPlayerPositionY && j == currectPlayerPositionX)
            { 
                if (map[i, j] == '$')
                {
                    pointAmount++;
                    map[i, j] = 'x';
                }

                Console.ForegroundColor = playerColor;
                Console.Write(playerChar + " ");
            }
            else
            {
                if (map[i, j] == '$')
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                }

                Console.Write(map[i, j] + " ");
            }

            Console.ResetColor();
        }

        Console.WriteLine();
    }

    Console.WriteLine($"Собрано очков:  {pointAmount}/{targetPoint}");

    if (pointAmount >= targetPoint)
    { 
        isWon = true;
        Console.WriteLine("Вы собрали достаточно очков для продолжения. Нажмите ENTER");
    }
}
 void Input()
{
    switch (Console.ReadKey().Key)
    {
        case ConsoleKey.LeftArrow:
            if (map[currectPlayerPositionY, currectPlayerPositionX - 1] != '#')
            {
                currectPlayerPositionX--;
            }
            break;
        case ConsoleKey.RightArrow:
            {
                if (map[currectPlayerPositionY, currectPlayerPositionX + 1] != '#')
                {
                    currectPlayerPositionX++;
                }
            }
            break;
        case ConsoleKey.UpArrow:
            {
                if (map[currectPlayerPositionY - 1, currectPlayerPositionX] != '#')
                {
                    currectPlayerPositionY--;
                }
            }

            break;
        case ConsoleKey.DownArrow:
            if (map[currectPlayerPositionY + 1, currectPlayerPositionX] != '#')
            {
                currectPlayerPositionY++;
            }
            break;
         case ConsoleKey.Enter:
            if (pointAmount >= targetPoint)
            {
               isWon = true;
            }
            break;
        default:
            break;
    }
}
Leave a Comment