Small cleanup

This commit is contained in:
Late Night Defender 2021-11-15 22:26:30 +07:00
parent b3108b71fd
commit 26d6b7940e

View file

@ -6,8 +6,6 @@
#include <stdlib.h>
#include <string.h>
#include <string>
#include <string.h>
#include <string>
using namespace std;
#define termMaxX 145
@ -22,10 +20,10 @@ using namespace std;
void drawVoid(){
printf("\033[1;32m\033[40m \033[0m"); //\033[1;32m green text,\033[40m black bg, display " ",\033[0m set default
printf("\033[1;32m\033[40m \033[0m");
}
void drawSnake(){
printf("\033[1;32m\033[40m*\033[0m"); //\033[1;32m green text,\033[40m black bg, display *,\033[0m set default
printf("\033[1;32m\033[40m*\033[0m");
}
void SetCursorPosition(int XPos, int YPos) {
printf("\033[%d;%dH",YPos+1,XPos+1);
@ -120,8 +118,6 @@ int crashBomb(int posX, int posY, int bombX[100],int bombY[100], bool bombShown[
}
void gameOver(int score){
//clear();
//initscr();
cbreak();
noecho();
scrollok(stdscr, TRUE);
@ -136,6 +132,7 @@ void gameOver(int score){
printf("\033[45m \033[0m"); //\033[41m
}
}
//Draws GAME OVER
SetCursorPosition((paMaxX/2)-34,(paMaxY/2)-7);
printf("\033[45m \033[41m \033[45m \033[41m \033[45m \033[41m \033[45m \033[41m \033[45m \033[41m \033[45m \033[41m \033[45m \033[41m \033[45m \033[41m \033[45m \033[41m \033[45m \033[41m \033[45m ");
SetCursorPosition((paMaxX/2)-34,(paMaxY/2)-6);
@ -151,7 +148,7 @@ void gameOver(int score){
SetCursorPosition((paMaxX/2)-34,(paMaxY/2)-1);
printf("\033[45m \033[41m \033[45m \033[41m \033[45m \033[41m \033[45m \033[41m \033[45m \033[41m \033[45m \033[41m \033[45m \033[41m \033[45m \033[41m \033[45m \033[41m \033[45m \033[41m \033[45m \033[41m \033[45m ");
printf("\e[?25h");
//For score values with multiple digits
int scoreShift=0,temp=score;
while(temp>=10){
@ -162,9 +159,7 @@ void gameOver(int score){
printf("Score: %d", score);
SetCursorPosition((paMaxX/2)-19,(paMaxY/2)+6);
printf("Enter you name: ");
SetCursorPosition((paMaxX/2)-1,(paMaxY/2)+6);
//cin>>score;
//Save player scores at $HOME/.config/cursedSnakeGameScores
FILE *cmd=popen("echo -n $HOME", "r");
char result[100]={0x0};
fgets(result, sizeof(result), cmd);
@ -179,7 +174,7 @@ void gameOver(int score){
return;
}
string playerName;
//Asks for player name
scanf("%s",playerName.c_str());
fprintf(fptr,"%s %d\n", playerName.c_str(), score);
fclose(fptr);
@ -188,7 +183,6 @@ void gameOver(int score){
int mainMenu() {
int currentButtonState=0,menuStarted=0;
printf("\e[?25l");//ปิดcursor
//initscr();
cbreak();
noecho();
scrollok(stdscr, TRUE);
@ -301,7 +295,7 @@ int mainMenu() {
void showScores() {
endwin();
int line=0,currentLine=0;
char c;
char c; //UserInputCharacter
FILE *cmd=popen("echo -n $HOME", "r");
char result[100]={0x0};
fgets(result, sizeof(result), cmd);
@ -375,9 +369,7 @@ void showScores() {
currentLine++;
}
}
fclose(fptr);
drawFrame();
SetCursorPosition(5,3);
printf("Name");
@ -390,18 +382,13 @@ void showScores() {
noecho();
scrollok(stdscr, TRUE);
nodelay(stdscr, TRUE);
//int j=0;
while(1){
usleep(10000);
c = getch();
if(showLinesIndicator==1){
if(c==upArrow){
for(int i=1;i<paMaxX-1;i++){
for(int j=4;j<paMaxY-1;j++){
SetCursorPosition(i,j);
printf("\033[0m ");
}
@ -410,9 +397,7 @@ void showScores() {
}
if(c==downArrow){
for(int i=1;i<paMaxX-1;i++){
for(int j=4;j<paMaxY-1;j++){
SetCursorPosition(i,j);
printf("\033[0m ");
}
@ -431,7 +416,6 @@ void showScores() {
}
if(showLinesIndicator==0){
for(int i=currentLine;i<line;i++){
SetCursorPosition(5,4+i);
printf("%s", playerName[i].c_str());
SetCursorPosition(50,4+i);
@ -456,17 +440,11 @@ int game(){
bool bombShown[100];
double thistimeMillisec;
srand(time(NULL));
/*for(int j=0;j<20;j++){
star[0][j]=rand()%4+2;//2-5
}*/
char input,lastInput;
//initscr();
cbreak();
noecho();
scrollok(stdscr, TRUE);
nodelay(stdscr, TRUE);
//sleep(1);//รอโปรแกรมเปิด
start_color();
init_pair(1,COLOR_WHITE, COLOR_BLACK);
wbkgd(stdscr, COLOR_PAIR(1));
@ -492,7 +470,6 @@ int game(){
break;
}
}
bombX[i]=rand()%98+1;
bombY[i]=rand()%28+1;
}
@ -504,9 +481,7 @@ int game(){
SetCursorPosition(posX[0],posY[0]);
if(ft<5){//สร้างงูรอบแรกสุด
for(int i=0;i<paMaxX;i++){
for(int j=0;j<paMaxY;j++){
SetCursorPosition(i,j);
printf("\033[0m ");
}
@ -597,11 +572,9 @@ int game(){
while(1){
if(fruitX!=bombX[k]){
if(fruitY!=bombY[k]){
break;
}
}
fruitX=rand()%96+2;
fruitY=rand()%26+2;
}
@ -614,40 +587,22 @@ int game(){
}
SetCursorPosition(fruitX,fruitY);
printf("0");
//SetCursorPosition(0,29);for(int i=0;i<10;i++){printf("%d:%d %d |",i+1,bombX[i],bombY[i]);}
//SetCursorPosition(0,29);for(int a=0;bombShown[a]==1;a++){printf("%d ",bombShown[a]);}
//SetCursorPosition(0,29);for(int a=0;a<100;a++){printf("%d ",bombShown[a]);}
if(snakeLength-2>=bombAmount){
bombLoop++;
bombShown[bombLoop-2]=1;
bombAmount=bombLoop*3;
}
for(int i=0;i<100;i++){
if(bombShown[i]==1){
SetCursorPosition(bombX[i],bombY[i]);
printf("\033[1;97m\033[41m \033[0m");
}
}
//
}
return snakeLength-2;
}
/*int mainmenu(){
for(int i=0;i<paMaxY;i++){
for(int j=0;j<paMaxX;j++){
SetCursorPosition(j,i);
printf("\033[100m \033[0m");
}
}
}*/
int main () {
int mainMenuSelected,score;
initscr();
@ -656,7 +611,6 @@ int main () {
if(mainMenuSelected==0){
score=game();
gameOver(score);
getchar();
}
if(mainMenuSelected==1){