009
20.01.2004, 00:36 Uhr
0xdeadbeef
Gott (Operator)
|
Das sieht zwar in der Tat krank aus, aber in der Regel werden solche Programme erst geschrieben und nachher von Hand verunstaltet. Ich hab sowas mal auseinandergepfriemelt, das hier:
C++: |
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/time.h> #include <signal.h> #define m(b)a=b;z=*a;while(*++a){y=*a;*a=z;z=y;} #define h(u)G=u<<3;printf("\e[%uq",l[ u ]) #define c(n,s)case n:s;continue char x[]="((((((((((((((((((((((",w[]= "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b";char r[]={92,124,47},l[]={2,3,1 ,0};char*T[]={" |"," |","%\\|/%"," %%%",""};char d=1,p=40,o=40,k=0,*a,y,z,g= -1,G,X,**P=&T[4],f=0;unsigned int s=0;void u(int i){int n;printf( "\233;%uH\233L%c\233;%uH%c\233;%uH%s\23322;%uH@\23323;%uH \n",*x-*w,r[d],*x+*w ,r[d],X,*P,p+=k,o);if(abs(p-x[21])>=w[21])exit(0);if(g!=G){struct itimerval t= {0,0,0,0};g+=((g<G)<<1)-1;t.it_interval.tv_usec=t.it_value.tv_usec=72000/((g>> 3)+1);setitimer(0,&t,0);f&&printf("\e[10;%u]",g+24);}f&&putchar(7);s+=(9-w[21] )*((g>>3)+1);o=p;m(x);m(w);(n=rand())&255||--*w||++*w;if(!(**P&&P++||n&7936)){ while(abs((X=rand()%76)-*x+2)-*w<6);++X;P=T;}(n=rand()&31)<3&&(d=n);!d&&--*x<= *w&&(++*x,++d)||d==2&&++*x+*w>79&&(--*x,--d);signal(i,u);}void e(){signal(14, SIG_IGN);printf("\e[0q\ecScore: %u\n",s);system("stty echo -cbreak");}int main (int C,char**V){atexit(e);(C<2||*V[1]!=113)&&(f=(C=*(int*)getenv("TERM"))==( int)0x756E696C||C==(int)0x6C696E75);srand(getpid());system("stty -echo cbreak" );h(0);u(14);for(;;)switch(getchar()){case 113:return 0;case 91:case 98:c(44,k =-1);case 32:case 110:c(46,k=0);case 93:case 109:c(47,k=1);c(49,h(0));c(50,h(1 ));c(51,h(2));c(52,h(3));}}
|
löste sich dann auf in
C++: |
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/time.h> #include <signal.h>
#define LEFT (-1) #define RIGHT (1) #define FWD (0)
#define MAX_TRACK_INDEX (21) #define MAX_TREE_INDEX (4)
int track[] = { 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40}, width [] = { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8}, led [] = { 2, 3, 1, 0};
char delim [] = { '\\', '|', '/' }, *tree [] = {" |", " |", "%\\|/%", " %%%", ""}; int tree_ix = MAX_TREE_INDEX, tree_pos, delim_ix = 1, pos = 40, oldpos = 40, steer = FWD, lauf, speed = -1, gear = 0, sound_on = 0;
unsigned int score = 0;
void do_main (int sig) { int n;
pos += steer; printf ("\233;%uH\233L%c\233;%uH%c\233;%uH%s\23322;%uH@\23323;%uH \n", track[0] - width[0], delim[delim_ix], track[0] + width[0], delim[delim_ix], tree_pos, tree[tree_ix], pos, oldpos);
if (abs (pos - track[MAX_TRACK_INDEX]) >= width[MAX_TRACK_INDEX]) exit (0);
if (speed != gear*8) { struct itimerval t = { 0, 0, 0, 0 };
speed += (speed < gear*8) ? 1 : -1;
t.it_interval.tv_usec = t.it_value.tv_usec = 72000 / (speed / 8 + 1); setitimer (0, &t, 0);
if(sound_on) printf ("\e[10;%u]", speed + 24); }
if(sound_on) putchar (7);
score += (9 - width[MAX_TRACK_INDEX]) * (speed / 8 + 1); oldpos = pos;
for(lauf = MAX_TRACK_INDEX; lauf > 0; --lauf) { width[lauf] = width[lauf - 1]; track[lauf] = track[lauf - 1]; }
if((n = rand ()) % 256 == 0 && width[0] > 1) --width[0];
if (tree[tree_ix][0]) { ++tree_ix; } else if(!(n&0x1f00)) { while (abs ((tree_pos = rand () % 76) - track[0] + 2) - width[0] < 6); ++tree_pos; tree_ix = 0; }
if((n = rand () & 31) < 3) (delim_ix = n);
if(delim_ix == 0 && --track[0] - width[0] <= 0){ ++track[0]; ++delim_ix; } else if(delim_ix == 2 && ++track[0] + width[0] >= 80) { --track[0]; --delim_ix; }
signal (SIGALRM, do_main); }
void do_on_exit () { signal (SIGALRM, ((__sighandler_t) 1)); printf ("\e[0q\ecScore: %u\n", score); system ("stty echo -cbreak"); }
int main (int argc, char *argv[]) { int term; char c;
atexit (do_on_exit);
if((argc < 2 || *argv[1] != 113)) { term = *(int*) getenv("TERM"); if (term == (int) 0x756E696C || term == (int) 0x6C696E75) sound_on = 1; }
srand (getpid ()); system ("stty -echo cbreak");
printf("\e[%uq", led[gear]);
do_main (SIGALRM);
for(;;) switch (c = getchar ()) { case 'q': return 0; case '[': case 'b': case ',': steer = LEFT; continue; case ' ': case 'n': case '.': steer = FWD; continue; case ']': case 'm': case '/': steer = RIGHT; continue; case '1': case '2': case '3': case '4': gear = c - '1'; printf ("\e[%uq", led[gear]); continue; } }
|
-- Einfachheit ist Voraussetzung für Zuverlässigkeit. -- Edsger Wybe Dijkstra Dieser Post wurde am 20.01.2004 um 00:37 Uhr von 0xdeadbeef editiert. |