Reputation: 83
So i need help to do my car game, my objective is make the road always appear in the console and keep the lifes in the top of the screen, i already have the function that makes a random from the type of road that appears(function - "DesenharEstrada();"), but i cant keep the lifes printed on the top of the screen because they are inside a "while" and they disappears when the road leave the screen limit. I hope you understand my question, my english is not so good, sorry.
int lifes= 3;
string[] road = { " ", " ", " ", " ", " ", " "," "};
int a=0;
while (lifes> 0)
{
Console.Title = "Road To Hell \n- Vidas: " + vidas;
road = DesenharEstrada();
escreveAvermelho(road[0]);
escreveFundoAcinza(road[1] + road[2]);
escreveAvermelho(road[3]);
escreveFundoAcinza(road[4] + road[5]);
escreveAvermelho(road[6]);
System.Threading.Thread.Sleep(delay);
A_cores(ConsoleColor.Yellow, "Vidas: " + vidas + "\n");
Console.SetCursorPosition(0, Console.CursorTop - 1);
//para o delay não ficar negativo
if (delay < 30)
{
//lifes= lifes - 1;
delay = 30;
}
else if(delay < 100 && a < 3000 )
{
delay = delay - 1;
}
}
//Fim do Jogo
Console.Clear();
writeCol(string.Format(@"
___ ___ ___ ___
/ /\ / /\ /__/\ / /\
/ /:/_ / /::\ | |::\ / /:/_
/ /:/ /\ / /:/\:\ | |:|:\ / /:/ /\
/ /:/_/::\ / /:/~/::\ __|__|:|\:\ / /:/ /:/_
/__/:/__\/\:\ /__/:/ /:/\:\ /__/::::| \:\ /__/:/ /:/ /\
\ \:\ /~~/:/ \ \:\/:/__\/ \ \:\~~\__\/ \ \:\/:/ /:/
\ \:\ /:/ \ \::/ \ \:\ \ \::/ /:/
\ \:\/:/ \ \:\ \ \:\ \ \:\/:/
\ \::/ \ \:\ \ \:\ \ \::/
\__\/ \__\/ \__\/ \__\/
___ ___ ___
/ /\ ___ / /\ / /\
/ /::\ /__/\ / /:/_ / /::\
/ /:/\:\ \ \:\ / /:/ /\ / /:/\:\
/ /:/ \:\ \ \:\ / /:/ /:/_ / /:/~/:/
/__/:/ \__\:\ ___ \__\:\ /__/:/ /:/ /\ /__/:/ /:/___
\ \:\ / /:/ /__/\ | |:| \ \:\/:/ /:/ \ \:\/:::::/
\ \:\ /:/ \ \:\| |:| \ \::/ /:/ \ \::/~~~~
\ \:\/:/ \ \:\__|:| \ \:\/:/ \ \:\
\ \::/ \__\::::/ \ \::/ \ \:\
\__\/ ~~~~ \__\/ \__\/
You made lines. Press Esc to exit"), ConsoleColor.Red);
System.Threading.Thread.Sleep(2000);
Console.ReadKey();
Upvotes: 0
Views: 1249
Reputation: 17
I would create separate classes for your car and road. Give your road class a method that draws only the road, the road and the car never intercepts so you can draw it without messing with the car. Then also make a class for your car and add a method that will draw your car.
Upvotes: 0
Reputation: 469
I would clear the screen and rewrite everything after moving a single line - this might be very slow, but this isn't the way the console was intended to be used.
Upvotes: 1