|
| 1 | +#include<stdio.h> |
| 2 | +#include<conio.h> |
| 3 | +#include<dos.h> |
| 4 | +#include<stdlib.h> |
| 5 | +#include<time.h> |
| 6 | +main() |
| 7 | +{ |
| 8 | +int i,j,k,l,m,b[14000],n,s,f,d,aa,ab,ac,ad,ae,af,g,x,c[80][23]; |
| 9 | +char ch; |
| 10 | +textcolor(0); |
| 11 | +textbackground(7); |
| 12 | +clrscr(); |
| 13 | +i=5;j=5;m=1; |
| 14 | +for(i=4;i<76;i++) |
| 15 | +{for(j=3;j<23;j++) |
| 16 | +{c[i][j]=0;}} |
| 17 | +clrscr(); |
| 18 | +gotoxy(35,15); |
| 19 | +printf("welcome to snake mania"); |
| 20 | +getch(); |
| 21 | +clrscr(); |
| 22 | +gotoxy(35,14); |
| 23 | +printf("instruction"); |
| 24 | +gotoxy(35,15); |
| 25 | +printf("press w - up"); |
| 26 | +gotoxy(42,16); |
| 27 | +printf("s-down"); |
| 28 | +gotoxy(42,17); |
| 29 | +printf("a-left"); |
| 30 | +gotoxy(42,18); |
| 31 | +printf("d-right"); |
| 32 | +gotoxy(42,19);printf("q-qiut"); |
| 33 | +start: |
| 34 | +clrscr(); |
| 35 | +gotoxy(35,14); |
| 36 | +printf("choose number to select level"); |
| 37 | +gotoxy(38,16); |
| 38 | +printf("1)easy"); |
| 39 | +gotoxy(38,17); |
| 40 | +printf("2)medium"); |
| 41 | +gotoxy(38,18); |
| 42 | +printf("3)hard"); |
| 43 | +gotoxy(39,19); |
| 44 | +printf("4)professional"); |
| 45 | +ch=getch(); |
| 46 | +if(ch=='1') |
| 47 | +{s=400;} |
| 48 | +else if(ch=='2') |
| 49 | +{s=300;} |
| 50 | +else if(ch=='3') |
| 51 | +{s=100;} |
| 52 | +else if(ch=='4') |
| 53 | +{s=75;} |
| 54 | +else{goto start;} |
| 55 | +clrscr(); |
| 56 | +for(i=4;i<76;i++) |
| 57 | +{gotoxy(i,3);printf("-");gotoxy(i,23);printf("-");} |
| 58 | +for(j=3;j<=23;j++) |
| 59 | +{gotoxy(3,j);printf("|");gotoxy(76,j);printf("|");} |
| 60 | +gotoxy(5,1);printf("score=0 "); |
| 61 | +gotoxy(50,24);printf("devolped by earnest"); |
| 62 | +x=0; |
| 63 | +i=10;j=10;m=1; |
| 64 | +for(n=0;n<5;n++) |
| 65 | +{i=i+1;gotoxy(i,j);c[i][j]=1;b[m]=(i*100)+j;printf("*");m=m+1;} |
| 66 | +n=5; |
| 67 | +f=0; |
| 68 | +goto food1; |
| 69 | +game: |
| 70 | +left: |
| 71 | +f=1; |
| 72 | +while(!kbhit()) |
| 73 | +{i=i+1;if(i>75||j>22||j<4||i<4){goto gameover;} |
| 74 | +if(c[i][j]==1){goto gameover;} |
| 75 | +if(i==aa&&j==ab){goto increase;} |
| 76 | +gotoxy(i,j);c[i][j]=1;b[m]=(i*100)+j;printf("*");d=b[m-n];k=d/100;l=d%100; |
| 77 | +gotoxy(k,l);printf(" ");c[k][l]=0;delay(s);m=m+1;} |
| 78 | +ch=getch(); |
| 79 | +if(ch=='a') |
| 80 | +{goto left;} |
| 81 | +goto choice; |
| 82 | +right: |
| 83 | +f=2; |
| 84 | +while(!kbhit()) |
| 85 | +{i=i-1;if(i>75||j<4||i<4||j>22){goto gameover;} |
| 86 | +if (c[i][j]==1){goto gameover;} |
| 87 | +if(i==aa&&j==ab){goto increase;} |
| 88 | +gotoxy(i,j);c[i][j]=1;b[m]=(i*100)+j;printf("*");d=b[m-n];k=d/100;l=d%100; |
| 89 | +gotoxy(k,l);printf(" ");c[k][l]=0;delay(s);m=m+1;} |
| 90 | +ch=getch(); |
| 91 | +if(ch=='d') |
| 92 | +{goto right;} |
| 93 | +goto choice; |
| 94 | +up: |
| 95 | +f=3; |
| 96 | +while(!kbhit()) |
| 97 | +{j=j-1;if(i<4||i>75||j>22||j<4){goto gameover;} |
| 98 | +if(c[i][j]==1){goto gameover;} |
| 99 | +if(i==aa&&j==ab){goto increase;} |
| 100 | +gotoxy(i,j);c[i][j]=1;b[m]=(i*100)+j;printf("*");d=b[m-n];k=d/100;l=d%100; |
| 101 | +gotoxy(k,l);printf(" ");c[k][l]=0;delay(s);m=m+1;} |
| 102 | +ch=getch(); |
| 103 | +if(ch=='s'){goto up;} |
| 104 | +goto choice; |
| 105 | +down: |
| 106 | +f=4; |
| 107 | +while(!kbhit()) |
| 108 | +{j=j+1;if(i<4||i>75||j>22||j<4){goto gameover;} |
| 109 | +if(c[i][j]==1){goto gameover;} |
| 110 | +if(i==aa&&j==ab){goto increase;} |
| 111 | +gotoxy(i,j);c[i][j]=1;b[m]=(i*100)+j;printf("*");d=b[m-n];k=d/100;l=d%100; |
| 112 | +gotoxy(k,l);printf(" ");c[k][l]=0;delay(s);m=m+1;} |
| 113 | +ch=getch(); |
| 114 | +if(ch=='w'){goto down;} |
| 115 | +choice: |
| 116 | +if(ch=='w'){goto up;} |
| 117 | +else if(ch=='s'){goto down;} |
| 118 | +else if(ch=='a'){goto right;} |
| 119 | +else if(ch=='d'){goto left;} |
| 120 | +else if(ch=='q'){goto exit;} |
| 121 | +else {if(f==1){goto left;} |
| 122 | +else if(f==2){goto right;} |
| 123 | +else if(f==3){goto up;} |
| 124 | +else{goto down;}} |
| 125 | +food1: |
| 126 | +randomize(); |
| 127 | +aa=(rand()%100); |
| 128 | +if(aa<=3){goto food1;} |
| 129 | +if(aa>=76){goto food1;} |
| 130 | +randomize(); |
| 131 | +ab=(rand()%30); |
| 132 | +if(ab<=3){goto food1;} |
| 133 | +else if(ab>=23){goto food1;} |
| 134 | +gotoxy(aa,ab);printf("*"); |
| 135 | +if(f==0){goto game;} |
| 136 | +if(f==1){goto left;} |
| 137 | +if(f==2){goto right;} |
| 138 | +if(f==3){goto up;} |
| 139 | +else{goto down;} |
| 140 | +increase: |
| 141 | +if(f==1){b[m]=(i*100)+j;gotoxy(i,j);printf("*");m=m+1;n=n+1;gotoxy(5,1);x=x+1;printf("score=%d",x);goto food1;} |
| 142 | +if(f==2){b[m]=(i*100)+j;gotoxy(i,j);printf("*");m=m+1;n=n+1;x=x+1;gotoxy(5,1);printf("score=%d",x);goto food1;} |
| 143 | +if(f==3){b[m]=(i*100)+j;gotoxy(i,j);printf("*");m=m+1;n=n+1;x=x+1;gotoxy(5,1);printf("score=%d",x);goto food1;} |
| 144 | +else{b[m]=(i*100)+j;gotoxy(i,j);printf("*");m=m+1;n=n+1;x=x+1;gotoxy(5,1);printf("score=%d",x);goto food1;} |
| 145 | +gameover: |
| 146 | +clrscr(); |
| 147 | +gotoxy(35,10); |
| 148 | +printf("game over"); |
| 149 | +gotoxy(30,11); |
| 150 | +printf("your score=%d",x); |
| 151 | +gotoxy(30,12); |
| 152 | +printf("press key to continue"); |
| 153 | +getch(); |
| 154 | +goto exit; |
| 155 | +exit: |
| 156 | +clrscr(); |
| 157 | +gotoxy(32,11); |
| 158 | +printf("do you want to quit(y/n)"); |
| 159 | +ch=getch(); |
| 160 | +if(ch=='n') |
| 161 | +{goto start;} |
| 162 | +else if(ch=='y') |
| 163 | +{clrscr();gotoxy(35,11);printf("thanks for playing");getch();goto qiut;} |
| 164 | +else{goto exit;} |
| 165 | +qiut: |
| 166 | +getch(); |
| 167 | +return 0; |
| 168 | +} |
0 commit comments