#include "lab_2.h" /***************************************************************/ /*SKRIVER UT HIGHSCORE-LISTAN */ /***************************************************************/ void printhigh(spelare listarray[],int antal) { int i; clrscr(); cout <<"HIGHSCORES\n" <<"----------\n"; cout << setw(6) << "Plats:" << setw(NAMESIZE) << "Namn:" << setw(15) << "Gissningar:" << setw(18) << "Datum:" << endl; for (i=0 ; i listarray[j+1].score) && (listarray[j+1].score !=0)) swap (listarray[j], listarray[j+1]); else if (listarray[j].score == 0) swap (listarray[j], listarray[j+1]); } /***************************************************************/ /*LÄSER FRÅN FILEN */ /***************************************************************/ int las(spelare listarray[]) { int x=0; fstream load("highscr.dat",ios::in| ios::binary); if(!load) return 0; while ((load.peek() != EOF) && (x < NAMESIZE)) load.read((char *)&listarray[x++],sizeof(listarray[x])); load.close(); return x; } /***************************************************************/ /*SKRIVER TILL FILEN */ /***************************************************************/ void skriv(spelare listarray[]) { fstream save("highscr.dat",ios::out| ios::binary); if (!save) cout <<"Error!"; else for (int i=0 ; i<=NAMESIZE ; i++) save.write((char *)&listarray[i], sizeof(listarray[i])); save.close(); } /***************************************************************/ /*SPELAREN ÄR KLAR MED OMGÅNGEN, SKRIVER EV. IN SITT NAMN OSV. */ /***************************************************************/ void klar(int a) { int x; char spana; spelare p, listarray[NAMESIZE]; cout << "\n\nRätt svar efter " << a << " gissningar" << endl; cout << "Tryck på en tangent..." << endl; getch(); for (int i=0 ; i a) || (listarray[NAMESIZE-1].score==0)) { cout <<"Du platsar på highscore-listan!" <<"\nSkriv in ditt namn: "; cin >> p.namn; getdate(&p.datum); p.score=a; listarray[NAMESIZE-1] = p; bubbleSort(listarray,NAMESIZE); skriv(listarray); } printhigh(listarray,5); cout <<"\n Vill du se hela listan? (J/N): "; cin >> spana; if (spana == 'j') printhigh(listarray,NAMESIZE); }