#include <stdlib.h> #include <time.h> #include <allegro.h> #include <tdgui.h> #include "mine.h" DATAFILE *data; char pole[100][100],dif; char shown[100][100]; BITMAP *bmp; int num; unsigned char col[8]={223,1,245,34,13,54,34,23}; const char cx[8]={0,1,1,1,0,-1,-1,-1}; const char cy[8]={-1,-1,0,1,1,1,0,-1}; char stupol=0; int oznacil=0,stlacil=0; char sec,min,hod,tim; void main_delscreen() { int x; char i=2; for(x=0;x>-1;x+=i){ if(x>=480){x=479;i=-2;} hline(screen,0,x,640,0); delay(1); } } static char *obtname[8]={ "Weak Juro", "Very Easy", "Easy", "Normal", "Medium", "Hard", "Master", "Grand Master Imro" }; void urob_tabulku() { int i,c; char tbuf[20]; tdbox(screen,120,140,400,225,6); textout_centre(screen,data[bfont].dat,"Najlepsi hraci",320,140,0); set_config_file("mine.hi"); for(i=0;i<8;i++){ tdhline(screen,125,160+i*25,515); textout(screen,font,obtname[i],125,162+i*25,0); sprintf(tbuf,"dif%d",i); textout(screen,data[bfont].dat,get_config_string(tbuf,"name","Anonym"),125,167+i*25,0); c=get_config_int(tbuf,"time",3600*5); sprintf(tbuf,"- %02d:%02d:%02d",c/3600,(c%3600)/60,c%60); textout(screen,data[bfont].dat,tbuf,315,167+i*25,0); } readkey(); main_delscreen(); } void mainmenu() { int i,k=-1; int x,y; show_mouse(0); text_mode(-1); clear_to_color(screen,makecol(50,50,50)); textout(screen,data[bfont].dat,"VYFUK software 1999",0,0,155); textout_centre(screen,data[bfont].dat,"MINES 1.0",320,100,255); textout_centre(screen,data[bfont].dat,"only for MadMen",320,120,255); tdbox(screen,100,220,440,200,6); tdbox(screen,110,250,420,160,1); tdbox(screen,100,425,440,20,6); tdbox(screen,100,455,440,20,6); textout_centre(screen,data[bfont].dat,"Vyber obtiaznost",320,225,0); textout_centre(screen,data[bfont].dat,"Koniec hry",320,455,0); textout_centre(screen,data[bfont].dat,"Tabulka",320,425,0); for(i=0;i<8;i++){ textout_centre(screen,data[bfont].dat,obtname[i],320,250+i*20,0); tdhline(screen,115,268+i*20,525); } show_mouse(screen); while(k==-1){ if(mouse_b){ x=mouse_x;y=mouse_y; if(x>=100&&x<=540&&y>=455&&y<=474) k=-2; if(x>=110&&x<=530&&y>=250&&y<=410){ k=(y-250)/20; if(k>=8) k=-1; } if(x>=100&&x<=540&&y>=425&&y<=444) k=-3; } if(key[KEY_ESC]) k=-2; } show_mouse(0); main_delscreen(); if(k==-3){ urob_tabulku(); k=-2; } if(k==-2){ allegro_exit(); printf("(C) VYFUK software 1999\n"); exit(0); } dif=k; } char name[25]; void napis_meno() { int c,l; char k=0,a; tdbox(screen,220,200,200,80,6); rectfill(screen,230,230,230+180,270,0); tdbox(screen,230,230,180,40,1); textout_centre(screen,data[bfont].dat,"Napis meno",320,205,0); text_mode(0); l=strlen(name); while(k==0){ name[l]=13; name[l+1]=13; name[l+2]=0; textout(screen,data[bfont].dat,name,235,240,255); a=readkey(); if(a==13) k=1; if(a==8) l--; if(l<0) l=0; if(a>=13&&a<=125){ name[l]=a; l++; } if(a==0) a=readkey(); if(l>11) l=11; } text_mode(-1); name[l]=0; name[l+1]=0; } void save_game() { PACKFILE *s; s=pack_fopen("mine.sve",F_WRITE_PACKED); if(s==0) return; sound(800); pack_fwrite(pole,10000,s); pack_fwrite(shown,10000,s); pack_iputw(num,s); pack_iputw(stupol,s); pack_iputw(oznacil,s); pack_iputw(stlacil,s); pack_iputw(sec,s); pack_iputw(min,s); pack_iputw(hod,s); pack_iputw(dif,s); pack_fwrite(bmp->dat,1000000,s); pack_fclose(s); nosound(); } void load_game() { PACKFILE *s; s=pack_fopen("mine.sve",F_READ_PACKED); if(s==0) return; sound(800); pack_fread(pole,10000,s); pack_fread(shown,10000,s); num=pack_igetw(s); stupol=pack_igetw(s); oznacil=pack_igetw(s); stlacil=pack_igetw(s); sec=pack_igetw(s); min=pack_igetw(s); hod=pack_igetw(s); dif=pack_igetw(s); pack_fread(bmp->dat,1000000,s); pack_fclose(s); nosound(); } void timer() { tim=1; sec++; if(sec>=60){min++;sec=0;} if(min>=60){hod++;min=0;} } END_OF_FUNCTION(timer); void zapis_tab(int cas) { char tbuf[20]; int c; set_config_file("mine.hi"); sprintf(tbuf,"dif%d",dif); c=get_config_int(tbuf,"time",999999); if(cas<=c){ billalert("Ty mas ale stastie","Prekonal si najlepsi cas!",0,"&OK",0,'o',0); strcpy(name,get_config_string(tbuf,"name","Anonymous")); show_mouse(0); napis_meno(); set_config_string(tbuf,"name",name); set_config_int(tbuf,"time",cas); } } void generuj_pole() { int i,x,y,c; const int kd[8]={50,100,200,500,1000,1200,1500,2000}; for(i=0;i<kd[dif];i++) pole[random()%100][random()%100]=-1; num=0; for(x=0;x<100;x++) for(y=0;y<100;y++){ if(pole[x][y]!=-1){ c=0; for(i=0;i<8;i++) if(x+cx[i]>=0&&x+cx[i]<100&&y+cy[i]>=0&&y+cy[i]<100) if(pole[x+cx[i]][y+cy[i]]==-1) c++; pole[x][y]=c; } else num++; } } void nakresli() { int x,y; char tb[3]; for(x=0;x<100;x++) for(y=0;y<100;y++){ if(stupol==0){ if(shown[x][y]==0&&pole[x][y]>=10){ tdbox(bmp,x*10,y*10,9,9,1); if(pole[x][y]>10&&pole[x][y]<20){ sprintf(tb,"%d",pole[x][y]-10); textout(bmp,font,tb,x*10+3,y*10+2,col[pole[x][y]-11]); } shown[x][y]=1; } if(shown[x][y]==-1){ tdbox(bmp,x*10,y*10,9,9,6); shown[x][y]=1; if(pole[x][y]>30) draw_rle_sprite(bmp,data[vlajka].dat,x*10,y*10); else shown[x][y]=0; } } else{ // stupol if(stupol==1){ if(pole[x][y]==-1) draw_rle_sprite(bmp,data[mina].dat,x*10,y*10); } else{ if(pole[x][y]>10&&pole[x][y]<20){ tdbox(bmp,x*10,y*10,9,9,1); sprintf(tb,"%d",pole[x][y]-10); textout(bmp,font,tb,x*10+3,y*10+2,col[pole[x][y]-11]); } if(pole[x][y]>0&&pole[x][y]<10){ tdbox(bmp,x*10,y*10,9,9,1); sprintf(tb,"%d",pole[x][y]); textout(bmp,font,tb,x*10+3,y*10+2,col[pole[x][y]-11]); } if((pole[x][y]==0)||(pole[x][y]==10))tdbox(bmp,x*10,y*10,9,9,1); if((pole[x][y]==-1)||(pole[x][y]==39)) draw_rle_sprite(bmp,data[vlajka].dat,x*10,y*10); } } } } void init_bitmaps() { int x,y; bmp=create_bitmap(1000,1000); for(x=0;x<100;x++)for(y=0;y<100;y++)tdbox(bmp,x*10,y*10,9,9,6); } inline void rozsir(int mx,int my) { char c=5,i; int x,y; if(pole[mx][my]==-1) return; pole[mx][my]+=10; stlacil++; c=0; for(i=0;i<8;i++) if(pole[mx+cx[i]][my+cy[i]]==0){ pole[mx+cx[i]][my+cy[i]]=10;c=1; stlacil++; } while(c!=0){ c=0; for(x=0;x<100;x++) for(y=0;y<100;y++){ if(key[KEY_ESC]) return; if(pole[x][y]==10) for(i=0;i<8;i++) if(x+cx[i]>=0&&x+cx[i]<100&&y+cy[i]>=0&&y+cy[i]<100) if(pole[x+cx[i]][y+cy[i]]<10&&pole[x+cx[i]][y+cy[i]]>=0){ pole[x+cx[i]][y+cy[i]]+=10; stlacil++; c=1; } } } } inline int press_but(int mx,int my,int b) { if(b==1&&pole[mx][my]<30){ if(pole[mx][my]==-1){ stupol=1; return 2; } if(pole[mx][my]>=0&&pole[mx][my]<=8) rozsir(mx,my); return 2; } if(b==2&&((pole[mx][my]<10)||(pole[mx][my]>=30))){ if(pole[mx][my]>30){ if(pole[mx][my]==39) oznacil--; pole[mx][my]-=40;shown[mx][my]=-1; } else if(pole[mx][my]<30){ if(pole[mx][my]==-1) oznacil++; pole[mx][my]+=40;shown[mx][my]=-1; } return 2; } return 0; } void game() { int x=0,y=0,mx,my,cas; char c=1,k=0,tb[10]; generuj_pole(); while(k==0){ if(c==2){nakresli();c=1;} if((c==1)||(tim==1)){ show_mouse(0); vsync(); if(tim==1){ sprintf(tb,"%02d:%02d:%02d",hod,min,sec); tdbox(screen,9,9,100,21,5); textout(screen,data[bfont].dat,tb,15,10,135); tim=0; } blit(bmp,screen,x,y,0,40,640,440); show_mouse(screen); while(mouse_b); c=0; } if(stupol==2){ zapis_tab(cas); stupol=3; } mx=mouse_x;my=mouse_y; if(stupol==0){ if(mouse_b&&my>40){ c=press_but((mx+x)/10,(my+y-40)/10,mouse_b); } if(c==-1) k=-1; } if(mouse_b&&my<40){ if(mx>=120&&mx<=220&&my>9&&my<30){save_game();} if(mx>=230&&mx<=330&&my>9&&my<30){load_game();c=2;} if(mx>=340&&mx<=630&&my>9&&my<30) k=1; } if((oznacil==num&&stupol==0)||(stlacil==(10000-num)&&stupol==0)){ cas=sec+min*60+hod*3600; stupol=2;c=2; } if(mx<1){x-=4;c=1;} if(my<1){y-=4;c=1;} if(mx>638){x+=4;c=1;} if(my>478){y+=4;c=1;} if(x<0) x=0; if(y<0) y=0; if(x>=360) x=360; if(y>=560) y=560; if(key[KEY_ESC]) k=1; } } int main(void) { srandom(time(0)+1000); allegro_init(); install_keyboard(); install_timer(); install_mouse(); bill_init(); packfile_password("IdeaZ"); LOCK_FUNCTION(timer); data=load_datafile("#"); if(data==0){ allegro_exit(); printf("I need MINE.DAT !\n"); exit(1); } install_int_ex(timer,BPS_TO_TIMER(1)); set_color_depth(8); set_gfx_mode(0,640,480,0,0); set_gfx_mode(0,640,480,0,0); set_palette(data[pal].dat); text_mode(-1); col[0]=makecol(0,0,255); col[1]=makecol(0,55,0); col[2]=makecol(255,0,0); col[3]=makecol(255,0,255); col[4]=makecol(0,55,55); col[5]=makecol(255,255,0); col[6]=makecol(0,0,0); col[7]=makecol(0,0,0); mainmenu(); init_bitmaps(); tdbox(screen,0,0,640,39,6); tdbox(screen,120,9,100,21,6); textout_centre(screen,data[bfont].dat,"Save",170,10,col[2]); tdbox(screen,230,9,100,21,6); textout_centre(screen,data[bfont].dat,"Load",280,10,col[2]); tdbox(screen,340,9,290,21,6); textout_centre(screen,data[bfont].dat,"Quit This Stupid Game",485,10,col[2]); game(); main_delscreen(); allegro_exit(); printf("(C) IdeaZ software 1999\n"); exit(0); }