void protoss_build_nexus(char* f_name,partition_t* nexus){ FILE* fp = fopen(f_name,"w"); int i; char* temp; char set_temp[] = {"charset "}; fputs("#nexus\n",fp); fputs("begin sets;\n",fp); for(i=0;i<nexus->part_len;i++){ fputs(set_temp,fp); fputs(nexus->gene_names[i],fp); fputs(" = ",fp); temp=intchar(nexus->start[i]); fputs(temp,fp); free(temp); fputs(" - ",fp); temp=intchar(nexus->end[i]); fputs(temp,fp); free(temp); fputs(";\n",fp); } fputs("\ncharpartition ",fp); fputs(nexus->partition_names[0],fp); fputs(" =\n",fp); for(i=0;i<nexus->part_len;i++){ fputs(nexus->model_names[i],fp); fputs(": ",fp); fputs(nexus->gene_names[i],fp); if(i==(nexus->part_len-1)) fputs(" ;\n",fp); else fputs(" ,\n",fp); } fputs("end;",fp); fclose(fp); }
void display_portal( int x, int y, int n, BITMAP *bm) { char filename[] = "Image/PortalX.bmp"; filename[12] = intchar(n); BITMAP *port = load_bitmap(filename,NULL); blit(port,bm,0,0,x-5,y-5,10,10); }
void saverec( int matrix[][50], int v[][2], int f[]) // this function will write the new record on the file { int i,j,k=0; // counters char filename[] = "sceneryx.txt"; if(scenery_number==-1) { filename[7] = 'x'; } else if(scenery_number==0) { filename[7] = '_'; } else { filename[7] = intchar(scenery_number); } // before, the function will erase the snake on the matrix and the food erase(matrix,v); matrix[f[0]][f[1]] = 0; FILE *scenery; // the pointer of file scenery = fopen(filename,"w"); // opening the file to write /* Writing the matrix */ for(i=0; i<25; i++) // passing through the lines { for(j=0; j<50; j++) { putc(intchar(matrix[i][j]),scenery); // passing through the column } putc('\n',scenery); // at the final of the line, put a newline } /*Writing the record*/ if(score > record) { record = score; for(i=4; i>=0; i--) { putc(intchar(((int)(record/pow(10,i)))%10),scenery); } textout_ex(screen,font,"NEW RECORD!",220,130,0xFFFFFF,0x000000); } else { for(i=4; i>=0; i--) { putc(intchar(((int)(record/pow(10,i)))%10),scenery); } textout_ex(screen,font,"GAME OVER!",220,130,0xFFFFFF,0x000000); } fclose(scenery); }
void outnumber( int x, int y, int number) // prints a number by coordinates { int k; char str_number[7]; str_number[5] = str_number[6] = ' '; for(k=0; k<5; k++) { str_number[4-k] = intchar(((int)(number/pow(10,k)))%10); } textout_ex(screen,font,str_number,x,y,0x040428,0xFFFFFF); }
int main() { int field[25][50]; int python[1000][2]; int fd[2]; int k,i,j,n=1,counter=0, over,t2; char directory[] = "Music/x.mid"; allegro_init(); install_keyboard(); set_color_depth(32); set_gfx_mode(GFX_AUTODETECT_WINDOWED, 600, 272, 0, 0); install_sound(DIGI_AUTODETECT,MIDI_AUTODETECT,NULL); BITMAP *buffer = create_bitmap(600,272); MIDI *music; while(n>0) { dir = r; length = 4; score = 0; t = 100; sp = 1; over = 0; look = 'r'; t2 = 1; python[0][0] = 15; python[0][1] = 10; python[1][0] = 15; python[1][1] = 9; python[2][0] = 15; python[2][1] = 8; python[3][0] = 15; python[3][1] = 7; srand(time(NULL)); directory[6] = intchar(rand()%9 + 1); music = load_midi(directory); play_midi(music,0); clear_to_color(screen,0x000000); opening(); menu_mode(field); init(field); position(field,python); // position the snake food(field,fd); guardi = python[length-1][0]; guardj = python[length-1][1]; display(field,python,fd,t2); while(over!=1) { if(t2<10) { t2++; } guardi = python[length-1][0]; guardj = python[length-1][1]; save = dir; python[length][0] = i; python[length][1] = j; rest(10); if(keypressed()) { dir = readkey(); } else if ((dir & 0xff) == 'w') dir =u; else if ((dir & 0xff) == 's') dir =d; else if ((dir & 0xff) == 'a') dir =l; else if ((dir & 0xff) == 'd') dir =r; if((dir==u)||(dir==d)||(dir==l)||(dir==r)) { over = analysis(field,python,fd); rest(t-10); } else if(dir==esc) { over=1; n=0; } else { dir = save; over = analysis(field,python,fd); rest(t-10); }; display(field,python,fd,t2); } portal1[0] = 50; portal1[1] = 50; portal2[0] = 50; portal2[1] = 50; clear_to_color(screen,0xFFFFFF); textout_ex(screen,font,"Score: ",225,160,0x02094A,0xF7FF0B); outnumber(265,160,score); saverec(field,python,fd); destroy_midi(music); rest(100); if(readkey()==esc) { n=0; } } destroy_bitmap(buffer); return 0; }
void select_stage( int matrix[][50]) // if wall mode is off { int k = 0, i,j,s=0; char button; char address[13] = "sceneryx.txt"; // the generic address to some scenery BITMAP *buffer2 = create_bitmap(600,272); BITMAP *mb = load_bitmap("Image/Miniblock.bmp",NULL);// load the miniblock FILE *scenery; // pointer of file while(s != 1) { clear_to_color(buffer2,0x6F6F6F); rect(buffer2,173,71,425,198,0x000000);// boot the rectangle rect(buffer2,172,70,426,199,0x000000);// boot the rectangle rectfill(buffer2,174,72,424,197,0xFFFFFF);// boot the rectangle address[7] = intchar(k); scenery = fopen(address,"r"); if(scenery==NULL) { zeroing(matrix); } else { for(i=0; i<25; i++) { for(j=0; j<=50; j++) { if(j==50) { getc(scenery); } else matrix[i][j] = charint(getc(scenery)); } } fclose(scenery); } for(i=0; i<25; i++) { for(j=0; j<50; j++) { if(matrix[i][j]==8) { blit(mb,buffer2,0,0,(177+j*5)-2,(75+i*5)-2,5,5); } } } blit(buffer2,screen,0,0,0,0,600,272); outnumber(240,210,k); textout_ex(screen,font,"Field ",185,210,0xFFFFFF,0x6F6F6F); button = readkey(); rest(20); if((button==enter)&&(scenery!=NULL)&&(k!=0)) { clear_to_color(screen,0xFFFFFF); build_scenery(matrix,address); s = 1; scenery_number = k; } else if((button==enter)&&(scenery==NULL)) { build_scenery(matrix,"scenery_.txt"); s = 1; scenery_number = 0; } else if((button==l)||(button==d)) { if(k>0) { k--; } } else { if(k<9) { k++; } } } }