int main(int argc, char *argv[]){ if(argc != 2) usage(argv[0]); int level = atoi(argv[1]); if(level <= 0) usage(argv[0]); game g = init_game(level); char buf[3][100]; int piece_num; dir d; int distance; int back_code; while(!game_over_hr(g)){ bool good = false; while(!good){ //Loop for the break of cancel instruction while(!good){ system("clear"); print_game(g); printf("Move the pieces for free the piece 0 to the exit:\n"); printf("Write exit for quit the game or cancel for restart the current move.\n"); printf("Total move: %d\n",game_nb_moves(g)); //First loop to take the number piece that you want to move back_code = take_piece_num(g, buf[0], &(piece_num)); if(back_code == 0) break; if(back_code == -1) return EXIT_SUCCESS; //Second loop to take the direction where you want to move back_code = take_direction(g, piece_num, buf[1], &(d)); if(back_code == 0) break; if(back_code == -1) return EXIT_SUCCESS; //Third loop to take the number of case that need for the move back_code = take_number_case(g, piece_num, d, buf[2], &(distance)); if(back_code == 0) break; if(back_code == -1) return EXIT_SUCCESS; good = true; } } } system("clear"); print_game(g); printf("CONGRATULATION\nYou won in %d moves\n", game_nb_moves(g)); delete_game(g); return EXIT_SUCCESS; }
int my_gohome(char **env) { int pos; int i; i = 0; pos = my_needposchar("HOME=", '='); while (env[i] != NULL) { if (my_nmatch("HOME=", env[i], pos)) { if (take_direction(env[i]) == -1) return (-1); return (0); } i++; } my_printf("ERROR : 'HOME' doesn't exist.\n"); return (-1); }
int my_cd_tiret(char **env) { int pos; int i; i = 0; pos = my_needposchar("OLDPWD=", '='); while (env[i] != NULL) { if (my_nmatch("OLDPWD=", env[i], pos) == 0) { if (take_direction(env[i]) == 1) return (-1); if (aff_directory(env[i], pos) == -1) return (-1); return (0); } i++; } my_printf("42sh : cd: OLDPWD not set.\n"); return (-1); }