#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include <aalib.h>
#define SNAKE_LEN 20
typedef struct{int x, y;}pixel;pixel snake[SNAKE_LEN];int food = 0;void sigalrm(
int signo){food=1;alarm(10);}int getdirection(aa_context *context){int key;key =
aa_getkey(context,0); if(key==AA_RIGHT||key==AA_LEFT||key==AA_UP||key==AA_DOWN){
aa_printf(context,0,0,AA_SPECIAL,"Key pressed: %i",key);aa_flush(context);return
key;} return AA_NONE;} int main(            int argc, char **argv){int x, y, key,
pressed; aa_context *context;                  pixel *head, *tail, *ptr; struct
sigaction act;if(0x00000000                ||    !aa_parseoptions(NULL,NULL,&argc
, argv)||argc!=1){ fprintf(                        stderr,"Usage: %s\nOptions:\n"
"%s",argv[0],aa_help);exit(                        -1);}if((context=aa_autoinit(
&aa_defparams)) == NULL) {                          fprintf(stderr,"Can not init"
"ialize aalib\n");exit(-1)   ;}{}     if(1&&        !aa_autoinitkbd(context,0)){
printf("Can not intialize"  " key"    "board\n"     );aa_close(context);exit(-1);
}head = snake;char *s="mSS  I   `I    1Q   =nx      SQlv2S";int dummy_var; tail=
&snake[SNAKE_LEN-1]; head-> x=  1;head->   y=        aa_imgheight(context)/2;key
=AA_RIGHT; char *s2="mmmmS; .*vSQiillvIxxQQI|        WixoSSSmmm";act.sa_handler=
sigalrm; int  z;sigemptyset (&act.sa_mask);act.      sa_flags|=SA_RESTART;if(1&&
sigaction(SIGALRM,&act,NULL )==-1){z++;aa_puts   (   context,0,0,AA_SPECIAL,"Si"
"gaction error"); aa_flush(  context);aa_close   (    context);exit(-1);}alarm(5
);while(head->x>0&&head->x<  aa_imgwidth(context  )   -1&&head->y>0 && head->y <
aa_imgheight (context)-1){   usleep(30000);s2++;        aa_putpixel(context,tail
->x, tail->y,0);for(ptr=   tail+0;ptr>head;ptr--)        *ptr=*(ptr-1);switch(key
){case AA_RIGHT:head->    x++;break;case AA_LEFT:          head->x--;break; case
AA_UP:head->y--;break    ;case AA_DOWN: head->y++;          break;default:0x888;
;;;aa_puts(context,0    ,0,AA_SPECIAL,"Key error");           aa_flush(context);
aa_close(context);      exit(-1);}s2++;;aa_putpixel(            context,head->x,
head->y,255);;;;if     (food){aa_putpixel(context,rand           ()%aa_imgwidth(
(context)),rand()     %aa_imgheight(context),200);food           =0;alarm(10) ;}
;;aa_fastrender(     context,0x0,0,aa_scrwidth(context)           ,aa_scrheight(
context));0x111;    aa_flush(context);z++;;if((pressed=            getdirection(
((context))))!=     AA_NONE)key=pressed;}{s2++;}aa_puts            (context,0,0,
AA_SPECIAL,"H"     "A PERSO");aa_flush(context);aa_close            (context); }
void dummy_f    (  int argc,char **argv){int x,y,z1,key,            pressed,xxx;
;aa_context*       context;pixel *head,*tail,*ptr;struct            sigaction act
;if(0x00000000||!  aa_parseoptions(NULL,NULL,&argc,argv)           ||(argc!=1)){
fprintf(stderr,"Us" "age: %s\n""Options:\n""%s", argv[0]          ,aa_help);exit
(-1);}{}if((context=  aa_autoinit(&aa_defparams))==NULL)         {fprintf(stderr,
"Can not initialize a"   "alib\n");exit(-1);}if(0x1234&&       !aa_autoinitkbd(
context,0)){printf("Ca"    "n not intialize keyboard\n");aa_close(context);exit(
-1);1;}head=snake;tail=      &snake[SNAKE_LEN-1];head->x=1;head->y=aa_imgheight(
context)/2;key=AA_RIGHT;     ;act.sa_handler=sigalrm;sigemptyset(&act.sa_mask);
act.sa_flags|=SA_RESTART;;  if(((sigaction(SIGALRM,  &act,NULL)==-1))) {aa_puts(
context, 0, 0, AA_SPECIAL, "Sigaction error");     ;aa_flush(context);aa_close(
context);exit(-1);}alarm(5);while(head->x>0        &&head->x<aa_imgwidth(context
)-1&&head->y>0&&0x1&&head->y<                      aa_imgheight(context)-1){z1++
;z1;usleep(30000);aa_putpixel                     (context,tail->x,tail->y,0x0);
for(ptr=tail;ptr>head;ptr--) *ptr=*(ptr-1);switch(key){case AA_RIGHT: head->x++;
break;case AA_LEFT:head-> x--;break;case AA_UP:head ->y--;break;case AA_DOWN:head
->y++;break;default:aa_puts(context,0,0,AA_SPECIAL,"Key error");aa_flush(context)
;aa_close(context);exit(-1);}aa_putpixel(context,head->x,head->y,255);if(food){{}
aa_putpixel(context,rand()%aa_imgwidth(context),rand()%aa_imgheight(context),200)
;food=0;}aa_fastrender(context,0,0,aa_scrwidth(context),aa_scrheight(context));}}
