Added contextual instructions and reworked leaderboards
This commit is contained in:
parent
db832eb540
commit
5ccd9479dc
1 changed files with 32 additions and 14 deletions
46
main.cpp
46
main.cpp
|
@ -157,6 +157,8 @@ void gameOver(int score){
|
|||
}
|
||||
SetCursorPosition(((paMaxX/2)-5)-(scoreShift/2),(paMaxY/2)+3);
|
||||
printf("Score: %d", score);
|
||||
SetCursorPosition(2,paMaxY-2);
|
||||
printf("Input your name (without spaces!) and press ENTER to return to main menu.");
|
||||
SetCursorPosition((paMaxX/2)-19,(paMaxY/2)+6);
|
||||
printf("Enter you name: ");
|
||||
//Save player scores at $HOME/.config/cursedSnakeGameScores
|
||||
|
@ -176,7 +178,7 @@ void gameOver(int score){
|
|||
string playerName;
|
||||
//Asks for player name
|
||||
scanf("%s",playerName.c_str());
|
||||
fprintf(fptr,"%s %d\n", playerName.c_str(), score);
|
||||
fprintf(fptr,"%d %s\n",score , playerName.c_str());
|
||||
fclose(fptr);
|
||||
}
|
||||
|
||||
|
@ -208,6 +210,16 @@ int mainMenu() {
|
|||
printf("\033[45m \033[107m#####\033[45m \033[107m#####\033[45m \033[107m#\033[45m \033[107m#\033[45m \033[107m#####\033[45m \033[107m#######\033[45m \033[107m######\033[45m \033[107m#####\033[45m \033[107m#\033[45m \033[107m#\033[45m \033[107m#\033[45m \033[107m#\033[45m \033[107m#\033[45m \033[107m#\033[45m \033[107m########");
|
||||
SetCursorPosition((paMaxX/2)-44,(paMaxY/2)-5);
|
||||
printf("\033[45m GAME\033[0m");
|
||||
//Author info
|
||||
SetCursorPosition(paMaxX-8,paMaxY-3);
|
||||
printf("\033[45mMade by\033[0m");
|
||||
SetCursorPosition(paMaxX-39,paMaxY-2);
|
||||
printf("\033[45mPongpeera Wongprasitthiporn (64010543)\033[0m");
|
||||
//Instructions
|
||||
SetCursorPosition(2,paMaxY-3);
|
||||
printf("\033[45mUse ARROW KEYS to navigate\033[0m");
|
||||
SetCursorPosition(2,paMaxY-2);
|
||||
printf("\033[45mENTER to select\033[0m");
|
||||
if(menuStarted<=3){
|
||||
for(int i=0;i<paMaxX;i++){
|
||||
|
||||
|
@ -294,6 +306,7 @@ int mainMenu() {
|
|||
|
||||
void showScores() {
|
||||
endwin();
|
||||
system("sort $HOME/.config/cursedSnakeGameScores -nr > $HOME/.config/cursedSnakeGameScores.tmp && mv $HOME/.config/cursedSnakeGameScores.tmp $HOME/.config/cursedSnakeGameScores");
|
||||
int line=0,currentLine=0;
|
||||
char c; //UserInputCharacter
|
||||
FILE *cmd=popen("echo -n $HOME", "r");
|
||||
|
@ -346,7 +359,6 @@ void showScores() {
|
|||
playerName[i]="";
|
||||
scores[i]="";
|
||||
}
|
||||
//*fptr = *fopen(fullpath.c_str(),"r");
|
||||
if(fptr == NULL) {
|
||||
perror("Error in opening file");
|
||||
return;
|
||||
|
@ -354,13 +366,10 @@ void showScores() {
|
|||
bool scoreName=0;
|
||||
while(currentLine!=line){
|
||||
c=fgetc(fptr);
|
||||
|
||||
if(scoreName==0){
|
||||
|
||||
if(scoreName==1){
|
||||
playerName[currentLine]+=c;
|
||||
}
|
||||
if(scoreName==1){
|
||||
|
||||
if(scoreName==0){
|
||||
scores[currentLine]+=c;
|
||||
}
|
||||
if(c==' ') scoreName=1;
|
||||
|
@ -371,10 +380,12 @@ void showScores() {
|
|||
}
|
||||
fclose(fptr);
|
||||
drawFrame();
|
||||
SetCursorPosition(5,3);
|
||||
printf("Name");
|
||||
SetCursorPosition(50,3);
|
||||
printf("Name");
|
||||
SetCursorPosition(15,3);
|
||||
printf("Score");
|
||||
SetCursorPosition(5,3);
|
||||
printf("Rank");
|
||||
currentLine=0;
|
||||
bool showLinesIndicator=1;
|
||||
if(line<=20) showLinesIndicator=0;
|
||||
|
@ -405,25 +416,30 @@ void showScores() {
|
|||
if(currentLine+20!=line) currentLine++;
|
||||
}
|
||||
for(int i=currentLine;i<20+currentLine;i++){
|
||||
|
||||
SetCursorPosition(5,4+i-currentLine);
|
||||
printf("%s", playerName[i].c_str());
|
||||
SetCursorPosition(50,4+i-currentLine);
|
||||
printf("%s", playerName[i].c_str());
|
||||
SetCursorPosition(15,4+i-currentLine);
|
||||
printf("%s", scores[i].c_str());
|
||||
SetCursorPosition(5,4+i-currentLine);
|
||||
printf("%d", i+1);
|
||||
}
|
||||
SetCursorPosition(1,paMaxY-2);
|
||||
printf("lines %d-%d",currentLine+1,currentLine+21);
|
||||
}
|
||||
if(showLinesIndicator==0){
|
||||
for(int i=currentLine;i<line;i++){
|
||||
SetCursorPosition(5,4+i);
|
||||
printf("%s", playerName[i].c_str());
|
||||
SetCursorPosition(50,4+i);
|
||||
printf("%s", playerName[i].c_str());
|
||||
SetCursorPosition(15,4+i);
|
||||
printf("%s", scores[i].c_str());
|
||||
SetCursorPosition(5,4+i-currentLine);
|
||||
printf("%d", i+1);
|
||||
}
|
||||
}
|
||||
SetCursorPosition(64,paMaxY-2);
|
||||
printf("Press Enter to return to main menu.");
|
||||
SetCursorPosition(paMaxX-28,paMaxY-3);
|
||||
printf("Use ARROW KEYS to navigate.");
|
||||
if(c=='\n'){
|
||||
break;
|
||||
}
|
||||
|
@ -493,6 +509,8 @@ int game(){
|
|||
}
|
||||
SetCursorPosition(0,0);
|
||||
printf("\033[1;97\033[45mScore: %d\033[0m", snakeLength-2);
|
||||
SetCursorPosition(0,paMaxY-1);
|
||||
printf("\033[45mUse WASD or ARROW KEYS to move snake, hold to dash, B to stop snake, X to exit immediately.\033[0m");
|
||||
input=getch();//รับจากแป้นพิมพ์
|
||||
if(input=='x'){
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue