From f5630398bf78f01c7978b682d9b491fb90168f1a Mon Sep 17 00:00:00 2001 From: Rnhmjoj Date: Wed, 21 Nov 2012 01:07:30 +0100 Subject: [PATCH] =?UTF-8?q?Risolti=20problemi=20di=20compatibilit=C3=A0=20?= =?UTF-8?q?e=20risolti=20alcuni=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit *Abilmente esclusa int mgetchar() dalla compilazione su Windows; *void Sleep(int milliseconds) di windows.h aggiunta; *Risolto un bug che provocava un ciclo infinito dopo che un char rimane nella stdin. *Aggiornato il README.md; --- README.md | 22 +++++++++++++++------- Tris in stile C | Bin 0 -> 22724 bytes main.c | 35 +++++++++++++++++++++-------------- tris.c | 41 +++++++++++++++++++++-------------------- tris.h | 13 +++++++++---- 5 files changed, 66 insertions(+), 45 deletions(-) create mode 100755 Tris in stile C diff --git a/README.md b/README.md index 4892823..f63c1e1 100644 --- a/README.md +++ b/README.md @@ -12,16 +12,24 @@ Le mosse del computer sono pseudocasuali (livello facile) o calcolate usando l'a L'output è a colori grazie alle sequenze di escape ANSI. Per visualizzare decentemente il testo è necessario un terminale compatibile. Su Windows si può usare ANSIcon che ripristina il supporto al driver ANSI.SYS per le console Win32. + Link: http://github.com/adoxa/ansicon -Link: http://github.com/adoxa/ansicon - -### Installazione +### Compilazione Per compilare il programma su UNIX usa _make_. - -Su windows usa un compilatore qualisasi o _make_ se hai MinGW - -Link: http://www.mingw.org + Su windows usa un compilatore qualisasi o _mingw32-make_ se hai MinGW. + Link: http://www.mingw.org ### Istruzioni Le istruzioni su come giocare sono cotenute nel programma stesso. +### Avvisi +Se provando a compilare ricevi avvisi del tipo: + + warning: implicit declaration of function ‘getch’ + warning: implicit declaration of function ‘kbhit’ + +oppure: + + warning: implicit declaration of function ‘mgetchar’ + +è perchè stai compilando rispettivamente su UNIX o su Windows e queste funzioni vengono sostituite dalle loro controparti per quel sistema dato che non sono portabili. Anche se sono nel sorgente e nel file oggetto non verranno mai eseguite. \ No newline at end of file diff --git a/Tris in stile C b/Tris in stile C new file mode 100755 index 0000000000000000000000000000000000000000..b3946ef9391a9ae3b2024fbbf3bcc612a6e4605f GIT binary patch literal 22724 zcmeHPdw5jUwcj&IAcV(+mkJ0RP$1A4f;K2y>@kH7M3sSOcM%+Z35%U(s}F-$R2X1K}7;>*}N%R9#PmZx4h^^+32R!g%NL zII%$LTcI=%-rc3^{&Kx6>J9lNSGs+L-;(-{Dnkgj+n27J;^Zw1pstq`uP(OL7D+uK zSJ8m;rErQ9(o3;Im#$YtBO76tUg?cuc)QYz<`Hh!NAWQfw|VLM#)vJ9&(SxxsIxx8)AbEEm7&!2ptn2wJWAhAB}2GfANg;j zs-r^JeUVTo5;jTc{ySMD?JGAKP@29c68XY@rSizqCCjgJmn<=J00ND9O~(PJ>y>O- zl3jLP6OpG1sS13=l8v&6aCLcrw*fA?Mu;W|IsspVyL6Qhm!rJ+IwAIhJ`gZi`6B&v zkHtL>_XylwUE8h|V)A(^hk&Nx9)x>(A{Lz<3~ZQQx;a=1oUSpr$&MfXuKA8JXJ%dc z;;qA9U2$3aBbS1fi(6#p@IB4MiH0i={Uy07YQT0;J9BYU9raOUJcfrO)i&B+wK*2| zhYA)Jz>dHMVv@E~d)e@ZhVmP@3C{!G!&C=X-__@VJ`ePHpw9z+9_aHxp9h4vMR<}Q zc&guT_0-&%?Ws-VCeK#C8WnW_EgUki7yEB!({QOd;9gsU3WZfC2E){}3?Dz9ol$6=4JAvxk6<9@Vq&;c@di)SsAokoLZ4GGUP}fZTXZ_J1RG^u{i1y<08; zbtG%!;hDn>Zzd08Wabc)A56`I@seh=pd(&so_K zqZ+D=iDZHr{x|S?2@@l#^;*;eEyUT13UA{SUQW%{Jvb}j_)H8p70fnCokRA$%S;DS z$i5ED7P7x(l)PgL*+WVKA^R_X=P7)GjDbtq&}SnAGuSUMH zEYc_*aYte(O!>f^;Sg@Q!xWELyq5Tl7DrPc&C}IkF`h_%6Q|s z`;ijwPo}FO_#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^uS zo&knbJ@u6ICsci=(pRPMY=u`Ve2~KLAsm8rqow?P3a=U>@$V@-cdEpHtni!h)l`Uy z#}t0_Qi(rBIPA++`kzzv6{`RBs(ys3r>}5P`>m?}n8Huu+rgy&xZ>9o|9c8AQTV5d zUnu*(P&j>xK=NPVMoA!FSrW1E+%$Z28m^_`d1?5JG<;qfUYv$snTD@O!>>)lZ%o7K zpC06&?9VM}cr*>aGY#LFhVMzkA56nFG&2GBMBJC)#xM(t`N_Da;HC+N&=3eu{=GsB zqd;hj0^B(E6@|EG;Ko&i|K$<*2PUE6{%3V+La*Ro57jvn`-Chj@#C1O%&P0>W?tPZ zbgxQnIwx}-!t{~6OpUxy2KdWUx|!T{wJPYT9Ipq2eyh-J>xUkq+^vT=QR^Wyh3o3e zDyZSyt;@v(Yao5gN$4?^wy}hB9@o{E83X_;A?k9yl51INGaw<}2c*__xw4yUy0w~{ z>$tgsTWdD~F(FrLoj#3*O}swqF3) + printf(ROSSO" [3]"RESET BIANCO" Difficile\n"); + getchar(); + scanf("%d",&difficolta); + if(difficolta<1||difficolta>3){ printf(GRASSETTO ROSSO"\n Scelta non valida.\n\n" RESET BIANCO); + aspetta(2); + + } }while(difficolta<1||difficolta>3); system(clear); stampa(); @@ -184,6 +190,7 @@ int main (){ do{ system(clear); printf("\n Vuoi usare il tastierino numerico o le coordinate"ROSSO"[T,C]"RESET BIANCO"?\n"); + getchar(); scanf("\n%c",&a); }while(a!='T' && a!='C' && a!='t' && a!='c'); if(a=='T'||a=='t') diff --git a/tris.c b/tris.c index 3f03810..da9eacf 100755 --- a/tris.c +++ b/tris.c @@ -3,25 +3,26 @@ /*Funzioni*/ /*Legge dalla tastiera senza usare il buffer*/ -int mgetchar(){ - char buf=0; - struct termios old={0}; - if(tcgetattr(0,&old)<0) - perror("tcsetattr()"); - old.c_lflag&=~ICANON; - old.c_lflag&=~ECHO; - old.c_cc[VMIN]=1; - old.c_cc[VTIME]=0; - if(tcsetattr(0,TCSANOW,&old)<0) - perror("tcsetattr ICANON"); - if(read(0,&buf,1)<0) - perror("read()"); - old.c_lflag|=ICANON; - old.c_lflag|=ECHO; - if(tcsetattr(0,TCSADRAIN,&old)<0) - perror("tcsetattr ~ICANON"); - return (buf); -} + +UX int mgetchar(){ +UX char buf=0; +UX struct termios old={0}; +UX if(tcgetattr(0,&old)<0) +UX perror("tcsetattr()"); +UX old.c_lflag&=~ICANON; +UX old.c_lflag&=~ECHO; +UX old.c_cc[VMIN]=1; +UX old.c_cc[VTIME]=0; +UX if(tcsetattr(0,TCSANOW,&old)<0) +UX perror("tcsetattr ICANON"); +UX if(read(0,&buf,1)<0) +UX perror("read()"); +UX old.c_lflag|=ICANON; +UX old.c_lflag|=ECHO; +UX if(tcsetattr(0,TCSADRAIN,&old)<0) +UX perror("tcsetattr ~ICANON"); +UX return (buf); +UX} /*Stampa la tabella del tris*/ void stampa(){ @@ -292,7 +293,7 @@ void spinner(int tempo) { for (int i=0; i<(tempo*10);i++){ putchar(spinner[i%4]); fflush(stdout); - usleep(200000); + sleep(2000); putchar('\b'); } printf(RESET); diff --git a/tris.h b/tris.h index 78fa257..ec7337f 100755 --- a/tris.h +++ b/tris.h @@ -26,18 +26,23 @@ /*Funzione specifiche degli os*/ #ifdef __WIN32__ - #define os 0 #include + #include + #define os 0 #define clear "cls" + #define sleep(x) Sleep(x) + #define UX // #else - #define os 1 - #define clear "clear" #include #include + #define os 1 + #define clear "clear" + #define sleep(x) usleep(x*100) + #define UX int mgetchar(void); - + #endif /*Prototipi*/