From a1ac74174f2c3032f59e02f8c9d99723bba350a4 Mon Sep 17 00:00:00 2001 From: Racoonicorn Date: Mon, 19 Dec 2016 14:02:06 +0100 Subject: [PATCH] Update roofus.c --- roofus.c | 197 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 101 insertions(+), 96 deletions(-) diff --git a/roofus.c b/roofus.c index 7dfa4a1..3743d1e 100644 --- a/roofus.c +++ b/roofus.c @@ -1,192 +1,197 @@ -#define VERSION "0.01" +#define VERSION "0.02" #define N 5 #include #include #include -void start(); -void printm(); -void move(char * dir); -void nolow(); -int win(); -int error(); +void start (); +void printm (); +void move (char *dir); +void nolow (); +int win (); +int error (); int matrix[N][N]; -int my_x=N/2; -int my_y=N/2; +int my_x = N / 2; +int my_y = N / 2; int moves = 0; int main () { char dir[20]; char exit; - int end=0; + int end = 0; srand (time(NULL)); - start(); - printm(); - while(end==0){ - printf("\nDirection? "); - scanf("%s", dir); - getchar(); - if(dir[0]=='0'){ - printf("\nExit? [y/n] "); - scanf("%c", &exit); - if(exit=='y'){ - printf("\n\n\n\nv%s", VERSION); + start (); + printm (); + while (end == 0) { + printf ("\nLeft: a. Up: w. Right: d. Down: s. Exit: 0"); + printf ("\nDirection? "); + scanf ("%s", dir); + getchar (); + if (dir[0] == '0') { + printf ("\nExit? [y/n] "); + scanf ("%c", &exit); + if (exit == 'y') { + printf ("\n\n\n\nv%s", VERSION); return moves; - }else{ - dir[0]='1'; - getchar(); + } else { + dir[0] = '1'; + getchar (); } } - move(dir); - printm(); - end = win(); + move (dir); + printm (); + end = win (); } return 0; } -void start(){ +void start () { int i, j; - for (i=0; i0){ + if (my_y > 0) { my_y--; - }else{ - stop=error(); + } else { + stop = error (); } break; case 's': - if(my_y < N-1){ + if(my_y < N-1) { my_y++; - }else{ - stop=error(); + } else { + stop = error (); } break; case 'o': - stop=1; + stop = 1; break; default: - stop=error(); + stop = error (); break; } - if(stop==0){ - - if(*dir == 'd'){ - for (j=1+xinit;j<=4; j++){ - if(matrix[yinit][j]!=0){ - matrix[yinit][j]= matrix[yinit][j] - matrix[yinit][xinit]; - if(matrix[yinit][j]<0 && matrix[yinit][xinit]!=0) + if (stop == 0) { + // change values + if (*dir == 'd') { + for (j = 1 + xinit; j <= 4; j++) { + if (matrix[yinit][j] != 0) { + matrix[yinit][j] = matrix[yinit][j] - matrix[yinit][xinit]; + if (matrix[yinit][j] < 0 && matrix[yinit][xinit] != 0) matrix[yinit][j] = -matrix[yinit][j]; } } } - if(*dir == 'a'){ - for (j=0;j=0; i--){ - if(matrix[i][my_x]!=0){ - matrix[i][my_x]= matrix[i][my_x] - matrix[yinit][xinit]; - if(matrix[i][my_x]<0 && matrix[yinit][xinit]!=0) + if (*dir == 'w'){ + for (i = my_y;i >= 0; i--) { + if (matrix[i][my_x] != 0) { + matrix[i][my_x] = matrix[i][my_x] - matrix[yinit][xinit]; + if (matrix[i][my_x] < 0 && matrix[yinit][xinit] != 0) matrix[i][my_x] = -matrix[i][my_x]; } } } - if(*dir == 's'){ - for (i=my_y;i random number +void nolow () { int i, j; - for(i=0;i< N;i++){ - for(j=0;j< N;j++){ - if(matrix[i][j]<3 && matrix[i][j]>0) - matrix[i][j] = (rand()%10)-10; + for (i = 0; i < N; i++) { + for (j = 0; j < N; j++) { + if ( matrix[i][j] < 3 && matrix[i][j] > 0) + matrix[i][j] = rand () % 10 - 10; } } } -void printm(){ +// print matrix +void printm () { int i, j; - printf("\n\n"); - for (i=0; i "); - if(matrix[i][j]!=0) - printf("%d\t", matrix[i][j]); + if (matrix[i][j] != 0) + printf ("%d\t", matrix[i][j]); else - printf(" \t"); + printf (" \t"); } - printf("\n\n"); + printf ("\n\n"); } } -int win(){ +int win () { // 20+ zeros int i, j, count=0; - for (i=0; i= N*(N-1)){ - printf("\nYou win! Moves: %d", moves); + if (count >= N * (N-1)) { + printf ("\nYou win! Moves: %d", moves); return 1; }else{ + printf ("\nYou still need to delete %d numbers", N * (N-1) - count); return 0; } } -int error(){ - printf("ERROR!!!"); +int error () { + printf ("ERROR!!!"); return 1; }