Add to Favorites    Make Home Page 5191 Online  
 Language Categories  
 Our Services  

Home » C Home » Beginners / Lab Assignments Home » Puzzle--finding the number

A D V E R T I S E M E N T

Search Projects & Source Codes:

Title Puzzle--finding the number
Author Vinoth
Author Email vintaf_2 [at] yahoo.com
Description This is a puzzle game
Category C » Beginners / Lab Assignments
Hits 365283
Code Select and Copy the Code
#include<stdio.h> #include<conio.h> #include<graphics.h> #include<dos.h> #include<math.h> int mx,my,ans=0,p=4; screen(); void button(); /* The main logic lies in displaying the numbers in the screen The numbers are placed corresponding to their binary value EX:In case of 14(binary equivalent is 01110).Therefore it will be placed in 2,3 & 4 screen */ int s1[]={16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31}; int s2[]={8,9,10,11,12,13,14,15,24,25,26,27,28,29,30,31}; int s3[]={4,5,6,7,12,13,14,15,20,21,22,23,28,29,30,31}; int s4[]={2,3,6,7,10,11,14,15,18,19,22,23,26,27,30,31}; int s5[]={1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31}; int a1,a2,a3,a4,a5; void main() { int gd=DETECT,gm; initgraph(&gd,&gm,"c:\tc\bgi"); mouseini(); showmp(); action(); } action() { int ans=0; char st[10]; initialscreen(); while(1) { /* The X & Y coordinate of each function is calculated with respect to mx "maximum of x value" & my "maximum of y value" */ if(click((mx/4)+95,(my/4)+100,(mx/4)+235,(my/4)+140,"Play..")==0) { a1=screen(s1,16); a2=screen(s2,16); a3=screen(s3,16); a4=screen(s4,16); a5=screen(s5,16); ans=a1+a2+a3+a4+a5; result(ans); getch(); exit(); } } } initialscreen() { mx=getmaxx(),my=getmaxy(); setmp(); setfillstyle(1,7); bar(mx/4,my/4,3*mx/4,3*my/4); setcolor(WHITE); line(mx/4,my/4,3*mx/4,my/4); line(mx/4,my/4,mx/4,3*my/4); setcolor(BLACK); line(mx/4,3*my/4,3*mx/4,3*my/4); line(3*mx/4,my/4,3*mx/4,3*my/4); setcolor(RED); outtextxy((mx/4)+40,(my/4)+30,"THINK A NUMBER BETWEEN 1-31"); button((mx/4)+95,(my/4)+100,(mx/4)+235,(my/4)+140,"Play.."); } screen(int *scr,int num) { int a,i,x1,y1; char st[10]; mx=getmaxx(),my=getmaxy(); setmp(); setfillstyle(1,7); bar(mx/4,my/4,3*mx/4,3*my/4); setcolor(WHITE); line(mx/4,my/4,3*mx/4,my/4); line(mx/4,my/4,mx/4,3*my/4); setcolor(BLACK); line(mx/4,3*my/4,3*mx/4,3*my/4); line(3*mx/4,my/4,3*mx/4,3*my/4); setcolor(RED); outtextxy((mx/4)+9,(my/4)+5,"TELL ME WHETHER THE NUMBER IS PRESENT?"); button((3*mx/4)-40 ,(3*my/4)-20,(3*mx/4)-5 ,(3*my/4)-5,"yes"); button((3*mx/4)-80 ,(3*my/4)-20,(3*mx/4)-45 ,(3*my/4)-5,"no"); x1=(mx/4)+80; y1=(my/4)+65; for(i=0;i<num;i++) { a=scr[i]; /*To convert the integer into string and then displaying it on the graphic mode*/ itoa(a,st,10); outtextxy(x1 ,y1,&st); x1+=50; if((i==3)||(i==7)||(i==11)) { y1=y1+30; x1=(mx/4)+80; } } /*We have already noted that the numbers are placed in screen corresponding to their binary value To find the number we can convert these binary numbers to integers*/ while(1) { if (click((3*mx/4)-40 ,(3*my/4)-20,(3*mx/4)-5 ,(3*my/4)-5,"yes")==0) { ans=pow(2,p); p=p-1; return ans; } if (click((3*mx/4)-80 ,(3*my/4)-20,(3*mx/4)-45 ,(3*my/4)-5,"no")==0) { p=p-1; return 0; } } } result(int ans) { char st[10]; mx=getmaxx(),my=getmaxy(); setmp(); setfillstyle(1,7); bar(mx/4,my/4,3*mx/4,3*my/4); setcolor(WHITE); line(mx/4,my/4,3*mx/4,my/4); line(mx/4,my/4,mx/4,3*my/4); setcolor(BLACK); line(mx/4,3*my/4,3*mx/4,3*my/4); line(3*mx/4,my/4,3*mx/4,3*my/4); setcolor(RED); if(ans==0) { outtextxy((mx/4)+110,(my/4)+45,"I DONT BELEIVE"); outtextxy((mx/4)+60,(my/4)+60,"YOU MIGHT BE WRONG SOMEWHERE"); } else { outtextxy((mx/4)+95,(my/4)+30,"THE NUMBER IS "); itoa(ans,st,10); outtextxy((mx/4)+205,(my/4)+30,st); } button((mx/4)+95,(my/4)+100,(mx/4)+235,(my/4)+140,"TRY AGAIN!"); button((mx/4)+95,(my/4)+150,(mx/4)+235,(my/4)+190,"EXIT"); while(1) { if (click((mx/4)+95,(my/4)+150,(mx/4)+235,(my/4)+190,"EXIT")==0) { closegraph(); restorecrtmode(); exit(); } if (click((mx/4)+95,(my/4)+100,(mx/4)+235,(my/4)+140,"TRY AGAIN!")==0) { p=4; action(); } } } void button(int x1,int y1,int x2,int y2,char str[]) { int xc,yc,i=0,l=0; while(i<strlen(str)) { l+=4; i++; } xc=(x2-x1)/2+x1-l; yc=(y2-y1)/2+y1; unpress(x1,y1,x2,y2); settextstyle(0,0,0); setcolor(RED); outtextxy(xc,yc,str); } unpress(int x1,int y1,int x2,int y2) { setlinestyle(0,1,1); setfillstyle(1,7); bar(x1,y1,x2,y2); setcolor(WHITE); line(x1,y1,x2,y1); line(x1,y1,x1,y2); setcolor(0); line(x1,y2,x2,y2); line(x2,y1,x2,y2); return 0; } press(int x1,int y1,int x2,int y2) { setlinestyle(0,1,1); setfillstyle(1,7); bar(x1,y1,x2,y2); setcolor(0); line(x1,y1,x2,y1); line(x1,y1,x1,y2); setcolor(WHITE); line(x1,y2,x2,y2); line(x2,y1,x2,y2); return 0; } mouseini() { union REGS i,o; i.x.ax=0; int86(0x33,&i,&o); return(o.x.ax); } showmp() { union REGS i,o; i.x.ax=1; int86(0x33,&i,&o); return 0; } hidemp() { union REGS i,o; i.x.ax=2; int86(0x33,&i,&o); return 0; } getmp(int *button,int *x,int *y) { union REGS i,o; i.x.ax=3; int86(0x33,&i,&o); *button=o.x.bx; *x=o.x.cx; *y=o.x.dx; return 0; } setmp() { union REGS i,o; i.x.ax=4; i.x.cx=(3*mx/4)+20; i.x.dx=(3*my/4)+20; int86(0x33,&i,&o); } click(int x1,int y1,int x2,int y2,char str[]) { int button,x,y; int xc,yc,i=0,l=0; while(i<strlen(str)) { l+=4; i++; } xc=(x2-x1)/2+x1-l; yc=(y2-y1)/2+y1; getmp(&button,&x,&y); if( (x>x1 && x<x2) && (y>y1 && y<y2) && button==1) { hidemp(); press(x1,y1,x2,y2); setcolor(RED); settextstyle(0,0,0); outtextxy(xc,yc,str); showmp(); while((button==1)) getmp(&button,&x,&y); hidemp(); unpress(x1,y1,x2,y2); showmp(); setcolor(RED); settextstyle(0,0,0); outtextxy(xc,yc,str); for(i=50;i<500;i=i+50) { delay(10); sound(i+200); } showmp(); nosound(); setcolor(RED); settextstyle(0,0,0); outtextxy(xc,yc,str); return 0; } else return 1; }

