Ho trovato su internet un codice che utilizza le librerie #include <stdio.h> #include <stdlib.h> #include <stdarg.h>#include <string.h> #include <windows.h>

Ecco il codice:

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <windows.h>

#define MAN_LIFE 3
#define MAN_JMP 6
#define MAN_CHAR 'O'
#define MAN_COLOR 153

#define WORLD_CHAR '#'
#define WORLD_COLOR 42

#define OBJ_PORT_CHAR '8'
#define OBJ_PORT_COLOR 14

#define CONSOLE_WIDTH 80
#define CONSOLE_HEIGHT 24

#define KEYDOWN 0x8000

///BASE WINDOWS CONSOLE FUNCTION

void gotoxy (short x,short y)
{
COORD coord = {x, y};
HANDLE hconsole = GetStdHandle(STD_OUTPUT_HANDLE);
if (hconsole == INVALID_HANDLE_VALUE) return;
SetConsoleCursorPosition (hconsole,coord );
}

void cls()
{
CONSOLE_SCREEN_BUFFER_INFO csbi;
const COORD startCoords = {0,0};
DWORD dummy;
HANDLE hconsole = GetStdHandle(STD_OUTPUT_HANDLE);
if (hconsole == INVALID_HANDLE_VALUE) return;
GetConsoleScreenBufferInfo(hconsole,&csbi);
FillConsoleOutputAttribute(hconsole,0,csbi.dwSize. X * csbi.dwSize.Y,startCoords,&dummy);
FillConsoleOutputCharacter(hconsole,' ',csbi.dwSize.X * csbi.dwSize.Y,startCoords,&dummy);
gotoxy(0,0);
}

void textcolor(unsigned short color)
{
HANDLE hconsole = GetStdHandle(STD_OUTPUT_HANDLE);
if (hconsole == INVALID_HANDLE_VALUE) return;
SetConsoleTextAttribute(hconsole,color);
}

void printfk(char* format,...)
{
va_list ap;
va_start(ap,format);

char data[32];
char* pdata;
int vap;
char* pcap;
double dap;
int* piap;
int process;
while (*format != '\0')
{
if (*format != '%')
{
putchar(*format);
++format;
}
else
{
pdata = data;
process = 0;
while (*format != '\0')
{
*pdata++ = *format++;
switch (*format)
{
case 'd':
case 'i':
case 'o':
case 'u':
case 'x':
case 'X':
case 'c':
vap = va_arg(ap,int);
*pdata++ = *format++;
*pdata = '\0';
printf(data,vap);
process = 1;
break;
case 's':
pcap = va_arg(ap,char*);
*pdata++ = *format++;
*pdata = '\0';
printf(data,pcap);
process = 1;
break;
case 'e':
case 'f':
case 'g':
dap = va_arg(ap,double);
*pdata++ = *format++;
*pdata = '\0';
printf(data,dap);
process = 1;
break;
case 'p':
case 'n':
piap = va_arg(ap,int*);
*pdata++ = *format++;
*pdata = '\0';
printf(data,piap);
process = 1;
break;
case '%':

*pdata = '\0';
printf(data);
process = 1;
break;
case 'k':
if (pdata - data == 1)
vap = va_arg(ap,int);
else
{
*pdata = '\0';
data[0] = '0';
vap = atoi(data);
}
++format;
textcolor(vap);
process = 1;
break;
}//switch %
if (process) break;
}//while %
}//is %
}//every char format

va_end(ap);
}


