Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
- #include "resource/nyamain.h"
- //#include "resource/nyaeater.c"
- void title(void);
- void addrank(void); //rank Input & Rank Test
- void howto(void);
- int stage(void);
- int game(int stage, int setnum, int *total_score, int *total_time);
- void setfood(int base_num, char (*block)[base_num], int setnum, int stage);
- void playboard(int base_num, char (*block)[base_num], int cnt, int score, int stage, int time);
- void clear(int base_num, char (*block)[base_num]);
- int end(int ckend, int eatscr,int bonus, int playscr, int score, int stage);
- void prorank(char player[10], int total_score, int total_time);
- void sortrank(int *n1, int *n2);
- void viewrank(void);
- int gameover(int ckend, int total_score,int total_time);
- int main(void)
- {
- srand(time(NULL));
- title();
- system("clear");
- printf("GAME SYSTEM END!\n");
- return 0;
- }
- void title(void)
- {
- int i,select;
- while(1)
- {
- __fpurge(stdin);
- system("clear");
- printf("======================\n");
- printf("======================\n");
- for(i=0;i<5;i++)printf("||| |||\n");
- printf("||| =K!MOZZI!= |||\n");
- printf("||| =EAT THE FOOD= |||\n");
- printf("|Press a Key To Start|\n");
- printf("||| R=Rank|E=End |||\n");
- printf("||| M=HowToPLAY? |||\n");
- for(i=0;i<5;i++)printf("||| |||\n");
- printf("||| (C)T.H.Kim |||\n");
- printf("======================\n");
- printf("======================\n");
- sleep(2);
- select=getch();
- if(select==109) howto();
- else if(select==114) viewrank();
- else if(select==112) addrank();
- else if(select==100)
- {
- int temp;
- FILE *rank;
- rank = fopen("resource/rank.sav","w");
- fclose(rank);
- printf("\n\nOK! RANK CLEAR!\nPress Any Key\n");
- temp = getch();
- }
- else if(select==101) break;
- else stage();
- }
- }
- void addrank(void)
- {
- system("clear");
- char player[5];
- int score , time;
- printf("enter name/score/time\n>");
- scanf("%s%d%d", player , &score, &time);
- getchar();
- prorank(player,score,time);
- return;
- }
- void howto(void)
- {
- system("clear");
- int i;
- printf("======HowToPLAY?======\n");
- printf("======================\n");
- for(i=0;i<6;i++)printf("||| |||\n");
- printf("||| D-KEY[<]MOVE |||\n");
- printf("||| EAT[F].CLEAR |||\n");
- printf("|||IF U PL 100sOVER|||\n");
- printf("||| UR GAMEOVER! |||\n");
- for(i=0;i<4;i++)printf("||| |||\n");
- printf("|||================|||\n");
- printf("||| PRESS ANY KEY. |||\n");
- printf("======================\n");
- printf("======================\n");
- int temp = getch();
- }
- int stage(void)
- {
- int err, total_score=0, total_time=0;
- time_t start = time(NULL);
- err = game(1,2,&total_score,&total_time);
- if(err!=1)err = game(2,5,&total_score,&total_time);
- if(err!=1)err = game(3,8,&total_score,&total_time);
- if(err!=1)err = game(4,11,&total_score,&total_time);
- if(err!=1)err = game(5,13,&total_score,&total_time);
- time_t gamecls = time(NULL);
- gameover(err,total_score,gamecls-start);
- }
- int game(int stage, int setnum, int *total_score, int *total_time)
- {
- __fpurge(stdin);
- int base_num=16;
- char block[base_num][base_num];
- int cnt=0, x=0,y=0;
- int score=0, bonus=0, playscr;
- time_t start = time(NULL);
- clear(base_num,block);
- setfood(base_num,block,setnum,stage);
- while(2)
- {
- system("clear");
- int now = time(NULL);
- int time = now - start;
- if(time>100) return 1;
- if(block[x][y]=='F')
- {
- cnt++;
- int randnum = (rand()%10);
- bonus+=randnum;
- score+=100+randnum;
- }
- if(cnt==setnum)
- {
- score+=(100-time);
- *total_score+=score;
- *total_time+=time;
- end(0,setnum*100,bonus,100-time,score,stage);
- }
- block[x][y] = '<';
- if(cnt==setnum)break;
- playboard(base_num,block,cnt,score,stage,time);
- //int value = linux_kbhit();
- //while(linux_kbhit()!=-1)
- while(3)
- {
- int plust;
- plust = getch();
- if(plust==27)
- {
- plust = getch();
- if(plust==91)
- {
- plust = getch();
- block[x][y] = ' ';
- switch(plust)
- {
- case 65: if(x>0){x--;} break;
- case 66: if(x<base_num-1){x++;} break;
- case 67: if(y<base_num-1){y++;} break;
- case 68: if(y>0){y--;} break;
- default: break;
- }
- }
- //else title();
- }
- break;
- }
- }
- return 0;
- }
- void setfood(int base_num, char (*block)[base_num], int setnum, int stage)
- {
- int foodnum = base_num-1;
- int x, y, cnt=0;
- int rx , ry , r_cnt=0;
- while(1)
- {
- x = (rand()%foodnum);
- y = (rand()%foodnum);
- //printf("%d|%d\n",x,y);
- if(cnt==setnum) break;
- else if(block[x][y]!='F')
- {
- block[x][y]='F';
- cnt++;
- }
- }
- }
- void playboard(int base_num, char (*block)[base_num], int cnt, int score, int stage, int time)
- {
- int x=0,y=0;
- //printf("==NYA!MOZZI VER.01A==\n");
- printf("========STAGE%d========\n",stage);
- printf("======================\n");
- while(x<base_num)
- {
- printf("|||");
- while(y<base_num)
- {
- printf("%c",block[x][y]);
- y++;
- }
- printf("|||\n");
- y=0;
- x++;
- }
- printf("======================\n");
- printf("==EAT:%02d|SCORE:%05d==\n",cnt,score);
- }
- void clear(int base_num, char (*block)[base_num])
- {
- int x=0,y=0;
- while(x<base_num)
- {
- while(y<base_num)
- {
- block[x][y] = ' ';
- y++;
- }
- y=0;
- x++;
- }
- }
- int end(int ckend, int eatscr,int bonus, int playscr, int score, int stage)
- {
- int i;
- printf("========STAGE%d========\n",stage);
- printf("======================\n");
- for(i=0;i<6;i++)printf("||| |||\n");
- printf("||| EATSCORE:%05d |||\n",eatscr);
- printf("||| BONUSSCR:%05d |||\n",bonus);
- printf("||| PLYTMSCR:%05d |||\n",playscr);
- printf("||| ALLSCORE:%05d |||\n",score);
- for(i=0;i<4;i++)printf("||| |||\n");
- printf("|||================|||\n");
- printf("||| PRESS ANY KEY. |||\n");
- printf("======================\n");
- printf("======================\n");
- sleep(2);
- int temp = getch();
- //printf("EATSCORE:%05d\n",eatscr);
- //printf("BONUSSCR:%05d\n",bonus);
- //printf("PLYTMSCR:%05d\n",playscr);
- //printf("ALLSCORE:%05d\n",score);
- //printf("PRESS ANY KEY\n");
- }
- void prorank(char player[10], int total_score, int total_time)
- {
- FILE *rank;
- char name[15][10];
- int score[15];
- int time[15];
- int res, cnt=0, w_cnt=0, err, i, j;
- rank = fopen("resource/rank.sav", "r");
- if(rank==NULL)
- {
- rank = fopen("resource/rank.sav","w");
- fclose(rank);
- rank = fopen("resource/rank.sav", "r");
- if(rank==NULL)
- {
- printf("SORRY! RANK ERROR\n");
- sleep(5);
- return;
- }
- }
- strcpy(name[cnt],player);
- score[cnt] = total_score;
- time[cnt] = total_time;
- cnt++;
- while(1)
- {
- res = fscanf(rank,"%s%d%d", name[cnt],&score[cnt],&time[cnt]);
- if(res==EOF){fclose(rank);break;}
- cnt++;
- }
- if(cnt>1)
- {
- for(i=0;i<cnt;i++)
- {
- for(j=i+1;j<cnt;j++)
- {
- if(score[i]<=score[j])
- {
- char temp[10];
- strcpy(temp,name[i]);
- strcpy(name[i],name[j]);
- strcpy(name[j],temp);
- sortrank(&score[i],&score[j]);
- sortrank(&time[i],&time[j]);
- }
- }
- }
- }
- rank = fopen("resource/rank.sav", "w");
- while(1)
- {
- fprintf(rank,"%s %d %d\n", name[w_cnt],score[w_cnt],time[w_cnt]);
- w_cnt++;
- if(cnt==1){fclose(rank);break;}
- else if(w_cnt==cnt){fclose(rank);break;}
- else continue;
- }
- viewrank();
- }
- void sortrank(int *n1, int *n2)
- {
- int temp;
- temp = *n1;
- *n1 = *n2;
- *n2 = temp;
- }
- void viewrank(void)
- {
- __fpurge(stdin);
- system("clear");
- FILE *rank;
- char name[10][10];
- int score[10]={0}, time[10]={0};
- int res, err, i, cnt=0;
- for(i=0;i<10;i++) strcpy(name[i],"MOZZI");
- rank = fopen("resource/rank.sav", "r");
- if(rank==NULL) err=1;
- while(err!=1)
- {
- res = fscanf(rank,"%s%d%d", name[cnt],&score[cnt],&time[cnt]);
- if(res==EOF){fclose(rank);break;}
- cnt++;
- }
- printf("=========RANK=========\n");
- printf("======================\n");
- if(err==1)
- {
- for(i=0;i<7;i++)printf("||| |||\n");
- printf("||| SORRY.NORANK |||\n");
- printf("||| UR.1ST.PLANER! |||\n");
- for(i=0;i<5;i++)printf("||| |||\n");
- printf("|||================|||\n");
- }
- else
- {
- printf("|NO|PNAME|SCORE|TI:ME|\n");
- printf("|====================|\n");
- for(i=0;i<10;i++)printf("|%02d|%5s|%05d|%02d:%02d|\n",i+1,name[i],score[i],time[i]/60,time[i]%60);
- for(i=0;i<4;i++)printf("|||================|||\n");
- }
- printf("||| PRESS ANY KEY. |||\n");
- printf("======================\n");
- printf("======================\n");
- sleep(3);
- int temp = getch();
- }
- int gameover(int ckend, int total_score, int total_time)
- {
- __fpurge(stdin);
- char player[10];
- system("clear");
- int i;
- printf("=======GAMEOVER=======\n");
- printf("======================\n");
- for(i=0;i<7;i++)printf("||| |||\n");
- if(ckend!=1)
- {
- printf("||| GAMECLR! |||\n");
- printf("|||SEE U NEXT TIME!|||\n");
- }
- else
- {
- printf("||| GAMEOVER |||\n");
- printf("|||U NEED SPEED UP!|||\n");
- for(i=0;i<4;i++)printf("||| |||\n");
- printf("|||TOTALSCORE|%05d|||\n",total_score);
- printf("||| PLAYTIME |%02d:%02d|||\n",total_time/60,total_time%60);
- printf("||| PRESS ANY KEY. |||\n");
- printf("======================\n");
- printf("======================\n");
- sleep(5);
- int temp = getch();
- return 0;
- }
- for(i=0;i<5;i++)printf("||| |||\n");
- printf("|||TOTALSCORE|%05d|||\n",total_score);
- printf("||| PLAYTIME |%02d:%02d|||\n",total_time/60,total_time%60);
- printf("======================\n");
- printf("===ENTER YOUR NICK!===\n");
- printf("(MAX 5)>");
- scanf("%s",player);
- sleep(3);
- prorank(player,total_score,total_time);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement