Untitled
char playerChar = '*'; ConsoleColor playerColor = ConsoleColor.Green; int startPlayerPositionX = 1; int startPlayerPositionY = 1; int currentPlayerPositionX = startPlayerPositionX; int currentPlayerPositionY = startPlayerPositionY; int pointAmount = 0; int targetPoints = 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 == 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}/{targetPoints}"); if (pointAmount >= targetPoints) { 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 >= targetPoints) { isWon = true; } break; default: break; } }
Leave a Comment