Задание - игра наподобие "Тепло или холодно" - C#
Формулировка задачи:
Прошу помощи.
Нужно сделать игру на подобии "Тепло или холодно".
Чтобы игроку со старта присвоились рандомные координаты и при передвижении вверх, вниз, влево и вправо ему писало правильно он идет или нет.
В общем не понятно как сделать чтобы ему это писало.
Решение задачи: «Задание - игра наподобие "Тепло или холодно"»
textual
Листинг программы
Random rand = new Random();
int x = rand.Next(0, 10);
int y = rand.Next(0, 10);
int playerX = rand.Next(0, 10);
int playerY = rand.Next(0, 10);
int xR;
Console.WriteLine("Вы должны добраться до сокровища. Вы можете идти вверх, вниз, направо, налево.\nПри каждой шаге вам будут говорить - тепло или холодно.");
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Сокровище спрятано. Игра начинается");
Console.ForegroundColor = ConsoleColor.White;
// xR = playerX;
//if(playerX)
ConsoleKeyInfo input;
do
{
input = Console.ReadKey(true);
if (playerX >= x)
{
if (input.Key == ConsoleKey.LeftArrow)
{
playerX = playerX - 1;
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Тепло");
}
if (input.Key == ConsoleKey.RightArrow)
{
playerX = playerX + 1;
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("Холодно");
}
}
else
{
if (input.Key == ConsoleKey.LeftArrow)
{
playerX = playerX - 1;
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("Холодно");
}
if (input.Key == ConsoleKey.RightArrow)
{
playerX = playerX + 1;
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Тепло");
}
}
if (playerY >= y)
{
if (input.Key == ConsoleKey.UpArrow)
{
playerY = playerY - 1;
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Тепло");
}
if (input.Key == ConsoleKey.DownArrow)
{
playerY = playerY + 1;
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("Холодно");
}
}
else
{
if (input.Key == ConsoleKey.UpArrow)
{
playerY = playerY - 1;
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("Холодно");
}
if (input.Key == ConsoleKey.DownArrow)
{
playerY = playerY + 1;
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Тепло");
}
}
if ((playerX == x) && (playerY == y))
break;
} while (input.Key != ConsoleKey.Escape);
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Сокровище было на координатах" + " x: " + x + " y: " + y);
Console.WriteLine("Вы дошли до координатов" + " x: " + playerX + " y: " + playerY);
Console.ReadLine();