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

Home » C Home » Games and Graphics Home » Magic Number Game - A Program in C

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

Search Projects & Source Codes:

Title Magic Number Game - A Program in C
Author Achin Saxena
Author Email achin_saxena [at] rediffmail.com
Description This program "MAGICNUM.C" has been made for fun and entertainment purpose only. This program asks the user to think any number between 1-55. Then six different lists of numbers are displayed and simultaneously the user is asked to answer whether the number has appeared in the list or not. If the
user has answered honestly/correctly the number been thought is displayed.

This program and its concept has been prepared and developed completely by myself. This program utilizes bit of principles Boolean mathematics as
well as C. Since I wish that other people could make use of this program, I decided to send it to net. As I couldn't find a better site than VyomWorld.com, I am sending this program to it.

Provided that the lists are correctly answered the result will be correct.In case of any ambiguity please check again.
Category C » Games and Graphics
Hits 369159
Code Select and Copy the Code
/* ---------------------------------- Program to find the number which has been thought by a person. You have to think a number between 1-55 and tell whether the number has appeared in following six lists in y/n. Then this program tells the number which has been thought. In case you get a false result that means that either number doesn't lie between 1-55 or some mistakes have been committed in answering y/n. So Please check again. Written & Devloped By : Achin Saxena Email : achin_saxena@rediffmail.com OR achin_saxena@indiatimes.com STD. : BE (II Year) (Electronics & Comm. Engg.) Jodhpur Engg. College & Research Centre Jodhpur (Rajasthan), India In case of any trouble shoot ups or comments about this program please feel free to contact me on e-mail ------------------------------ */ #include <stdio.h> #include <graphics.h> #include <dos.h> #include <string.h> void InitGraphicMode(); void Welcome(); void StartGame(); void DisplayName(int ); void Clear(); void main() { InitGraphicMode(); Welcome(); getch(); StartGame(); closegraph(); } void InitGraphicMode() { int gdriver = DETECT, gmode, errorcode; //In next line the path of bgi files is taken initgraph(&gdriver, &gmode, "c:\tc\bgi"); errorcode = graphresult(); if (errorcode != grOk) /* an error occurred */ { printf("Graphics error: %s ", grapherrormsg(errorcode)); printf("Press any key to halt:"); getch(); exit(1); /* return with error code */ } } //to print the welcome screen void Welcome() { char pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x00, 0x27, 0x20, 0x70}; int i; setfillpattern(pattern, BLUE); for(i=0;i<=320;i++) { bar(320-i,240-i*0.75,320+i,240+i*0.75); delay ( 1 ) ; } settextjustify(1,1); DisplayName(100); settextstyle(5,0,4); outtextxy(100,300,"By :-"); settextstyle(7,0,6); setcolor(14); outtextxy(320,350,"ACHIN SAXENA"); music(); delay(3); } //to Start the game void StartGame() { void FirstScreen(); char ShowList1(),ShowList2(),ShowList3(),ShowList4(),ShowList5(),ShowList6(); int FindNumber(long); long check(char); int number,i; long num=0; char val; char ch; char numstr[10]; while(1) { Clear(); music(); FirstScreen(); Clear(); music(); val=ShowList1(); num=check(val); Clear(); music(); val=ShowList2(); num=num*10+check(val); Clear(); music(); val=ShowList3(); num=num*10+check(val); Clear(); music(); val=ShowList4(); num=num*10+check(val); Clear(); music(); val=ShowList5(); num=num*10+check(val); Clear(); music(); val=ShowList6(); num=num*10+check(val); number=FindNumber(num); itoa(number,numstr,10); Clear(); music(); settextstyle(5,0,4); settextjustify(0,1); if (number) { outtextxy(100,150,"So the number you thought was..."); setcolor(14); settextstyle(4,0,15); settextjustify(1,1); outtextxy(320,250,numstr); setcolor(15); settextstyle(6,0,4); outtextxy(320,350,"Can't believe it ........."); } else { setcolor(14); outtextxy(100,180,"Your number is out of range ..."); outtextxy(200,260,"OR...."); outtextxy(100,340,"You did not answer properly !!! "); } settextjustify(1,1); settextstyle(6,0,4); setcolor(CYAN); outtextxy(320,400,"Wish to Try again (y/n) !!!!"); ch=getch(); if (ch=='y'||ch=='Y') { outtextxy(510,400,"Y"); music(); getch(); } else { outtextxy(510,400,"N"); getch(); music(); return; } } } void DisplayName(int ycor) { char *name[] = {"M","A","G","I","C"," ","N","U","M","B","E","R"}; int i; settextjustify(1,1); settextstyle(4,0,7); for(i=0;i<12;i++) { setcolor(i+2); outtextxy(40+i*45,ycor, name[i]); } } void Clear() { setfillstyle(8,BLUE); bar(0,0,640,480); DisplayName(30); } //Displaying the first Game Screen void FirstScreen() { settextjustify(1,1); setcolor(2); settextstyle(1,0,4); outtextxy(320,150," Think of any number in the range "); setcolor(14); settextstyle(4,0,8); outtextxy(320,250,"1 - 55"); settextstyle(5,0,3); setcolor(CYAN); outtextxy(320,350,"Press any key to continue ......"); setcolor(15); settextstyle(3,0,3); outtextxy(320,430,"And Please... Be Honest !!!!!"); getch(); } //Displaying the six lists char ShowList1() { char ch; setcolor(14); settextstyle(3,0,4); settextjustify(0,1); outtextxy(70,120,"1, 3, 4, 7, 8, 11, 12"); outtextxy(70,180,"14, 16, 17, 18, 19, 20"); outtextxy(70,240,"24, 25, 28, 30, 31, 33"); outtextxy(70,300,"35, 37, 40, 42, 44, 46"); outtextxy(70,360,"47, 48, 50, 52, 54, 55"); settextstyle(5,0,3); setcolor(2); outtextxy(30,420,"Does Your number appear here ? (y/n)..."); ch=getch(); fflush(stdin); if (ch=='y'||ch=='Y') outtextxy(500,420,"Y"); else outtextxy(500,420,"N"); getch(); return(ch); } char ShowList2() { char ch; setcolor(14); settextstyle(3,0,4); settextjustify(0,1); outtextxy(70,120,"1, 3, 6, 8, 10, 11, 12"); outtextxy(70,180,"15, 17, 18, 19, 22, 23"); outtextxy(70,240,"26, 29, 31, 32, 33, 34"); outtextxy(70,300,"36, 37, 38, 41, 44, 45"); outtextxy(70,360,"47, 50, 51, 53, 54, 55"); settextstyle(5,0,3); setcolor(2); outtextxy(30,420,"How about here ? (y/n)..."); ch=getch(); fflush(stdin); if (ch=='y'||ch=='Y') outtextxy(500,420,"Y"); else outtextxy(500,420,"N"); getch(); return(ch); } char ShowList3() { char ch; setcolor(14); settextstyle(3,0,4); settextjustify(0,1); outtextxy(70,120,"1, 2, 5, 6, 7, 10"); outtextxy(70,180,"11, 13, 15, 16, 17, 19"); outtextxy(70,240,"21, 22, 24, 26, 27, 28"); outtextxy(70,300,"32, 35, 38, 40, 44, 46"); outtextxy(70,360,"47, 48, 49, 53, 54, 55"); settextstyle(5,0,3); setcolor(2); outtextxy(30,420,"Now here ? (y/n)..."); ch=getch(); if (ch=='y'||ch=='Y') outtextxy(500,420,"Y"); else outtextxy(500,420,"N"); fflush(stdin); getch(); return(ch); } char ShowList4() { char ch; setcolor(14); settextstyle(3,0,4); settextjustify(0,1); outtextxy(70,120,"1, 2, 5, 9, 13, 17, 18"); outtextxy(70,180,"20, 22, 25, 26, 28, 30"); outtextxy(70,240,"31, 32, 33, 35, 36, 37"); outtextxy(70,300,"38, 39, 40, 41, 42, 43"); outtextxy(70,360,"45, 46, 49, 51, 54, 55"); settextstyle(5,0,3); setcolor(2); outtextxy(30,420,"And here ? (y/n)..."); ch=getch(); fflush(stdin); if (ch=='y'||ch=='Y') outtextxy(500,420,"Y"); else outtextxy(500,420,"N"); getch(); return(ch); } char ShowList5() { char ch; setcolor(14); settextstyle(3,0,4); settextjustify(0,1); outtextxy(70,120," 4, 5, 8, 9, 10"); outtextxy(70,180,"11, 12, 13, 14, 15, 16"); outtextxy(70,240,"19, 21, 24, 27, 29, 30"); outtextxy(70,300,"32, 33, 34, 37, 38, 40"); outtextxy(70,360,"42, 45, 46, 51, 54, 55"); settextstyle(5,0,3); setcolor(2); outtextxy(30,420,"And here ? (y/n)..."); fflush(stdin); ch=getch(); if (ch=='y'||ch=='Y') outtextxy(500,420,"Y"); else outtextxy(500,420,"N"); getch(); return(ch); } char ShowList6() { char ch; setcolor(14); settextstyle(3,0,4); settextjustify(0,1); outtextxy(70,120," 2, 3, 6, 7, 9"); outtextxy(70,180,"12, 13, 14, 15, 17, 19"); outtextxy(70,240,"23, 24, 25, 26, 27, 31"); outtextxy(70,300,"34, 35, 37, 38, 41, 42"); outtextxy(70,360,"43, 46, 47, 51, 52, 55"); settextstyle(5,0,3); setcolor(2); outtextxy(30,420,"Finally here ? (y/n)..."); ch=getch(); fflush(stdin); if (ch=='y'||ch=='Y') outtextxy(500,420,"Y"); else outtextxy(500,420,"N"); getch(); return(ch); } int FindNumber(long num) { switch(num) { case 111100 : return (1); case 1101 : return (2); case 110001 : return (3); case 100010 : return (4); case 1110 : return (5); case 11001 : return (6); case 101001 : return (7); case 110010 : return (8); case 111 : return (9); case 11010 : return(10); case 111010 : return(11); case 110011 : return(12); case 1111 : return(13); case 100011 : return(14); case 11011 : return(15); case 101010 : return(16); case 111101 : return(17); case 110100 : return(18); case 111011 : return(19); case 100100 : return(20); case 1010 : return(21); case 11100 : return(22); case 10001 : return(23); case 101011 : return(24); case 100101 : return(25); case 11101 : return(26); case 1011 : return(27); case 101100 : return(28); case 10010 : return(29); case 100110 : return(30); case 110101 : return(31); case 11110 : return(32); case 110110 : return(33); case 10011 : return(34); case 101101 : return(35); case 10100 : return(36); case 110111 : return(37); case 11111 : return(38); case 100 : return(39); case 101110 : return(40); case 10101 : return(41); case 100111 : return(42); case 101 : return(43); case 111000 : return(44); case 10110 : return(45); case 101111 : return(46); case 111001 : return(47); case 101000 : return(48); case 1100 : return(49); case 110000 : return(50); case 10111 : return(51); case 100001 : return(52); case 11000 : return(53); case 111110 : return(54); case 111111 : return(55); default : return(0); } } long check(char ch) { if (ch=='y'||ch=='Y') return(1); else return(0); } music() { int i ; float octave[7] = { 130.81, 146.83, 164.81, 174.61, 196, 220, 246.94 } ; for ( i = 0 ; i < 7 ; i++ ) { sound ( octave[i] * 8 ) ; delay ( 30 ) ; } nosound(); }

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=427


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