Hi, I'm new to this c ++ and I was doing a simple snake game I already have almost everything complete the only problem esque I want to do when I lose save the scores and names the file is already created but when the game starts the save function starts and does not let play
this is the functions and the main to not put as much code:
bool record(){
string playerName;
char option;
string display;
std::ofstream myfile("snake.txt", std::ofstream::out | std::ofstream::app);
system("cls");
cout<<"Ingrese su nombre: "<<endl;
cin>>playerName;
myfile<<playerName<<" "<<puntos<<endl;
myfile.close();
do{
cout<<"Quieres ver los records pasados? (y/n)"<<endl;
cin>>option;
switch(option){
case 'y':
ifstream myfile ("snake.txt");
if (myfile.is_open()){
system("cls");
while ( getline (myfile,display) ){
cout << display << '\n';
}
system("pause");
myfile.close();
}
break;
}
}while(option != 'n');
}
bool game_over()
{
if(y == 3 || y == 23 || x == 2 || x == 77)
return false;
for(int j = tam - 1; j > 0; j--){
if(cuerpo[j][0] == x && cuerpo[j][1] == y){
return false;
}
}
if(y != 3 || y != 23 || x != 2 || x != 77){
record();
}
return true;
}
Main:
int main()
{
OcultaCursor();
pintar();
gotoxy(xc, yc); printf("%c", 4);
while(tecla != ESC && game_over())
{
borrar_cuerpo();
guardar_posicion();
dibujar_cuerpo();
comida();
teclear();
teclear();
if(dir == 1) y--;
if(dir == 2) y++;
if(dir == 3) x++;
if(dir == 4) x--;
Sleep(velocidad);
}
cout<<puntos<<endl;
if(game_over()){
record();
}
pintar();
return 0;
}
I hope you can help me. Thanks