Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
3.1 kB
3
Indexable
Never
char playerChar = '*';
ConsoleColor playerColor = ConsoleColor.Green;

int startPlayerPositionX = 1;
int startPlayerPositionY = 1;

int currentPlayerPositionX = startPlayerPositionX;
int currentPlayerPositionY = startPlayerPositionY;

int PointAmount = 0;
int targetPoint = 4;

bool iswon = false;
char[,] map = new char[10, 10]
{
    {'#','#','#','#','#','#','#','#','#','#' },
    {'#',' ',' ',' ',' ',' ','#',' ',' ','#',},
    {'#',' ',' ','#',' ',' ','#','$',' ','#',},
    {'#',' ',' ','#',' ','$','#',' ',' ','#',},
    {'#',' ',' ','#',' ','#','#',' ',' ','#',},
    {'#',' ',' ','#',' ','#','#',' ',' ','#',},
    {'#',' ',' ','#',' ',' ',' ','$','$','#',},
    {'#','#','#','#',' ',' ',' ',' ',' ','#',},
    {'#',' ',' ',' ',' ',' ',' ',' ',' ','#',},
    {'#','#','#','#','#','#','#','#','#','#' },
};
while (!iswon)
{
    Console.Clear();
    Render(map);
    Input();
}

Console.WriteLine();
Console.WriteLine("Pobeda");

void Render(char[,] map)
{
    for (int i = 0; i < map.GetLength(0); i++)
    {
        for (int j = 0; j < map.GetLength(1); j++)
        {
            if (i == currentPlayerPositionY && j == currentPlayerPositionX)
            {
                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)
    {
        Console.WriteLine("ВЫ собрали очков для продолжения Enter");
    }
}


void Input()
{
    switch (Console.ReadKey().Key)
    {
        case ConsoleKey.LeftArrow:
            if (map[currentPlayerPositionY, currentPlayerPositionX - 1] != '#')
            {
                currentPlayerPositionX--;
            }
            break;
        case ConsoleKey.RightArrow:
            if (map[currentPlayerPositionY, currentPlayerPositionX + 1] != '#')
            {
                currentPlayerPositionX++;
            }
            break;
        case ConsoleKey.UpArrow:
            if (map[currentPlayerPositionY - 1, currentPlayerPositionX] != '#')
            {
                currentPlayerPositionY--;
            }
            break;
        case ConsoleKey.DownArrow:
            if (map[currentPlayerPositionY + 1, currentPlayerPositionX] != '#')
            {
                currentPlayerPositionY++;
            }
            break;
        case ConsoleKey.Enter:
            if (PointAmount >= targetPoint)
            {
                iswon = true;
            }
            break;
        default: break;
    }
}
Leave a Comment