Untitled
Dauren igraunknown
csharp
2 years ago
3.2 kB
8
Indexable
using System.Drawing;
char playerChar = '*';
ConsoleColor playerColor = ConsoleColor.Green;
int startPlayerPositionX = 1;
int startPlayerPositionY = 1;
int currentPlayerPositionX = startPlayerPositionX;
int currentPlayerPositionY = startPlayerPositionY;
int pointAmaunt = 0;
int targetPoints = 3;
bool isWon = false; // Victory
char[,] map = new char[10, 10]
{
{ '#','#','#','#','#','#','#','#','#','#', },
{ '#',' ',' ',' ',' ',' ',' ',' ','$','#', },
{ '#',' ',' ','#',' ',' ',' ',' ',' ','#', },
{ '#','$',' ','#',' ',' ',' ',' ',' ','#', },
{ '#',' ',' ','#',' ',' ',' ',' ','$','#', },
{ '#',' ',' ',' ',' ',' ',' ',' ',' ','#', },
{ '#',' ',' ',' ',' ','$',' ',' ',' ','#', },
{ '#','$',' ',' ',' ',' ',' ',' ',' ','#', },
{ '#',' ',' ',' ',' ',' ',' ',' ',' ','#', },
{ '#','#','#','#','#','#','#','#','#','#', },
};
while (true)
{
Render(map);
Input();
if(isWon) //
{
Console.WriteLine();
Console.WriteLine("Congratulation");
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] == '$')
{
pointAmaunt++;
map[i, j] = 'D';
}
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($"Sobrano ochkov: + {pointAmaunt}/{targetPoints}");
if (pointAmaunt >= targetPoints)
{
Console.WriteLine("Vy Sobrano dostatocno ochkov");
}
}
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 (pointAmaunt >= targetPoints)
{
isWon = true;
}
break;
default:
break;
}
}Editor is loading...
Leave a Comment