int main()
{
//LIVELLO1
char maplevel1[CONSOLE_HEIGHT][CONSOLE_WIDTH + 1];
strcpy(maplevel1[0] ," ");
strcpy(maplevel1[1] ," ");
strcpy(maplevel1[2] ," ");
strcpy(maplevel1[3] ," ");
strcpy(maplevel1[4] ," ");
strcpy(maplevel1[5] ," ");
strcpy(maplevel1[6] ," ");
strcpy(maplevel1[7] ," ");
strcpy(maplevel1[8] ," ");
strcpy(maplevel1[9] ," ");
strcpy(maplevel1[10]," ");
strcpy(maplevel1[11]," ");
strcpy(maplevel1[12]," 8 ");
strcpy(maplevel1[13]," # ");
strcpy(maplevel1[14]," ### ");
strcpy(maplevel1[15]," ##### ");
strcpy(maplevel1[16]," ###### ");
strcpy(maplevel1[17]," ");
strcpy(maplevel1[18]," O a ");
strcpy(maplevel1[19],"################################################ ################################");
strcpy(maplevel1[20]," ");
strcpy(maplevel1[21]," ");
strcpy(maplevel1[22]," ");
strcpy(maplevel1[23]," ");

int manx,many,manjmp,manstj;
int oldx,oldy;
int startlevelx;
int startlevely;
int life;
//int mov;
int endlevel;

//property
manx = 0;
many = 0;
oldx = 0;
oldy = 0;
manjmp = 0;
manstj = 0;
life = MAN_LIFE;
endlevel = 0;

//drawlevel
cls();
int iy,ix;
for (iy = 0 ; iy < CONSOLE_HEIGHT; iy++)
{
for (ix = 0; ix < CONSOLE_WIDTH - 0;ix++ )
{
if (maplevel1[iy][ix] == WORLD_CHAR)
{
printfk("%k%c",WORLD_COLOR,WORLD_CHAR);
}
else if (maplevel1[iy][ix] == MAN_CHAR)
{
manx = ix;
many = iy;
oldx = manx;
oldy = many;
startlevelx = manx;
startlevely = many;
maplevel1[iy][ix] = ' ';
printfk("%k%c",MAN_COLOR,MAN_CHAR);
}
else if (maplevel1[iy][ix] == OBJ_PORT_CHAR)
{
printfk("%k%c",OBJ_PORT_COLOR,OBJ_PORT_CHAR);
}
else
{
printfk("%7k%c",maplevel1[iy][ix]);
}
}
}

//gioco fino a che ho delle vite
while(life && !endlevel)
{
//game:
//Leggo Movimenti
if (GetAsyncKeyState('A') & KEYDOWN)
--manx;
else if (GetAsyncKeyState('D') & KEYDOWN)
++manx;
if ( (GetAsyncKeyState('W') & KEYDOWN) && manstj == 0 )
manstj = 1;

//eseguo salto
if (manstj == 1)
{
--many;
if (++manjmp == MAN_JMP) manstj = -1;
}
else if (manstj == -1)
{
++many;
--manjmp;
}

//controllo collisioni out of border
if (manx >= CONSOLE_WIDTH)
manx = CONSOLE_WIDTH - 1 ;
else if (manx < 0)
manx = 0;
if (many < 0)
many = 0;
else if (many >= CONSOLE_HEIGHT)
manx = CONSOLE_WIDTH - 1 ;

//collisione con obj port
if (maplevel1[many][manx] == OBJ_PORT_CHAR)
endlevel = 1;

//collisione terreno durante salto
if (manstj == -1)
{
//se ho la terra sotto fermo la caduta
if (maplevel1[many + 1][manx] == WORLD_CHAR)
{
//se ho saltato troppo muoio
if (manjmp < -4)
{
--life;
manx = startlevelx;
many = startlevely;
}
manstj = 0;
manjmp = 0;
}
}
else if (manstj == 1)
{
//se ho la terra sopra la testa non posso superarla
if (maplevel1[many-1][manx] == WORLD_CHAR)
++many;
}

//controllo collisione terra sotto i piedi
if ( manstj == 0 && maplevel1[many+1][manx] != WORLD_CHAR)
manstj = -1;

//disegno omino
if ( oldx != manx || oldy != many )
{
gotoxy(oldx,oldy);
printfk("%7k ");
gotoxy(manx,many);
printfk("%k%c",MAN_COLOR,MAN_CHAR);
gotoxy(0,0);
}

oldx = manx;
oldy = many;

Sleep(50);
}

cls();
printfk("%7k");
if (life == 0)
printf("MORTO");
else
printf("COMPLIMENTI");
Sleep(1500);//bug GetAsincKeyState
return 0;
}



Secondo te è un buon metodo? Non c'è nemmeno bisogno di istallare cose aggiuntive...