Update roofus.c
parent
5f2820b6e2
commit
a1ac74174f
13
roofus.c
13
roofus.c
|
@ -1,4 +1,4 @@
|
||||||
#define VERSION "0.01"
|
#define VERSION "0.02"
|
||||||
|
|
||||||
#define N 5
|
#define N 5
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -26,6 +26,7 @@ int main () {
|
||||||
start ();
|
start ();
|
||||||
printm ();
|
printm ();
|
||||||
while (end == 0) {
|
while (end == 0) {
|
||||||
|
printf ("\nLeft: a. Up: w. Right: d. Down: s. Exit: 0");
|
||||||
printf ("\nDirection? ");
|
printf ("\nDirection? ");
|
||||||
scanf ("%s", dir);
|
scanf ("%s", dir);
|
||||||
getchar ();
|
getchar ();
|
||||||
|
@ -65,6 +66,7 @@ void move(char * dir){
|
||||||
xinit = my_x;
|
xinit = my_x;
|
||||||
yinit = my_y;
|
yinit = my_y;
|
||||||
|
|
||||||
|
// move pointer
|
||||||
switch (dir[0]) {
|
switch (dir[0]) {
|
||||||
case 'a':
|
case 'a':
|
||||||
if (my_x != 0) {
|
if (my_x != 0) {
|
||||||
|
@ -102,7 +104,7 @@ void move(char * dir){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (stop == 0) {
|
if (stop == 0) {
|
||||||
|
// change values
|
||||||
if (*dir == 'd') {
|
if (*dir == 'd') {
|
||||||
for (j = 1 + xinit; j <= 4; j++) {
|
for (j = 1 + xinit; j <= 4; j++) {
|
||||||
if (matrix[yinit][j] != 0) {
|
if (matrix[yinit][j] != 0) {
|
||||||
|
@ -144,16 +146,18 @@ void move(char * dir){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if 1 or 2 -> random number
|
||||||
void nolow () {
|
void nolow () {
|
||||||
int i, j;
|
int i, j;
|
||||||
for (i = 0; i < N; i++) {
|
for (i = 0; i < N; i++) {
|
||||||
for (j = 0; j < N; j++) {
|
for (j = 0; j < N; j++) {
|
||||||
if ( matrix[i][j] < 3 && matrix[i][j] > 0)
|
if ( matrix[i][j] < 3 && matrix[i][j] > 0)
|
||||||
matrix[i][j] = (rand()%10)-10;
|
matrix[i][j] = rand () % 10 - 10;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// print matrix
|
||||||
void printm () {
|
void printm () {
|
||||||
int i, j;
|
int i, j;
|
||||||
printf ("\n\n");
|
printf ("\n\n");
|
||||||
|
@ -170,7 +174,7 @@ void printm(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int win(){
|
int win () { // 20+ zeros
|
||||||
int i, j, count=0;
|
int i, j, count=0;
|
||||||
for (i = 0; i < N; i++) {
|
for (i = 0; i < N; i++) {
|
||||||
for (j = 0; j < N; j++) {
|
for (j = 0; j < N; j++) {
|
||||||
|
@ -182,6 +186,7 @@ int win(){
|
||||||
printf ("\nYou win! Moves: %d", moves);
|
printf ("\nYou win! Moves: %d", moves);
|
||||||
return 1;
|
return 1;
|
||||||
}else{
|
}else{
|
||||||
|
printf ("\nYou still need to delete %d numbers", N * (N-1) - count);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue