#include #include #include #include #include #include /* .-- |__ | IFTEEN Authored by Hossein Bakhtiarifar No rights are reserved and this software comes with no warranties of any kind to the extent permitted by law. compile with -lncurses */ typedef signed char byte; byte size; byte py,px; byte ey,ex; //the empty tile chtype green=A_BOLD; //bold when there is no color void rectangle(byte sy,byte sx){ for(byte y=0;y<=size+1;y++){ mvaddch(sy+y,sx,ACS_VLINE); mvaddch(sy+y,sx+size*2,ACS_VLINE); } for(byte x=0;x<=size*2;x++){ mvaddch(sy,sx+x,ACS_HLINE); mvaddch(sy+size+1,sx+x,ACS_HLINE); } mvaddch(sy,sx,ACS_ULCORNER); mvaddch(sy+size+1,sx,ACS_LLCORNER); mvaddch(sy,sx+size*2,ACS_URCORNER); mvaddch(sy+size+1,sx+size*2,ACS_LRCORNER); } void logo(byte sy,byte sx){ mvaddstr(sy,sx, ".--"); mvaddstr(sy+1,sx,"|__"); mvaddstr(sy+2,sx,"| IFTEEN"); } //convert integer to representing sign char int2sgn(byte num){ if(!num) return ' '; else if(0< num && num <= 9) return num+'0'; else if(10<=num && num <=35) return num-10+'a'; else if(36<=num && num <=51) return num-36+'A'; return 0; } /*bool isinorder(byte board[size][size],byte y,byte x){ using check[][] is much cheaper return (board[y][x] == y*size+x+1); } */ //display void draw(byte sy,byte sx,char board[size][size],char check[size][size]){ rectangle(sy,sx); chtype prnt; byte y,x; for(y=0;y=0 && y=0 && x7){ fprintf(stderr,"3<=size<=7\n"); return EXIT_FAILURE; } } signal(SIGINT,sigint_handler); srand(time(NULL)%UINT_MAX); initscr(); mousemask(ALL_MOUSE_EVENTS,NULL); noecho(); cbreak(); keypad(stdscr,1); if(has_colors()){ start_color(); use_default_colors(); init_pair(1,COLOR_GREEN,-1); green=COLOR_PAIR(1); } char board[size][size]; char check[size][size]; fill(check); int input; Start: py=px=0; ey=ex=size-1; curs_set(0); fill(board); shuffle(board); while(1){ erase(); logo(0,0); draw(3,0,board,check); refresh(); if(issolved(board,check)) break; input = getch(); if( input==KEY_F(1) || input=='?' ) help(); if( input==KEY_F(2) ) gameplay(); if( input==KEY_MOUSE ) mouseinput(); if( (input=='k' || input==KEY_UP) && py>0) py--; if( (input=='j' || input==KEY_DOWN) && py0) px--; if( (input=='l' || input==KEY_RIGHT) && px