Hello, I'm doing the snake game, but I'm doing with an array, the way I'm doing is giving prints and system ("cls") quickly, but I'd like to know more efficient ways, like for example the gotoxy Code to give print to screen:
int i, j;
cout<<setw(MaxL/2 +5)<<"SNAKE GAME"<<endl;
for(i=0; i<MaxC; i++)
{
for(j=0; j<MaxL; j++)
{
if(j==MaxL-1)
cout<< ScreenPrint[i][j]<<endl;
else
cout<<ScreenPrint[i][j];
}
}
In this way I can easily know the coordinates where each thing is and know when I reach the limit: Code that updates the values of the snake, according to the keys W, A, S, D: Gety Returns the y value of the snake, Getx returns the x value of the snake SetY () updates coordinates, -1 to do y - and 1 to do y ++
switch(toupper(c)) {
case 'W':
ScreenPrint[GetY()][GetX()]=' ';
setY(-1);
ScreenPrint[GetY()][GetX()]=254;
break;
case 'A':
ScreenPrint[GetY()][GetX()]=' ';
setX(-1);
ScreenPrint[GetY()][GetX()]=254;
break;
case 'S':
ScreenPrint[GetY()][GetX()]=' ';
setY(1);
ScreenPrint[GetY()][GetX()]=254;
break;
case 'D':
ScreenPrint[GetY()][GetX()]=' ';
setX(1);
ScreenPrint[GetY()][GetX()]=254;
break;
default:
break;
}
/* SCREEN LIMIT */
if(GetX()<=0 || GetY()<=0 || GetX()>=MaxL-1 || GetY()>=MaxC-1)
return -1;
else
return 1;
To conclude, I would like to know about possible libraries to add, different ways to do it, new ideas, I still do not know how to use libraries beyond standards, I would like help. Thanks