Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <windows.h>
#include <conio.h>
#include <dos.h>
#include <time.h>
#define AMARILLO (14)
#define ROSA (5)
#define GRIS (8)
void presentacion(void)
{
HANDLE s= GetStdHandle (STD_OUTPUT_HANDLE);
system("cls");
SetConsoleTextAttribute(GetStdHandle (STD_OUTPUT_HANDLE),FOREGROUND_RED|FOREGROUND_INTENSITY);
printf("DEFENDER\n");
printf("\n");
SetConsoleTextAttribute(GetStdHandle (STD_OUTPUT_HANDLE),ROSA|FOREGROUND_INTENSITY);
printf("Press any key to continue");
}
void ciudad(void)
{ int a, b, c;
HANDLE s= GetStdHandle (STD_OUTPUT_HANDLE);
HANDLE q= GetStdHandle(STD_OUTPUT_HANDLE);
COORD coord;
SetConsoleTextAttribute(GetStdHandle (STD_OUTPUT_HANDLE),GRIS|FOREGROUND_INTENSITY);
system("cls");
coord.Y = 23;
for (a=0; a<=78; a++)
{
coord.X= a;
SetConsoleCursorPosition(q, coord);printf("%c\n", 220);
SetConsoleTextAttribute(GetStdHandle (STD_OUTPUT_HANDLE),GRIS|FOREGROUND_INTENSITY);
}
c=10;
for (b=-10; b<60; b++) //ciclo principal
{
b=b+c;
SetConsoleTextAttribute(GetStdHandle (STD_OUTPUT_HANDLE),GRIS|FOREGROUND_INTENSITY);
coord.X = 0+b;
for (a=23; a>=20; a--)
{ coord.Y= a;
SetConsoleCursorPosition(q, coord);printf("%c\n", 219);
SetConsoleTextAttribute(GetStdHandle (STD_OUTPUT_HANDLE),GRIS|FOREGROUND_INTENSITY);
}
coord.Y = 19;
for (a=0; a<=3; a++)
{ coord.X= a+b;
SetConsoleCursorPosition(q, coord);printf("%c\n", 220);
SetConsoleTextAttribute(GetStdHandle (STD_OUTPUT_HANDLE),GRIS|FOREGROUND_INTENSITY);
}
coord.X = 3+b;
for (a=23; a>=20; a--)
{ coord.Y= a;
SetConsoleCursorPosition(q, coord);printf("%c\n", 219);
SetConsoleTextAttribute(GetStdHandle (STD_OUTPUT_HANDLE),GRIS|FOREGROUND_INTENSITY);
}
coord.Y = 21;
for (a=4; a<=9; a++)
{ coord.X= a+b;
SetConsoleCursorPosition(q, coord);printf("%c\n", 220);
SetConsoleTextAttribute(GetStdHandle (STD_OUTPUT_HANDLE),GRIS|FOREGROUND_INTENSITY);
}
coord.X = 9+b;
for (a=22; a<24; a++)
{ coord.Y =a ;
SetConsoleCursorPosition(q, coord);printf("%c\n", 219);
SetConsoleTextAttribute(GetStdHandle (STD_OUTPUT_HANDLE),GRIS|FOREGROUND_INTENSITY);
}
}
fflush(stdout);
}
void random(void)
{
int n, M, R, y, numero;
HANDLE s= GetStdHandle (STD_OUTPUT_HANDLE);
HANDLE q= GetStdHandle(STD_OUTPUT_HANDLE);
COORD coord;
SetConsoleTextAttribute(GetStdHandle (STD_OUTPUT_HANDLE),FOREGROUND_RED|FOREGROUND_INTENSITY);
y=0;
coord.Y = y;
R=0;
n=78;
M=1;
srand( (unsigned)time( NULL ) );
while (R<1)
{
numero = rand () % (n);
coord.X = numero;
SetConsoleCursorPosition (q, coord);
printf("%c\n", 31);
while (y<18)
{
y = y+1;
coord.Y = y;
SetConsoleCursorPosition (q, coord);
Sleep(100);
printf("%c\n", 31);
}
if (y=18)
{
y=0;
coord.X = numero;
SetConsoleCursorPosition (q, coord);
printf("%c\n", 255);
while (y<18)
{
coord.Y = y;
SetConsoleCursorPosition (q, coord);
printf("%c\n", 255);
y = y+1;
}
}
R=R+1;
}
fflush(stdin);
}
void gotoxy0(int m, int y)
{
COORD coord;
coord.X = m;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
void gotoxy1(int j, int y)
{
COORD coord;
coord.X = j;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
void gotoxy2(int x, int y)
{
COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
void gotoxy3(int r, int y)
{
COORD coord;
coord.X = r;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
void gotoxy4(int t, int y)
{
COORD coord;
coord.X = t;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
main()
{
int tecla;
int salir=0;
int y=12,m=38,j=39,x=40,r=41,t=42;
presentacion();
getch();
ciudad ();
SetConsoleTextAttribute(GetStdHandle (STD_OUTPUT_HANDLE),AMARILLO|FOREGROUND_INTENSITY);
printf("Move with: z left, c right ... go out with escape");
SetConsoleTextAttribute(GetStdHandle (STD_OUTPUT_HANDLE),FOREGROUND_RED|FOREGROUND_INTENSITY);
gotoxy2(x,y);
while(salir==0)
{
tecla=getch();
switch(tecla)
{
case 122://izquierda
if (j>0)
{
m-=1;
j-=1;
x-=1;
r-=1;
t-=1;
gotoxy0(m,y);
printf("%c",255);
gotoxy1(j,y);
printf("%c", 22);
gotoxy2(x,y);
printf("%c", 22);
gotoxy3(r,y);
printf("%c", 22);
gotoxy4(t,y);
printf("%c",255);
}
else
{
j=0;
x=1;
r=2;
}
break;
case 99://derecha
if (r<79)
{
m+=1;
j+=1;
x+=1;
r+=1;
t+=1;
gotoxy4(t,y);
printf("%c",255);
gotoxy3(r,y);
printf("%c", 22);
gotoxy2(x,y);
printf("%c", 22);
gotoxy1(j,y);
printf("%c", 22);
gotoxy0(m,y);
printf("%c",255);
}
else
{
j=77;
x=78;
r=79;
}
break;
default:
salir=1;
break;
}
random();
}
return 0;
}