Related Source Codes

Script Name Author
The Game Opposite as seen on Nokia 2300 Mobile Manikanta
RECURSIVE BALANCED QUICK SORT ashish
Radix Sort ashish
Change your mouse pointer Ashim
The blinking star Shashank
Data Validation Crylittlebaby
To search a file by giving file type like mp3 or mpeg or doc Prashanth SR
Menus Demonstration B.Chidhambaram
Employee Database Project Using C. Reenku Raman Nayak
Creating a Lexical Analyzer in c fahad bader al-buhairi ¦Õ¤ ?¤Ð Ãß??ÝÐÝ
Calendar Program Omkar & Devendra
Stop double Process for start in C Cedrik Jurak
Stop double Process for start in C Cedrik Jurak
Time Scheduler Atiq Anwar
A timepass game between atmost two players Rahul Roy

A D V E R T I S E M E N T




Google Groups Subscribe to SourceCodesWorld - Techies Talk
Email:

Free eBook - Interview Questions: Get over 1,000 Interview Questions in an eBook for free when you join JobsAssist. Just click on the button below to join JobsAssist and you will immediately receive the Free eBook with thousands of Interview Questions in an ebook when you join.

New! Click here to Add your Code!


ASP Home | C Home | C++ Home | COBOL Home | Java Home | Pascal Home
Source Codes Home Page

 Advertisements  

Google Search

Google

Source Codes World.com is a part of Vyom Network.

Vyom Network : Web Hosting | Dedicated Server | Free SMS, GRE, GMAT, MBA | Online Exams | Freshers Jobs | Software Downloads | Interview Questions | Jobs, Discussions | Placement Papers | Free eBooks | Free eBooks | Free Business Info | Interview Questions | Free Tutorials | Arabic, French, German | IAS Preparation | Jokes, Songs, Fun | Free Classifieds | Free Recipes | Free Downloads | Bangalore Info | Tech Solutions | Project Outsourcing, Web Hosting | GATE Preparation | MBA Preparation | SAP Info | Software Testing | Google Logo Maker | Freshers Jobs

Sitemap | Privacy Policy | Terms and Conditions | Important Websites
Copyright ©2003-2024 SourceCodesWorld.com, All Rights Reserved.
Page URL: http://www.sourcecodesworld.com/source/show.asp?ScriptID=665


Download Yahoo Messenger | Placement Papers | Free SMS | C Interview Questions | C++ Interview Questions | Quick2Host Review