Here I am, Sunil ; Back again with a new and lot more better version of my base converter. This time the accuracy and precision is million times better than the earlier version. You can convert all sorts of numbers i.e. including real numbers ( 1.23 etc. ). Plus A Memory game to get your mind and time ticking all the time. The graphics are improved. Use of mouse makes it far more easier to use. Altogether Amazing program.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 | /* /// BASE CONVERTER V1.1 /// This is a program built by Me. This was built as a computer science project work. The program includes an easy to use mathematical tool ( Base Converter ) and a memory game. The Base Converter is a tool which can convert all sorts of numbers (including integers and fractions, but excluding -ve numbers) from one base to another to very high degree of accuracy. The Memory game is a simple, but yet exciting game. What you've to do is to remember certain nos. and repeat them when asked. */ #include<mouse.h> // For Operating Mouse // This Is Not A Standard Library Header File #include<iostream.h> #include<graphics.h> #include<conio.h> #include<dos.h> #include<stdlib.h> // For random() : Generating Random Nos. #include<string.h> #include<stdio.h> #include<time.h> // For randomize() : Initialising Random No. Generator // Global Variables char rx[30]; // Used In Conversion From Integer Or Double To Character int snd=0; // Used To Toggle Sound On Or Off int button,xax,yax; // Used To Store Mouse Parameters // Function Prototypes void menu(int y=getmaxy()-25); // Function For User Interaction At The Start void baseconv(); // Main Interface For Base Conversion void num2char(int); // Function To Convert Intergers To Character void zoom() { int a,o,w,z,k; for(a=getmaxx()/2-75,o=getmaxy()/2,w=getmaxx()/2+75,z=getmaxy()/2,k=0;k!=60;k++,a-=5,o-=5,w+=5,z+=5) // Zoom Effect { //setrgbpalette(WHITE,a,o,w); setfillstyle(1,WHITE); bar(a,o,w,z); } cleardevice(); } void timer(int time) // Timer For The Game { setcolor(WHITE); settextstyle(1,0,1); outtextxy(getmaxx()/2-65,getmaxy()-55,"Time Left (SEC)"); for(int i=time;i>0;i--) { rectangle(getmaxx()/2-50,getmaxy()-30,getmaxx()/2+50,getmaxy()-5); num2char(i); outtextxy(getmaxx()/2,getmaxy()-30,rx); setfillstyle(1,BLACK); sleep(1); bar(getmaxx()/2-50,getmaxy()-30,getmaxx()/2+50,getmaxy()-5); // To Hide Text Already Printed } bar(getmaxx()/2-120,getmaxy()-60,getmaxx()/2+100,getmaxy()); // To Hide The Text Printed At Last } void num2char(int x) // Converts Integer To Character Array { int i=0; while(x!=0) { rx[i]=x%10; x=x/10; rx[i]=rx[i]+48; // Setting Up In ASCII Format i++; } rx[i]='\0'; strrev(rx); // Reversing To Get Output In User-Understandable Form } void game() // Function For The Memory Game { int k=0; for(int i=getmaxx();i>getmaxx()-550;i-=10,k++) // Intro Screen { settextstyle(4,0,8); outtextxy(getmaxx()/2-175,getmaxy()/2-50,"Mem Rash"); settextstyle(4,0,4); outtextxy(getmaxx()/2-140,getmaxy()/2+45,"By Barking Bulls !!!"); setcolor(k); setrgbpalette(BLACK,random(50),random(50),random(50)); line(getmaxx(),getmaxy()/2-45,i,getmaxy()/2-45); line(0,getmaxy()/2+90,getmaxx()-i,getmaxy()/2+90); if(i>250) { delay(75); } settextstyle(4,0,8); } setrgbpalette(BLACK,0,10,25); setcolor(WHITE); settextstyle(4,0,8); outtextxy(getmaxx()/2-175,getmaxy()/2-50,"Mem Rash"); settextstyle(4,0,4); outtextxy(getmaxx()/2-140,getmaxy()/2+45,"By Barking Bulls !!!"); line(getmaxx(),getmaxy()/2-45,i,getmaxy()/2-45); line(0,getmaxy()/2+90,getmaxx()-i,getmaxy()/2+90); nosound(); sleep(1); int x,y; cleardevice(); char opt='y'; for(i=0;i<20;i++) // Screen Fade Effect setrgbpalette(BLACK,0,0,i); int no=0; int level=2,time=1; //Game Starts while(opt=='y') { no++; // Generating Random Nos. setcolor(WHITE); settextstyle(installuserfont("NOBL"),0,5); outtextxy(getmaxx()/2-195,25,"Here Are The Numbers"); line(0,85,getmaxx(),85); line(0,80,getmaxx(),80); line(0,10,getmaxx(),10); line(0,5,getmaxx(),5); settextstyle(2,0,5); int numb[100],tempnum[100]={0},k=0; // Variables To Store Random Nos. randomize(); int div1=0,div2=0,l=1; div2=level; if(level>10) { div1=level-10; div2=10; } int tempx=getmaxx()/(div2+1); x=tempx;y=120; for(i=0;i<level;i++,l++) { start: numb[i]=random(100); for(k=0;k<=i;k++) // Checking Repeatition Of Random Nos. { if(numb[i]==tempnum[k]) { goto start; } } tempnum[i]=numb[i]; num2char(numb[i]); outtextxy(x,y,rx); // Showing The Nos. delay(500); if(x<getmaxx()&&l<10) // Justification Of Text { x=x+tempx; } else { y=y+55; tempx=getmaxx()/(div1+1); x=tempx; l=0; } } timer(time); // Count Time bar(0,90,getmaxx(),getmaxy()); bar(0,15,getmaxx(),75); settextstyle(installuserfont("NOBL"),0,5); outtextxy(getmaxx()/2-175,25,"Repeat The Numbers"); int getnum,score=0; // Inputting Answer And Checking With Original Nos. Simultaneously for(i=0;i<level;i++) { gotoxy(38,14); cin>>getnum; gotoxy(38,14); cout<<" "; for(int j=0;j<level;j++) { if(getnum==numb[j]) { numb[j]=-1000; score++; } } } bar(0,15,getmaxx(),75); // Showing Results settextstyle(installuserfont("NOBL"),0,5); outtextxy(getmaxx()/2-70,25,"Results"); settextstyle(1,0,2); if(score<level) { outtextxy(getmaxx()/2-100,getmaxy()/2," You Failed !!"); outtextxy(getmaxx()/2-50,getmaxy()/2+50," Score :"); if(score==0) { outtextxy(getmaxx()/2+50,getmaxy()/2+50,"0"); } else // When User Fails { num2char(score); outtextxy(getmaxx()/2+50,getmaxy()/2+50,rx); } outtextxy(getmaxx()/2-150,getmaxy()/2+90,"Wanna Try Again ? [ Y / N ]"); opt=getche(); cleardevice(); } else // When User Succeeds { if(no>6) // To Check Clearance Of All Levels { cleardevice(); settextstyle(4,0,5); outtextxy(getmaxx()/2-240,getmaxy()/2,"You Cleared All The Levels"); sleep(2); cleardevice(); menu(); // Going Back To Main Menu } outtextxy(getmaxx()/2-75,getmaxy()/2,"You Made It !!"); outtextxy(getmaxx()/2-50,getmaxy()/2+50," Score :"); num2char(score); outtextxy(getmaxx()/2+50,getmaxy()/2+50,rx); outtextxy(getmaxx()/2-150,getmaxy()/2+90,"Wanna Go Ahead ? [ Y / N ]"); opt=getche(); zoom(); level+=2; // Increasing Difficulty Level time+=2; cleardevice(); } } // End Of While Loop cleardevice(); menu(); // Going Back To Main Menu } long double pow(long float number,int power) // Function For Calculating Value " Number " To The { // Power " Power " long double result=1.0; // Including Math.h For Single Function Is Not Efficient Practice if(power>0) { for(int i=0;i<power;i++) result*=number; } else { result=number; for(int i=0;i<1-power;i++) result=result/number; } return(result); } void numchar(long double x) // Converting Long Value To Character Array { char re[30]; int i=1; float a=1; long long int y=x,temp; x=x-y; while(a!=0) // Converting Frational Part { x=x*10; re[i]=int(x); re[i]+=48; temp=re[i]-48; // Setting Up According To ASCII Standard if(x>1) x=x-temp; a=x-temp; i++; if(i>7) break; } re[0]='.'; re[i]='\0'; i=0; while(y!=0) // Converting Integer Part { rx[i]=y%10; y=y/10; rx[i]=rx[i]+48; i++; } rx[i]='\0'; strrev(rx); strcat(rx,re); // Concatenating ( Integer + Fraction ) To Get Output In User Understandable Form } long double charnum(char dec[]) // Function To Convert Character To Number { int j=0,k; long long int x=0; long double y=0; char re[30]; for(int i=0;dec[i]!='.'&&i<strlen(dec);i++); // Counting Number Of Integer Digits k=i+1; i--; for(;i>=0;i--,j++) // Converting Integer Part x=x+((int(dec[i])-48)*pow(10,j)); i=0; j=1; for(;k<strlen(dec);k++,j++) y=y+((int(dec[k])-48)*pow(10,-j)); // Converting Fractional Part return x+y; } void decx(char gg[],int bs) // Function To Convert Decimal Number To Other Bases { // It Can Be Used To Convert Any Decimal Number To Any Base Upto 9 char re[30],rd[30]; // In This Program, It Has Been Used For Octal And Binary Only int i=1,temp; float a=1; long double e,x=charnum(gg); // Getting The Character Data Converted Into Computable Form long long int y=int(charnum(gg)); x=x-y; // Separating Integer Part while(a!=0) // Converting Fractional Part { x=x*bs; re[i]=int(x); re[i]+=48; // Setting Up In ASCII Format temp=re[i]-48; if(x>1) x=x-temp; a=x-temp; i++; if(i>15) break; } re[0]='.'; re[i]='\0'; i=0; while(y!=0) // Converting Integer Part { rd[i]=y%bs; y=y/bs; rd[i]=rd[i]+48; // Setting up In ASCII Format i++; } rd[i]='\0'; strrev(rd); strcat(rd,re); strcpy(rx,rd); } long double xdec(char bin[],int bs) // To Convert Number From Other Bases To Decimal { //Variable Declarations int x[30],y[30],i,h,k,j; double frac=0,intg=0; //Storing Characters in integer form for(i=0;bin[i]!='\0';i++) { if(bin[i]=='.') break; y[i]=int(bin[i])-48; } h=i-1; //Converting Integer Part for(k=0;k<i;k++,h--) { intg=intg+y[k]*pow(bs,h); } //Converting Fractional Part i++; for(j=0;i<strlen(bin);i++,j++) { x[j]=int(bin[i])-48; frac=frac+(x[j]*pow(bs,-(j+1))); } return frac+intg; } int datachk(int bs,char num[]) // Function To Check Validity Of The Data Input { if(bs==2) // For Binary Numbers { for(int i=0;i<strlen(num);i++) { if(num[i]!='1'&&num[i]!='0'&&num[i]!='.') { bs=1; break; } else { bs=0; } } } else if(bs==8) // For Octal Numbers { for(int i=0;i<strlen(num);i++) { if(num[i]!='1'&&num[i]!='0'&&num[i]!='2'&&num[i]!='3'&&num[i]!='4'&&num[i]!='5'&&num[i]!='6'&&num[i]!='7'&&num[i]!='.') { bs=1; break; } else { bs=0; } } } else if(bs==10) // For Decimal Numbers { for(int i=0;i<strlen(num);i++) { if(num[i]!='1'&&num[i]!='0'&&num[i]!='2'&&num[i]!='3'&&num[i]!='4'&&num[i]!='5'&&num[i]!='6'&&num[i]!='7'&&num[i]!='.'&&num[i]!='8'&&num[i]!='9') { bs=1; break; } else { bs=0; } } } return bs; // Returning Truth Value ( i.e. 0 If No Invalid Digits And 1 If Invaild Digits Are Encountered ) } void tag(int x,int y=0) // Function Displaying Various Headings Used In Program { if(x==0) { settextstyle(2,0,2); outtextxy(getmaxx()-80,y,"BASE CONVERTER V1.1"); } else if(x==1) { settextstyle(1,0,2); outtextxy(10,10,"BASE CONVERTER"); line(0,12,getmaxx(),12); line(0,35,getmaxx(),35); line(0,12,0,35); line(getmaxx(),12,getmaxx(),35); } else if(x==2) { settextstyle(1,0,2); outtextxy(10,12,"HELP"); line(0,12,getmaxx(),12); line(0,35,getmaxx(),35); line(0,12,0,35); line(getmaxx(),12,getmaxx(),35); } } void help() // Function To Display Miscelaneous Facts About The Program { cleardevice(); setcolor(WHITE); tag(2); tag(0); int size=4; settextstyle(2,0,size+2); outtextxy(10,50,"Basic Info"); settextstyle(2,0,size); outtextxy(10,70,"Program Name Base Converter + Memory Game"); outtextxy(10,80,"Program Version 1.1"); outtextxy(10,90,"Programmer Sunil Garwar "); outtextxy(10,100,"Publishing Date 24 Feb 2004 "); settextstyle(2,0,size+2); outtextxy(10,120,"Troubleshooting"); settextstyle(2,0,size); outtextxy(10,140,"If You're Experiencing Problems With Program Following Might Help."); outtextxy(10,155,"1) If You Recieve Values Like \"1.0010+e08\" or -ve values,You're Crossing Maximum Allowed Limits."); outtextxy(10,165," This Limit Is Different, For Different Operations.So, I'm Not Mentioning The Values. "); outtextxy(10,175," If You Happen To Get In Such Trouble Try Giving Smaller Values & Get Them Added To Get Bigger Values."); outtextxy(10,185,"2) Don't Input -ve Value Program Has Not Been Designed To Accept -ve Values."); outtextxy(10,195," If You Wan't -ve Values To Be Converted, Convert Equivalent +ve Value & Put '-' Sign ahead it."); settextstyle(2,0,size+2); outtextxy(10,215,"About Author"); settextstyle(2,0,size); outtextxy(10,235,"Occupation Standard XI Student"); outtextxy(10,245," Delhi Public School Korba (C.G.) India"); outtextxy(10,255,"More Information About Us Can Be Found At http://www.prologic.freewebsitehosting.com "); settextstyle(2,0,size+2); outtextxy(10,275,"About Program"); settextstyle(2,0,size); outtextxy(10,295,"A Simple Tool To Convert Numbers Form One Base To Another."); outtextxy(10,305,"You Can Check For Newer Versions At http://www.prologic.freewebsitehosting.com"); outtextxy(10,400,"Warning : Giving Character Inputs In The Game May Corrupt The Program And Possibly Damage Your System."); getch(); } void mus(int type) // Function For Computer Beeps { if(snd==0) // Checking Whether Sound Option Is On { if(type==1) // Different Beeps { sound(100); delay(120); sound(80); delay(160); } else if(type==0) { for(int i=50;i<1000;i+=50) { sound(i); delay(10); } sound(1500); delay(300); sound(1000); delay(200); } else if(type==2) { sound(750); delay(100); } else if(type==3) { for(int i=1000;i>0;i-=50) { sound(i); delay(10); } sound(1000); delay(200); sound(1500); delay(300); } } nosound(); // Putting Speaker Off } void baseconv() // Function Defination For User Interface Of Base Converter { //Variables Declaration char opt1,opt2,opt3,data[30]; int stat=0,y=getmaxy()-25; for(int i=0;i<30;i++) data[i]=' '; setcolor(WHITE); settextstyle(2,0,4); outtextxy(getmaxx()/2-35,getmaxy()/2+25,"LOADING"); rectangle(getmaxx()/2-40,getmaxy()/2+37,getmaxx()/2+10,getmaxy()/2+41); setfillstyle(1,RED); for(i=getmaxx()/2-39;i<getmaxx()/2+10;i++) { delay(10); bar(getmaxx()/2-39,getmaxy()/2+38,i,getmaxy()/2+40); } str: // Label cleardevice(); setcolor(WHITE); tag(1); tag(0); settextstyle(2,0,4); line(350,35,350,getmaxy()-25); outtextxy(35,60,"Select The Base In Which Data Is To Be Entered."); outtextxy(35,75," Decimal [ D ] "); outtextxy(35,90," Octal [ O ] "); outtextxy(35,105," Binary [ B ] "); rectangle(385,85,635,115); outtextxy(475,65,"Input Value"); input : // Label opt1=getche(); mus(2); if(opt1=='d'||opt1=='D') { rectangle(187,76,240,86); outtextxy(485,125,"Decimal"); gotoxy(50,7); cin>>data; stat=datachk(10,data); if(stat==1) { setfillstyle(1,BLACK); bar(482,123,600,139); setcolor(RED); outtextxy(475,125,"Invalid Data"); mus(1); setcolor(WHITE); } } else if(opt1=='o'||opt1=='O') // Input Data To Be Converted { rectangle(187,90,240,101); outtextxy(485,125," Octal"); gotoxy(50,7); cin>>data; stat=datachk(8,data); if(stat==1) { setfillstyle(1,BLACK); bar(482,123,600,139); setcolor(RED); outtextxy(475,125,"Invalid Data"); mus(1); setcolor(WHITE); } } else if(opt1=='b'||opt1=='B') { rectangle(187,105,241,116); outtextxy(485,125,"Binary"); gotoxy(50,7); cin>>data; stat=datachk(2,data); if(stat==1) { setfillstyle(1,BLACK); bar(482,123,600,139); setcolor(RED); outtextxy(475,125,"Invalid Data"); mus(1); setcolor(WHITE); } } else { outtextxy(115,125,"Invalid Option"); mus(1); sleep(1); setfillstyle(1,BLACK); bar(115,123,200,139); goto input; } if(stat==0) { // Asking For Base In Which Data Is To Be Converted outtextxy(35,160,"Select The Base In Which Data Is To Be Converted."); outtextxy(35,175," Decimal [ D ] "); outtextxy(35,190," Octal [ O ] "); outtextxy(35,205," Binary [ B ] "); rectangle(385,181,635,211); outtextxy(475,161,"Output Value"); inp : // Label opt2=getche(); mus(2); if(opt2=='d'||opt2=='D') // Showing The Values { rectangle(187,175,240,186); outtextxy(485,221,"Decimal"); gotoxy(50,13); if(opt1=='d'||opt1=='D') cout<<" No Conversion Required !"; else if(opt1=='b'||opt1=='B') cout<<xdec(data,2); else if(opt1=='o'||opt1=='O') cout<<xdec(data,8); } else if(opt2=='o'||opt2=='O') { rectangle(187,190,240,201); outtextxy(485,221," Octal"); gotoxy(50,13); if(opt1=='o'||opt1=='O') cout<<" No Conversion Required !"; else if(opt1=='b'||opt1=='B') { numchar(xdec(data,2)); decx(rx,8); cout<<rx; for(int c=0;c<30;c++) // Clearing The Array { if(c==29) rx[c]='\0'; else rx[c]=' '; } } else if(opt1=='d'||opt1=='d') { decx(data,8); cout<<rx; for(int c=0;c<30;c++) // Clearing The Array { if(c==29) rx[c]='\0'; else rx[c]=' '; } } } else if(opt2=='b'||opt2=='B') { rectangle(187,205,241,216); outtextxy(485,221,"Binary"); gotoxy(50,13); if(opt1=='b'||opt1=='B') cout<<" No Conversion Required !"; else if(opt1=='d'||opt1=='D') { decx(data,2); cout<<rx; for(int c=0;c<30;c++) // Clearing The Array { if(c==29) rx[c]='\0'; else rx[c]=' '; } } else if(opt1=='o'||opt1=='O') { numchar(xdec(data,8)); decx(rx,2); cout<<rx; for(int c=0;c<30;c++) // Clearing The Array { if(c==29) rx[c]='\0'; else rx[c]=' '; } } } else { outtextxy(115,225,"Invalid Option"); mus(1); sleep(1); setfillstyle(1,BLACK); bar(115,221,200,245); goto inp; } } rectangle(30,y,getmaxx()-30,y+15); // Menu Of Base Converter settextstyle(2,0,4); outtextxy(45,y+1,"Main Menu [ M ]"); line(175,y,175,y+15); outtextxy(190,y+1,"Continue [ C ]"); line(320,y,320,y+15); outtextxy(345,y+1,"Help [ H ]" ); line(460,y,460,y+15); outtextxy(480,y+1,"Exit [ X ]" ); mus(2); setcolor(RED); int u=1; while(u) // Loop To Get Mouse Status { lab: getmousepos(&button,&xax,&yax); if(kbhit()) { opt3=getche(); // Getting The Key Pressed break; } if(button==1&&xax>30&&xax<175&&yax>y&&yax<y+15) { rectangle(30,y,175,y+15); mus(2); setcolor(WHITE); delay(500); cleardevice(); settextstyle(1,0,1); outtextxy(getmaxx()/2-90,getmaxy()/2,"Base Converter V1.1"); tag(0); menu(); } else if(button==1&&xax>175&&xax<320&&yax>y&&yax<y+15) { rectangle(175,y,320,y+15); mus(2); setcolor(WHITE); delay(500); cleardevice(); goto str; } else if(button==1&&xax>460&&xax<getmaxx()-30&&yax>y&&yax<y+15) { rectangle(460,y,getmaxx()-30,y+15); mus(3); exit(0); } else if(button==1&&xax>320&&xax<460&&yax>y&&yax<y+15) { rectangle(320,y,460,y+15); mus(2); setcolor(WHITE); delay(500); cleardevice(); help(); cleardevice(); menu(); } } if(opt3=='m'||opt3=='M') // Operating The Program Using Keyboard { rectangle(30,y,175,y+15); setcolor(WHITE); mus(2); delay(500); cleardevice(); settextstyle(1,0,1); outtextxy(getmaxx()/2-90,getmaxy()/2,"Base Converter V1.1"); tag(0); menu(); } else if(opt3=='c'||opt3=='C') { rectangle(175,y,320,y+15); mus(2); setcolor(WHITE); delay(500); cleardevice(); goto str; } else if(opt3=='x'||opt3=='X') { rectangle(460,y,getmaxx()-30,y+15); mus(3); exit(0); } else if(opt3=='h'||opt3=='H') { rectangle(320,y,460,y+15); mus(2); setcolor(WHITE); delay(500); cleardevice(); help(); cleardevice(); menu(); } else { setcolor(WHITE); outtextxy(getmaxx()/2-30,getmaxy()-37,"Invalid Option "); mus(1); delay(500); setfillstyle(1,BLACK); bar(getmaxx()/2-30,getmaxy()-38,getmaxx()/2+50,y-1); goto lab; } } void menu(int y) // Function Defination Of Main Menu { str: settextstyle(1,0,1); outtextxy(getmaxx()/2-90,getmaxy()/2,"Base Converter V1.1"); tag(0); char opt; rectangle(10,y,getmaxx()-10,y+15); settextstyle(2,0,4); outtextxy(25,y+1,"Base Converter [ B ]"); line(175,y,175,y+15); outtextxy(190,y+1,"Game [ Memory ] [ G ]"); line(320,y,320,y+15); outtextxy(335,y+1,"Sound [ S ] { }"); if(snd==0) outtextxy(440,y+1,"<>"); else { outtextxy(440,y+1,"><"); } line(475,y,475,y+15); outtextxy(490,y+1,"Help [ H ]"); line(570,y,570,y+15); outtextxy(580,y+1,"Exit [X]"); int yy=1; while(yy) // Operating Program Using Mouse { in: if(kbhit()) { opt=getche(); // Getting The Key Pressed break; } setcolor(RED); getmousepos(&button,&xax,&yax); // Getting The Mouse Status if(button==1&&xax>10&&xax<175&&yax>y&&yax<y+15) { rectangle(10,y,175,y+15); mus(2); delay(500); baseconv(); } else if(button==1&&xax>175&&xax<320&&yax>y&&yax<y+15) { rectangle(175,y,320,y+15); mus(2); delay(500); cleardevice(); game(); } else if(button==1&&xax>320&&xax<475&&yax>y&&yax<y+15) { setfillstyle(1,BLACK); mus(2); bar(440,y+1,450,y+14); setcolor(WHITE); if(snd==0) // Putting Sound Off { outtextxy(440,y+1,"><"); delay(300); snd=1; } else { // Putting Sound On outtextxy(440,y+1,"<>"); delay(300); snd=0; } goto in; } else if(button==1&&xax>475&&xax<570&&yax>y&&yax<y+15) { rectangle(475,y,570,y+15); mus(2); delay(500); cleardevice(); help(); cleardevice(); goto str; } else if(button==1&&xax>570&&xax<getmaxx()-10&&yax>y&&yax<y+15) { rectangle(570,y,getmaxx()-10,y+15); mus(3); exit(0); } } if(opt=='b'||opt=='B') // Operating The Menu Using Keyboard { rectangle(10,y,175,y+15); mus(2); delay(500); baseconv(); } else if(opt=='g'||opt=='G') { rectangle(175,y,320,y+15); mus(2); delay(500); cleardevice(); game(); } else if(opt=='s'||opt=='S') { setfillstyle(1,BLACK); mus(2); bar(440,y+1,450,y+14); setcolor(WHITE); if(snd==0) { outtextxy(440,y+1,"><"); delay(300); snd=1; } else { outtextxy(440,y+1,"<>"); delay(300); snd=0; } goto in; } else if(opt=='h'||opt=='H') { rectangle(475,y,570,y+15); mus(2); delay(500); cleardevice(); help(); cleardevice(); goto str; } else if(opt=='x'||opt=='X') { rectangle(570,y,getmaxx()-10,y+15); mus(3); exit(0); } else { setcolor(WHITE); outtextxy(getmaxx()/2-30,getmaxy()-37,"Invalid Option "); mus(1); delay(500); setfillstyle(1,BLACK); bar(getmaxx()/2-30,getmaxy()-38,getmaxx()/2+50,y-1); goto in; } } void start() // Function For Intro Screen On Start Up { tag(0); settextstyle(2,0,4); outtextxy(getmaxx()/2-35,getmaxy()/2,"LOADING"); rectangle(getmaxx()/2-40,getmaxy()/2+12,getmaxx()/2+10,getmaxy()/2+16); setfillstyle(1,RED); for(int i=getmaxx()/2-39;i<getmaxx()/2+10;i++) { delay(25); bar(getmaxx()/2-39,getmaxy()/2+13,i,getmaxy()/2+15); } delay(100); cleardevice(); initmouse(); tag(0); for(i=0;i<10;i++) { setrgbpalette(BLACK,0,0,i); delay(20); } mus(0); delay(100); zoom(); tag(0); setfillstyle(1,BLACK); bar(0,getmaxy()/2-10,getmaxx(),getmaxy()/2+30); settextstyle(1,0,1); outtextxy(getmaxx()/2-75,getmaxy()/2,"Sunil Presents...."); sleep(2); zoom(); tag(0); setfillstyle(1,BLACK); bar(0,getmaxy()/2-10,getmaxx(),getmaxy()/2+30); settextstyle(1,0,1); outtextxy(getmaxx()/2-90,getmaxy()/2,"Base Converter V1.1"); delay(450); showmouseptr(); menu(); } void main() { int gdriver=DETECT,gmode; initgraph(&gdriver,&gmode,"c:\\tc\\bgi"); // Initialising Graphics Mode start(); getch(); closegraph(); // Closing Graphics Mode } //-------------------------------- //Mouse.h //-------------------------------- #include union REGS i,o; initmouse() { i.x.ax=0; int86(0x33,&i,&o); return(o.x.ax); } showmouseptr() { i.x.ax=1; int86(0x33,&i,&o); return(0); } hidemouseptr() { i.x.ax=2; int86(0x33,&i,&o); return(0); } restrictmouseptr(int x1,int y1, int x2, int y2) { i.x.ax=7; i.x.cx=x1; i.x.dx=x2; int86(0x33,&i,&o); i.x.ax=8; i.x.cx=y1; i.x.dx=y2; int86(0x33,&i,&o); return(0); } getmousepos(int *button, int *x, int *y) { i.x.ax=3; int86(0x33,&i,&o); *button=o.x.bx; *x=o.x.cx; *y=o.x.dx; return(0); } |