#include <stdio.h> #include <stdlib.h> #include <conio.h> #include <windows.h> #include < time.h> #include <math.h> #define SQR (x) x*xint I,j,x,y,d,k,f,stx,sty,score,e,l,w,h;char s[21][21];int a[21][ 21];int hard[13]={1,2,5,10,15,20,30,45,60,80,100};void Find () {for (Int. q=1;q<=20;q++) for (int r=1;r<=20;r++) if (a[q][r]==e) {s[q][r]= '; return;}} int yd () {if (w== ' h ' &&k== ' P ') return 0;if (w== ' P ' &&k== ' H ') return 0;if (w== ' M ' &&k== ' k ') return 0; if (w== ' k ' &&k== ' M ') return 0;if (w== ' K ') return 1;if (w== ' P ') return 1;if (w== ' H ') return 1;if (w== ' M ') return 1; return 0;} int main () {for (i=1;i<=20;i++) for (j=1;j<=20;j++) s[i][j]= "; S[9][10]=1;s[10][10]=1;s[11][10]=1;for (I=9;I&L t;=11;i++) {a[i][10]=i-8;} Stx=11;sty=10;e=1;srand (Time (0)); Z:;x=rand ()%20+1;y=rand ()%20+1;while (s[x][y]!= ") {X=rand ()%20+1;y=rand ()%20+1 ;} s[x][y]= ' * '; L=3;for (i=1;i<=20;i++) {s[i][1]=2;s[1][i]=2;s[20][i]=2;s[i][20]=2;} w= ' P '; H=12;while (!d) {System ("CLS"), for (; Kbhit ();) w=getch (); if (W!=0&&yd ()) k=w;if (k== ' H ') stx--;if (k== ' M ') sty++;if (k== ' P ') Stx++;if (k== ' K ') sty--;if (s[stx][sty]== ' * ') {score++;while (s[x][y]!= ") {X=rand ()%20+1;y=rand ()%20+1;} s[x][y]= ' * '; l++;s[stx][sty]=1;a[stx][sty]=l;} else if (s[stx][sty]!= ') {for (i=1;i<=20;i++) {for (j=1;j<=20;j++) Putchar (S[i][j]); Puts ("");} printf ("Game over!\nscore:%d\nhard:%d", score,13-h); Getch (); Getch (); return 0;;} Else{l++;s[stx][sty]=1;a[stx][sty]=l;find (); e++;} for (i=1;i<=20;i++) {for (j=1;j<=20;j++) printf ("%c", S[i][j]); Puts ("");} printf ("score:%d", Score,13-h);p rintf ("\nhard:%d", 13-h), if (score>=hard[13-h]) h--; Sleep (H*SQR (int) sqrt (h));} return 0;}
C + + mini game snake