Acknowledgement We, the two students of BCT 070 batch are feeling proud to present our first ever project in “C-Programming”. As we know ‘C’ is the basis of all the high level programming language, it has been compulsorily included in the engineering curriculum to help the students use their imaginative powers to design and bring out something new and display it on the computer. We are extremely overwhelmed with the knowledge that we have gathered in order to build our project and we hope that we would be able to learn more and more in the near future. Our curiosity was to build such a program which would somewhat look like and function as a tablet inside a computer, so we named our project “Virtual Tablet”. In the process of making the project we found that the knowledge we had wasn’t enough to show our imagination onto the screen. Moreover we learnt as many things as we could in order to add more features in our project. The more features we went on adding the further we wanted to add but all of us know that there is always a time limit for completing the project. So, we have tried our best to bring out our imagination to some extent and hope that the viewers would appreciate it. We would like to thank our respected teacher Mr. Babu Ram Dawadi for his valuable instructions on our project and hope to get such cooperation in coming days. Despite our endeavours some errors or bugs might have crept in the project, we would be thankful if you would tell us about these errors, At last, we would like to thank all our friends who had supported us and gave their ideas and views on our project. Be Creative, Enjoy Programming. Saurav Shrestha Sushil Shakya 1 Abstract of the project The main theme of this project is to make the use of simple techniques of CProgramming to build a collections of useful and enjoyable smaller programs and put them into a single box. “Virtual Tablet” , the name itself suggest that it is some kind of tablet like object built in the virtual environment which can’t be touched or felt but can be seen. Our tablet includes games, sound recorder, drawpad, calculator, various themes although all of these aren’t so advanced. Anyone glancing at our project would find it not such a big thing to build but both of us have spent a lot of time making every detail look good and work perfectly. In today’s world technology have become much advanced than it was earlier. Nowadays, we see people using their smart phones, tablets, laptops for various works so anybody would imagine our project to be somewhat like these things. Yeah, we also wanted to make our project look and work as the same but all of us know that advanced works can’t be accomplished without having knowledge about basic things so we made our tablet look like the real one upto the extent of our knowledge. In near future we would be bringing several changes in the project if necessary and our knowledge permits. For now our project is just a simple box where you can enjoy doing things by a simple click selection and not more than that. We want you to enjoy the program and take it as a simple use of basics of ‘C’ but we also want to add saying that “Don’t judge the program by just it’s appearance”. So we want you to view the source code of the project and see the techniques we have used to come up with various new things and also learn them yourself. Finally, we would like to say that we are writing an abstract to a project for the first time and we don’t know how it should look like so we would like to apologize for our mistakes. 2 Background of the project The key idea for making such a project got into our minds when we learnt to make the optimum use of graphics library. As all of engineering students must submit a project as a part of their marks structure, 25 marks has been allocated for the ‘C’ project. Yes, all of us has to compulsorily make the project but we didn’t make it just only for the marks instead we made it to learn more and more. Keeping the marks aside this project was a place to show our creativity and put it infront of all. Our project “Virtual Tablet” is a combination of different smaller programs into one huge field. It has got games, drawing tools, catchy wallpapers and much more. A user can spend much of his/her time on the tablet playing games, making drawings, calculating expressions, saving dates. Despite of our hard labour, we couldn’t make it look as attractive as we expected but still it’s a great achievement for us. Our whole project has been built in “Turbo C”, the very old yet much popular integrated development environment (IDE). Instead of using latest IDE’s like codeblocks, Borland C, we decided of using the older one as it was easy to use and has got several inbuilt functions along with their examples mentioned in the help bar. Another reason for using it was that other IDE don’t include graphics library instead they have got SDL which we weren’t allowed to use. So staying under the guidelines provided by our teacher we have made this project. Even before the project was given to us we had already made many smaller games and calculator and when the project was announced we pulled socks to combine all of our previously built programs into a single one. It took us about 15 days to get all the things into the place. We made several functions and learn about many other inbuilt functions to ease our task and we finally got success. Not only on the look but we have also tried hard to make the codes understandable to all the students so that they can learn some new things by looking at these codes. Last but not the least we are very happy that our project has been completed in time as per the deadline. 3 Problem Analysis When we first analyzed about our project we were sure that it wasn’t an easy task to do. The process of making smaller program is fun but the integration of all of them into a single one is surely the hardest. The program should run with continuous flow with making selection and returning to the main screen. The flow of the program would basically look like as shown below: Main screen Select any option Display the contents Fig: Flow of the program Graphics library is the power tool for making the main screen as well as the other inner screens look attractive and as per the desire. There are points where the program needs to wait for a keyboard hit from the user. For that there is an inbuilt function kbhit() under <conio.h> header file. Next the borders can be shown with the help of inbuilt functions like line(), rectangle(),etc. To go inside any options from the main screen the screen must be cleared and the contents of that options must be printed on the same screen. For that clrscr() could have been used but it generates problems when used with graphics functions so we don’t use it. Instead we print the spaces all over the screen in order to clear it. The main screen consists of a clock on the right side which exactly shows the system time. For that we use gettime() functions included under <time.h> library and get the system time. First we make several header files for different programs that are the parts of our project and then includes them in the main one. Then simply we make a call to the functions under these header files as per the selection of the user. And if the user wants to exit from any inner functions then there must a ‘Back’ button for it and the control of the main program should get passed to the outer functions. Also there should be and ‘Exit’ button which exits the main program and ends it. Overall these are the simple analysis of our project. 4 Algorithm Of the program Under mp.c main: 1. Start the program. 2. Include necessary user defined header files. 3. Initialize the graphic mode and declare a global variable theme= 9. 4. Call the function “front selection”. 5. Stop the program. frontselection: 1. Make necessary declarations to use the mouse pointer. 2. Call the function gendisplayscreen by passing l =1, totx = 5, toty = 1. 3. Call the function displaybox to display outer borders. 4. Call the function selectboxbox to display outer box for the selection. 5. Call the function displaytv to display a tv object on the screen. 6. Use do while(!kbhit()) the loop for making succeeding steps upto 8 to keep executing until the user hits makes a click or hits a key. 7. Call the function all to display the clock. 8. Call the function wallpaper for the live wallpaper. 9. Read a keyboard hit or a click from the user. 10. If a user hits enter or click on the area of “Home” option then ask security pattern and call genselection by passing the totx = 5, toty = 2 and k =2 if the pattern is correct and read a hit or click from the user else display wrong pattern and repeat step 2. 11. If a user hits moving keys or moves the pointer on the other options areas on the front screen call selectbox to make a red box around it. 12. If a user makes an enter hit or click on the quit option then end the program. 13. If a user makes an enter hit or click on the info option display the information about tablet. 14. If a user makes an enter hit or click on the credit option display the credits. 15. Goto step 5. gendisplayscreen: 1. Declare a variable gcnt = 0. 2. Use nested for loop to execute following steps until the row and column becomes equal totx and toty respectively. Call printoption by pasising the value of l that the gendisplayscreen has received and gcnt. gcnt = gcnt + 1 Call optionbox by passing the value of theme. printoption: 1. If l = 1 print the string stored in options[gcnt] declared globally as options pointer. 5 2. If l = 2 print the string stored in homeoptions[gcnt] in the respected areas. 3. If l=3 print the string stored in gameoptions[gcnt] in the respected areas. 4, If l=5 print the string stored in themeoptions[gcnt] in the respected areas. 5. If l= 7 print the string stored in drawpadoption[gcnt] in the respected areas. 6. If l = 8 print the string stored in galleryoption[gcnt] in the respected areas. optionbox: 1. Store the value of theme received in the variable style. 2. If style = 1 make rectangle boxes under every headings throughout the program. 3. I f style = 2 make rings under every headings throughout the program. 4. If style = 3 make triangle under every headings throughout the program. 5. If style = 4 make arrow under every headings throughout the program. 6. If style = 5 make pentagon under every headings throughout the program. 7. If style = 6 make window under every headings throughout the program. 8. If style = 7 make bracket under every headings throughout the program. 9. If style = 8 make dawn under every headings throughout the program. 10. If style = 9 make cube under every headings throughout the program. genselection: 1. Declare cn = 1. 2. Call selectbox to draw outer selection box. 3. Use do while(!kbhit()) loop to read a hit or click from the user. 4. . If a enter or click has been made on the region of back then call displayback to go to backscreen else if moving keys has been used then increase of decrease the coordinates of the box else use nested for loop to call callfunction by passing the value of k and cn and increase the value of cn by 1 after each inner loop. callfunction: 1. If k = 2 then execute following: If n=1 then call memo. If n=2 then call drawpad. If n=3 then call calculator. If n=4 then call games. If n=5 then call recorder. If n=6 then call light to display simple white light. If n=7 then call piano. If n=8 then call gallery. If n=9 then call themes 2. If k= 4 excute following: If n =1 call newdraw. 6 If n = 2 call loaddraw. Call gendisplayscreen by passing totx=3, toty =1 and l =7. 3. If k = 6 execute following: If n = 1 call newrecord. If n = 2 call loadrecord. Call gendisplayscreen by passing totx=3, toty=1 and l = 7. 4. If k = 5 execute following: If n = 1 call fight. If n = 2 call flappy. If n = 3 call fifteen. If n = 4 call chorpolice. Call gendisplayscreen by passing totx=5, toty=1 and l = 3. 5. If k = 8 execute the following: If n = 1 call gimage by passing 3. If n = 2 call gimage by passing 1. If n = 3 call gimage by passing 2. Call gendisplayscreen by passing totx=4, toty=1 and l = 8. 6. If k = 9 then theme = n and call frontselection. 7. If k =10 and n =1 call themes. games: 1. Call gendisplayscreen by passing totx = 5, toty = 1 and l=3. 2. Call genselection by passing totx =5 , toty =1 and k = 5. drawpad: 1. Call gendisplayscreen by passing totx = 3, toty = 1 and l=7. 2. Call genselection by passing totx =5 , toty =1 and k = 4. calculator: 1. Call calcula(). 2. Call gendisplayscreen by passing totx = 5, toty = 2 and l=2. recorder: 1. Call gendisplayscreen by passing totx = 3, toty = 1 and l=7. 2. Call genselection by passing totx =3, toty =1 and k = 6. gallery: 1. Call gendisplayscreen by passing totx = 4, toty = 1 and l=8. 2. Call genselection by passing totx =4 , toty =1 and k = 8. themes: 7 1. Call displaythemes. 2. Call genselection by passing totx =5 , toty =2 and k = 9. displaythemes: 1. Declare cnt = 0. 2. Use nested for loop till the inner loop is executed five times and the outer loop two times to execute the following: Print the list of themes heading using themeoptions[cnt]. cnt = cnt+1 Call optionbox by passing the value of cnt. Under fifteen.h fifteen: 1. Make necessary declaration for using graphics. 2. Call box to draw rectangle divided into nine smaller boxes. 3. Call initialize. 4. Call ssmove. 5. End the program. initialize: 1. Use nested for loop to store the number 1 to 9 in a 2D array number[100] [100] and also print the numbers inside the rectangle boxes. ssmove: 1. Declare count =1 and temp. 2. Call ssselectbox to display red box necessary for the selections. 3. Read a character from user. 4. If a user hits enter and count = 1 then store the number where the user has hit in temp. 5. If user hits enter and count >1 then execute the following: Swap the value where the user has hit with the value of temp. Call sscheck. If sscheck returns 0 then call ssdisplaynumber and print “You Won.” and stop the program. Intialize count = 1. 6. If user hits a right key increase x-cordinates of the red selection box else if user hits a left key decrease x-coordinates of the red selection box else if user hits up key decrease the y coordinate and if user hits down key increase the y coordinate of the box but only when there is place to move inside the rectangular box. 7. If a user hits “Esc” exit the game. 8. Call ssdisplaynumber. 9. Call ssselectbox to draw selection box around the respected area where user wished to move. 10. Goto step 3. ssdisplaynumber: 8 1. Use nested for loop to print the numbers stored in the array number array in the respective postion after they have been swapped by the user. sscheck: 1. Use nested for loop to sum up each horizontal and vertical stored in 2D array number. 2. If all the horizontal and vertical sum equals 15 return 0 else return 1. Under drawpad.h drawpad 1. Make necessary declarations to use graphics and mouse pointers. 2. Call newdraw. 3. Call loaddraw. 4. End the program. newdraw 1. Declare a file pointer *fil. 2. Declare tool =1, size = 10, col=3. 3. Call displaybox for outer borders. 4, Open a file draw.dat in writing mode. 5. Call displaykeyhelp tp displayhelp. 6. Call colorbox to display colours for the user to choose from. 7. Call toolbox to display tools for the user to choose from. 8. Read mouse click or keyboard hit using do while(!kbhit) loop from the user and draw the shapes selected by the user with selected colour and display it by calling drawtool. 9. If a user hits ‘w’ or ‘W’ then size = size +2 else if user hits ‘s’ or ‘S’ then size = size-2 else if user hits ‘q’ or ‘Q” then goto step 10 else goto step 8. 10. Ask user to save the drawing or not. 11. If a user hits ‘y’ call savedraw else close the file. drawtool: 1. If tool =1 make circle of given size. 2. If tool = 2 make rectangle of given size. 3. If tool = 3 make straight horizontal line of given size. 4. If tool = 4 make straight vertical line of given size. 5. If tool = 5 make oblique straight line of given size and inclination. 6. If tool = 6 make oblique straight line of given size and inclination. savedraw: 1. Read name for file and store the name in variable fname and also fname1 and also concantenate “.dat” with fname. 2. Open draw.dat in reading mode. 3. Open a file whose name is stored in fname in appending mode. 9 4. Open a file drawnum.dat in reading mode. 5. Read an integer from drawnum.dat and store it in fn. 6. Close the file drawnum.dat. 7. Open the file drawnum.dat in writing mode. 8. Write the value of fn+1 in drawnum.dat. 9. Close the file drawnum.dat. 10. Use while loop to copy all the contents of draw.dat into file with name stored in variable fname. 11. Store the string fname1 in the file drawfile.dat. 12, Close all the files. loaddraw: 1. Open the file draw.dat for reading. 2. Use while loop to read the content of the file and call the function drawtool by passing the values of tool,x,y,sizeand col as obtained from the file. 3. Close the file. Calcula.h calcula: 1. Declare cn =1, cn1 =1 and an array num[10] globally and call caldisplay. 2. Call calgenselection by passing the values of totx =5 , toty= 4. 3. End the program. calgenselection: 1. Declare cn =1. 2. Call calselectbox to make red selection box. 3. Read a keyboard hit from the user. 4. If a user hits enter call operate by passing current (x,y) coordinates. 5. If a user hits moving keys move the red selection box as per the conditions. 6. Goto step 1. operate: 1. Call calcheck by passing the values of current (x,y) coordinates and store the value returned in z. 2. If z= 1 call posvalue by passing the values of current (x,y) coordinates and store the value returned in r and also execute the following. num[cn] = r. c = cn mod 2. If cn>1 and c= 0 then operate b = 10 * num[cn -1]. num[cn-1] = b+ num[cn]. b = 0. 10 cn = cn-1. else num[cn] = r. 3. Make cn = cn +1. 4. If z = 2 then call posoperator by passing the current (x,y) coordinates and store the value returned in oper[cn1 ]and execute following:. Identify the operator from the value of oper[cn1] and if operator is “sin” or “cos” or “tan” then cn = cn+2 else cn = cn +1 cn1 = cn1 + 1 5. If z = 5 then execute following: call answer and sored the value returned in ans. Display answer and reset all the values to default. calcheck: 1. Use (x,y) coordinates received to check that he entered region is the region of a number or operator or “=”. 2. If the region is for “=” return 5 else if it is for number return 1 elseif it is for operator then return 2. posvalue: 1. Use (x,y) coordinates received to return the exact value of the given location. posoperator: 1. Use (x,y) coordinates received to return the exact operator of the given location. answer: 1. Use num[] and oper[] to calculate the final answer. For example: If num[1] = 5 , num[3] = 7, num[5] = 6, oper[1] = ‘+’, oper[2] = ‘-‘ then at first num[1] and num[3] are operated by oper[1] and resultant isstored in num[3] then num[3] and num[5] are operated by oper[2] and resultant is stored in num[5] and num[5] is returned.. Under gimage.h gimage: 1. Declare val as a global variable. 2. Make necessary declarations to use graphic mode. 3. Call arrow to make arrow shapes. 4. If k=1 then call openfile by passing 1 else if k =2 then call opennote by passing 1 else if k =3 then call opensound by passing 1. 5. Call image by passing the value of k. 6. End the program. image: 1. Make necessary declarations to use mouse pointer. 11 2. Call gcheckpos by passing (x,y) coordinates to check the position of the mouse pointer which returns 1 if the pointer is in the region of left arrow elseif returns 2 if the pointer is in the region of right arrow else returns 0. 3. If left click from mouse is pressed and ch isn’t equal to 0 then execute the following: val = val - 1 if chk = 1 val = val + 1 if chk = 2 val = 1 if val > filenum If k=1 call openfile. If k=2 call opennote. if k =3 call opensound. opennote: 1. Open the memofile.dat in reading mode. 2. Goes to val position of memofile. dat and gets the string stored there and open the file named as this string and display the contents on the screen. opensound: 1. Open the recordfile.dat in reading mode. 2. Goes to val position of recordfile.dat and gets the string stored there and open the file named as this string and display the content. openfile: 1. Open the drawfile.dat in reading mode. 2. Goes to valposition of drawfile.dat and gets the string stored there and open the file named as this string and display the content. Under chorp.h chorpolice: 1. Make necessary declaration to use graphics mode. 2. Call cpvictorybar to show how far is the thief away from the police represented by a circle on the bar. 3. Call cpmove. 4. End the program. cpmove: 1. Make necessary declarations to use mouse pointer. 2. Call chor by passing current(x.y) to make a circle at this position. 3. Use while loop till user hits “Esc” to keep executing the succeeding steps but if user hits “Esc” end the game. 4. Use do while(!kbhit()) loop to evaluate the position of circle in the bar and display “Police wins” if it has reached the police side else if it has reached chor side then display “Chor wins” and end the game. 5. Read a click or keyboard hit from the user. 6. If a click is read then check the coordinae of the mouse pointer and that of the circle. 7. If the coordinates of the mouse lies within the coordinates of the circle displace a circle in the bar towards police else towards chor. 8. If moving keys has been pressed then move then move the centre of the circle to the respective new (x,y) coordinate. 9. Goto step 4. 12 Under recorder.h newrecord: 1. Declare a file pointer fil and a variable time. 2. Open a file recording.dat in writing mode. 3. Use do while(!kbhit()) loop until there is a keyboard hit and keep increasing time by 1 after each loop. 4. If user hits ‘q’ then goto step 7. 5. If a user hits ‘c’ call sound by passing 261. else if a user hits ‘d’ call sound by passing 293. else if a user hits ‘e’ call sound by passing 329. else if a user hits ‘f’ call sound by passing 349. else if a user hits ‘g’ call sound by passing 392. else if a user hits ‘a’ call sound by passing 440. else if a user hits ‘b’ call sound by passing 493. else if a user hits ‘c’ call sound by passing 523. and also store the value of time and keys pressed in the file. 6. Goto step 3. 7. Close the file. 8. Ask the user to save the file or not and read a character. 9. If user hits ‘y’ then call saverecord. saverecord: 1. Read name of file and store it in fname as well as copy it to fname1. 2. Concatenate .dat with fname. 3. Open recording.dat in reading mode. 4. Open file named with the string stored in fname in appending mode. 5. Open file recordfile.dat in appending mode. 6. Open file recordnum.dat in appending mode. 7. Read the content of recordnum.dat and store in fn. 8. If fn>0 then make fn = 0. 9. Close recordnum.dat. 10. Open file recordnum.dat in writing mode and save fn+1 in it. 11. Close file recordnum.dat. 12. Copy all the contents of recording.dat into file with the name stored in fname. 13, Print the string stord in fname1 in recordfile.dat. 14. Close all the files. 13 loadrecord: 1. Open recording .dat in reading mode. 2. Use while loop to execute the following till end of file. Get the time and character and play respective notes. 3. Close the file. Under fight.h 1. Call warrior1 to draw first warrior. 2. Call warrior2 to draw second warrior. 3. Call displayhealthbar to show the lifebar of the warriors. 4. Call normalshot to keep hitting each other with the normal shot. 5. Read a key from the user. 6. If moving keys are hit for warrior 1 move it in the specified direction else if keys are hit for warrior2 move it in the specified directon. 7. If keys for the power shots are hit then hit the opponent with the power shots to decrease the life bar level. 8. Check the healthbar of the players. 9. If health bar of any player has reached null or users hit “Esc” button then stop the game else goto step 4. Under memo.h 1. Call memory to read some text from the user using file handling. 2. If user hits “Esc” key ask if user wants to save the text or not. 3. If user hits ‘y’ then call savememo else exit the program. 4. Save the text in a file using file handling. 5. If user wants to load some previously saved text then call loadmemo and display the saved text. 14 Flowchart of main program only Under mp.c Start main: Include necessary user defined header files. Initialize the graphic mode and declare a global variable theme= 9 and other necessary character pointers. Call the function “front selection”. Stop frontselection: Start Make necessary declarations to use the mouse pointer. Call the function gendisplayscreen by passing l =1, totx = 5, toty = 1. Call the function displaybox to display outer borders. Call the function selectboxbox to display outer box for the selection. 2 Call the function displaytv to display a tv object on the screen. Yes Is there a keyboard hit or mouse click? No Call the function all to display the clock. Call the function wallpaper for the live wallpaper. Read a keyboard hit or a click from the user. 1 15 1 No Is home entered or clicked? Yes Call genselection by passing the totx = 5, toty = 2 and k =2 Are moving keys hit or pointer moved? No Yes Call selectbox to make red selection box.. Is info selected? No Yes Display the tablet information. Is credit selected? No Yes Display the credits. Is exit selected? No 2 Yes Stop 16 gendisplayscreen: Declare a variable gcnt = 0. Has the nested loop executed for specified times? No Yes Call printoption by pasising the value of l that the gendisplayscreen has received and gcnt declared intially. gcnt = gcnt +1. Call optionbox by passing the value of theme. printoption: No Is l= 1 ? Yes Print the string stored in options[cnt]. Is l=2 ? No Yes Print the string stored in homeoptions[cnt]. No 3 Is l=3? Yes Print the string stored in gameoptions[cnt]. 17 3 No Is l= 5? Yes Print the string stored in themeoptions[cnt]. Is l=7 ? No Yes Print the string stored in drawoptions[cnt]. Is l=8? No Yes Print the string stored in galleryoptions[cnt]. optionbox: No Is style =1 ? Yes Display rectangle boxes under headings. Is style = 2? No Yes Display rings under headings. 4 18 4 No Is style =3 ? Yes Display triangle under headings. Is style = 4? No Yes Display arrow under headings. No Is style =5 ? Yes Display pentagon under headings. Is style = 6? No Yes Display window under headings. No Is style =7 ? Yes Display bracket under headings. Is style = 8? No Yes Display dawn under headings. 5 19 5 No Is style =9 ? Yes Display cube under headings. genselection: Declare a variable cn =1. Call selectbox to draw outer selection box. Is there a keyboard hit or a mouse click? Yes No Is back has been entered or clicked? Yes Call displayback to go to back screen. Has nested v loop executed for specified times? Yes No Call callfunction by passing k and cn. cn = cn+1. 20 callfunction: Is k= 1 ? No 6 Yes Is n=1 ? No Yes call memo. Yes Is n=2? call drawpad. Is n=3? No Yes call calculator. Is n=4? No Yes call drawpad. Yes Is n=5? call recorder. No 7 21 7 Is n=6 ? No Yes call light. Is n=7? No Yes call piano. Is n=8? No Yes call themes. Is n=9? Yes call themes. 6 No Is k=4? 8 Yes Is n=1 ? No Yes call newdraw. 9 22 9 No Is n=2? Yes call loaddraw. 8 Is k=6? Yes No Is n=1 ? No Yes call newrecord. Yes No Is n=2? Yes call loadrecord. Is k=5? 10 Yes No Is n=1? Yes call fight. Is n=2?No call flappy. . 11 23 11 Is n=3? No Yes call fifteen. Is n=4? No Yes call chorpolice. Is k=8? 10 Yes Is n=1 ? No Yes call gimage. by passing 3. Is n=2? No Yes call gimage. by passing 2. Is n=3? No Yes Is k=10 and n =1? No call gimage. by passing 1. Yes call themes. 24 25 Output Snapsots Main Screen: Security screen: 26 Home screen: Drawpad Screen: 27 Piano Screen: Fight Screen: 28 Flappy screen: Fifteen screen: 29 Chorpolice screen: Gallery screen: 30 Calculator screen: Themes screen: 31 Coding Under mp.c #include<stdio.h> #include<conio.h> #include<graphics.h> #include<dos.h> #include<process.h> #include"myfunc.h" #include"fight.h" #include"calcula.h" #include"drawpad.h" #include"recorder.h" #include"fifteen.h" #include"chorp.h" #include"flappy.h" #include"gimage.h" #include"clock.h" #include"memo.h" #include"piano.h" #include"pattern.h" 32 void gendisplayscreen(int,int,int,int,int,int); void genselection(int,int,int,int,int,int,int); int bcol=3,hbcol=9,gbcol=6,dbcol=8,sbcol=4,fbcol=2,sscol=1,theme=9,wper=2; char* options[5]={" Home","Info","Security","Credit"," Quit"} ; char*homeoptions[10]={"Memo","Drawpad","Calcula","Games","Record","Light","Piano","Gallery","Themes"," Back"}; char* gameoptions[5]={" Fight","Flappy","Fifteen","Catch"," Back"}; char*themeoptions[10]={"Tiles","Ring","Traingle","Arrow","Pentagon","Window","Bracket","Dawn","Cube","Back"}; char* drawpadoption[3]={"New"," Load","Back"}; char* galleryoption[4]={"Sounds","Picture","Notes","Back"}; /*the function optionbox(x,y,style) draws the logo of the option at (x,y) according to current theme.the value of theme is passed as style which determines the shape of logo.*/ void optionbox(x,y,style) // for the outer lining below the headings. { if(style==1) //condition for tiles rectangle(x,y,x+50,y+45); if(style==2) //condtition for ring circle(x+25,y+20,23); if(style==3) //for triangle { line(x+25,y,x+50,y+45); line(x+25,y,x,y+45); line(x,y+45,x+50,y+45); } if(style==4) //for arrow { line(x+25,y,x+50,y+45); line(x+25,y,x,y+45); line(x,y+45,x+25,y+35); line(x+25,y+35,x+50,y+45); } if(style==5) // for pentagon and so on..... { line(x+25,y,x,y+20); line(x,y+20,x+10,y+45); 33 line(x+10,y+45,x+40,y+45); line(x+40,y+45,x+50,y+20); line(x+50,y+20,x+25,y); } if(style==6) { rectangle(x,y,x+50,y+45); rectangle(x+5,y+4,x+45,y+41); line(x+5,y+4,x,y); line(x+45,y+4,x+50,y); line(x+5,y+41,x,y+45); line(x+45,y+41,x+50,y+45); } if(style==7) { line(x+10,y,x,y+20) ; line(x,y+20,x+10,y+45); line(x+40,y,x+50,y+20); line(x+50,y+20,x+40,y+45); } if(style==8) { circle(x+25,y+15,10); line(x+20,y+35,x,y+15); line(x+30,y+35,x+50,y+15); line(x+30,y+35,x+30,y+45); line(x+20,y+35,x+20,y+45); } if(style==9) { rectangle(x+10,y,x+30,y+20); rectangle(x+35,y,x+55,y+20); rectangle (x+10,y+25,x+30,y+45); rectangle(x+35,y+25,x+55,y+45); } 34 } void selectbox(x,y,col)// for drawing outer box for selection. { setcolor(col); rectangle(x+3,y,x+70,y+70); } void clearbox(x,y) //for overwriting the outer lining of the selection box black. { setcolor(0); rectangle(x+3,y,x+70,y+70); } void displaythemes() //for displaying the options inside themes menu { int i,j,x=6,y=4,x1=45,y1=70; int tcnt=0; displaybox(bcol); setcolor(5); for(j=1,y=4,y1=70;j<=2;j++,y+=7,y1+=105) { for(i=1,x=6,x1=45;i<=5;i++,x+=15,x1+=115) { gotoxy(x,y); printf("%s",themeoptions[tcnt]); tcnt++; optionbox(x1,y1,tcnt); } } } void info() { int q=0,a,i=0,ig=5,aint; FILE *ifil; char sh,tfname[50],as; int x; 35 cleardevice(); displaybox(); ifil=fopen("info.dat","r"); gotoxy(10,5); while(feof(ifil)==0) { fscanf(ifil,"%c",&as); if(as=='\n') { ig++; gotoxy(10,ig); } else printf("%c",as); if(kbhit()) break; } displaybox(); fclose(ifil); a=getch(); cleardevice(); gendisplayscreen(45,370,5,1,1,fbcol); } void credit() { int q=0,a,i=0,ig=5,aint; FILE *ifil; char sh,tfname[50],as; int x; cleardevice(); displaybox(); ifil=fopen("Credit.dat","r"); gotoxy(10,5); while(feof(ifil)==0) { 36 fscanf(ifil,"%c",&as); if(as=='\n') { ig++; gotoxy(10,ig); } else printf("%c",as); if(kbhit()) break; } displaybox(); fclose(ifil); a=getch(); cleardevice(); gendisplayscreen(45,370,5,1,1,fbcol); } void memo() { cleardevice(); displaybox(); memory(); resetmouse(); cleardevice(); gendisplayscreen(45,70,5,2,2,hbcol); } /*the function printoption is for displaying the headings of each menu x and y are coordinates to outtextxy(). l is to determine the menu and cnt is counter variable to display each options*/ void printoption(x,y,l,cnt) // for printing the headings under each main categories. { setcolor(7); if(l==1) //the value l and cnt is obtained from gendisplayscreen outtextxy(x,y,options[cnt]); if(l==2) outtextxy(x,y,homeoptions[cnt]); 37 if(l==3) outtextxy(x,y,gameoptions[cnt]); if(l==5) outtextxy(x,y,themeoptions[cnt]); if(l==7) outtextxy(x,y,drawpadoption[cnt]); if(l==8) outtextxy(x,y,galleryoption[cnt]); } /*the function gendisplayscreen is used to display the options in every part of program. it calls optionbox(x,y,theme) which displays the logo of option at (x,y) it also calls printotion(x,y,l,cnt) which displays the heading of option above the logo.*/ void gendisplayscreen(initx1,inity1,totx,toty,l,col) // for displaying the headings. { int i,x1,y1,j; int gcnt=0; cleardevice(); displaybox(bcol); setcolor(col); for(j=1,y1=inity1;j<=toty;j++,y1+=105) { for(i=1,x1=initx1;i<=totx;i++,x1+=115) { printoption(x1+1,y1-15,l,gcnt); setcolor(col); gcnt++; optionbox(x1,y1,theme); } } } void drawpad() { gendisplayscreen(45,70,3,1,7,dbcol); genselection(38,48,115,105,3,1,4); 38 } void calculator() { cleardevice(); displaybox(bcol); calcula(); cleardevice(); displaybox(bcol); gendisplayscreen(45,70,5,2,2,hbcol); } void games() { gendisplayscreen(45,70,5,1,3,gbcol); genselection(38,48,115,105,5,1,5); resetmouse(); } void recorder() { gendisplayscreen(45,70,3,1,7,dbcol); genselection(38,48,115,105,3,1,6); resetmouse(); } void light() { int a,i; cleardevice(); displaybox(bcol); outtextxy(100,100,"Press any key to turn on the light"); outtextxy(100,120,"Press esc to exit"); while(a!=27) //to turn on and off the light { a=getch(); if(a==27) break; setcolor(15); for(i=35;i<=595;i++) 39 { line(i,35,i,445); } a=getch(); cleardevice(); displaybox(bcol); } cleardevice(); displaybox(bcol); gendisplayscreen(45,70,5,2,2,hbcol); } void security() { cleardevice(); displaybox(); outtextxy(100,100,"Draw new pattern"); drawpattern(2); cleardevice(); displaybox(); gendisplayscreen(45,370,5,1,1,fbcol); } void piano() { cleardevice(); displaybox(); playpiano(); cleardevice(); gendisplayscreen(45,70,5,2,2,hbcol); } void gallery() { cleardevice(); gendisplayscreen(45,70,4,1,8,2); genselection(38,48,115,105,4,1,8); } 40 void themes() { cleardevice(); displaybox(); displaythemes(); genselection(38,48,115,105,5,2,9); //the last parameter is k that is passes to call function } void wallpaper(wper,k,col) //for the live wallpaper. { int i; setcolor(col); if(wper==1) { for(i=100;i<=300;i+=20) { line(i,20+k,i,40+k); line(i+10,40+k,i+10,60+k); } } if(wper==2) { circle(rand()%300+100,rand()%150+80,rand()%5+10); } } void displaytv() //displays the outer box of live wallpaper { rectangle(40,50,460,260); rectangle(40,52,460,258); } int checkmousepos(x,y) //this function is for checking the position of mouse pointer in front screen { int i,k; if(y>=350&&y<=420) { 41 for(i=37,k=1;i<=497;i+=115,k++) { if(x>=i&&x<=i+90) return k; } } return 0; } void frontselection() // for selecting the headings from the startup screen. { int a,qq,x=37,y=350,k=0,ck=0,i,opt,keycheck=0,click=0,mposx=100,mposy=100; char achar; union REGS in,out; cleardevice(); gendisplayscreen(45,370,5,1,1,fbcol); resetmouse(); showmouse(); displaybox(bcol);// background box. selectbox(37,350,sbcol) ; abc: displaytv(); keycheck=0; click=0; do { all(); //this function displays the clock wallpaper(wper,k,rand()%10); //this function is for live wall paper delay(50); k+=1; ck++; if(ck>=50) //these lines are also for live wallpaper { ck=0; for(i=50;i<=450;i++) { 42 line(i,60,i,250); } } if(k>=400) k=0; in.x.ax=3; int86(51,&in,&out); mposx=out.x.cx; mposy=out.x.dx; opt=checkmousepos(mposx,mposy); //the function checkmousepos checks the position of mouse pointer if(opt!=0) //and returns the value according to the options in position of pointer { //and returns 0 if mouse pointer is elsewhere than the options clearbox(x,y); x=37+(opt-1)*115; selectbox(37+(opt-1)*115,350); //selectbox(x,y) draws the selecting box at (x,y) //clearbox(x,y) draws the black coloured box at (x,y) this is used to clear the previously drawn box } if(out.x.bx==1&&opt!=0) { click=1; selectbox(x,y); delay(20); keycheck=1; break; } } while(!kbhit()); if(keycheck==0) { a=getch(); clearbox(x,y); } if(a==27) exit(0); if(a==13||click==1) { 43 if(x==497) //condition for Quit { cleardevice(); printf("end"); getch(); exit(0); } resetmouse(); // displayscreen(x); if(x==37) //condition for home { cleardevice(); displaybox(); outtextxy(100,100,"Draw security pattern"); delay(500); showmouse(); //drawpattern(); if(qq=drawpattern(1)==1) { hidemouse(); cleardevice(); displaybox(); gendisplayscreen(45,70,5,2,2,hbcol); resetmouse(); showmouse(); genselection(38,48,115,105,5,2,2); //genselection generates the selection of the options required throughtout the program } else { cleardevice(); displaybox(); outtextxy(100,100,"Wrong Pattern!!"); delay(1000); gendisplayscreen(45,370,5,1,1,fbcol); } 44 } if(x==152) { info(); } if(x==382) { credit(); } if(x==267) { cleardevice(); displaybox(); outtextxy(100,100,"Draw security pattern"); delay(500); showmouse(); //drawpattern(); if(qq=drawpattern(1)==1) { hidemouse(); cleardevice(); displaybox(); outtextxy(100,100,"Change pattern(y/n)??") ; achar=getch(); resetmouse(); showmouse(); if(achar=='y'||achar=='Y') security(); } else { cleardevice(); displaybox(); outtextxy(100,100,"Wrong Pattern!!"); delay(1000); gendisplayscreen(45,370,5,1,1,fbcol); 45 } } } if(a==77&&x!=497) //this two condition is for moving the selectbox using keyboard x+=115; if(a==75&&x!=37) x-=115; selectbox(x,y,sbcol); showmouse(); goto abc; qwe: } void displayback(k) //this function is for displaying the previous screen when the user selects back { displaybox(); if(k==2) gendisplayscreen(45,370,5,1,1,fbcol); if(k>=3&&k<=10) gendisplayscreen(45,70,5,2,2,hbcol); if(k==20) gendisplayscreen(45,70,4,1,4,sscol); } /*the callfunction is to call the required functions for entering any heading selected by user. this function is called in genselection. callfunction obtains the certain values from genselection which helps to determine the required fuction*/ void callfunction(k,n) { if(k==2) //k=2 represents the home { if(n==1) //k=2 and n=1 represents the first option ie memo inside home memo(); if(n==2) //k=2 and n=2 represents the 2nd option ie drawpad inside home drawpad(); 46 if(n==3) //and so on.... calculator(); if(n==4) games(); if(n==5) recorder(); if(n==6) light(); if(n==7) piano(); if(n==8) gallery(); if(n==9) themes(); } if(k==4||k==6) //k=4 represents inside drawpad and k=6 represents inside recorder { //since the drawpad and recorder have similar options they are put in same condition if(n==1)//n=1 represents first option ie new { cleardevice(); if(k==4) newdraw(); if(k==6) newrecord(); cleardevice(); displaybox(bcol); gendisplayscreen(45,70,3,1,7,dbcol); } if(n==2) //n=2 represents second option ie load { cleardevice(); if(k==4) loaddraw(); if(k==6) loadrecord(); 47 cleardevice(); displaybox(bcol); gendisplayscreen(45,70,3,1,7,dbcol); } } if(k==5)//k=5 represents inside of the game { if(n==1) //n=1 represents the first option inside the game ie fight fight(); if(n==2) //and so on... flappy(); if(n==3) fifteen(); if(n==4) chorpolice(); cleardevice(); displaybox(bcol); gendisplayscreen(45,70,5,1,3,gbcol); } if(k==8)//k=8 represents inside the gallery { if(n==1) gimage(3); if(n==2) gimage(1); if(n==3) gimage(2); cleardevice(); displaybox(); gendisplayscreen(45,70,4,1,8,2); } if(k==10) //k=10 represents the theme { if(n==1) themes(); 48 } if(k==9) //this is invoked after selection of themes { theme=n; gotoxy(20,20); printf("Applying..."); delay(2000); frontselection(); } } /*the function gencheckmousepos is the generalised form of checkmousepos this function checks the position of mouse pointer whether the pointer is located around the options or not. this function is to check the position of mouse pointer throughout the program except at the front screen. checkmousepos is used for front screen whereas gencheckmousepos is used at other all places except front screen*/ int gencheckmousepos(x,y,initx,inity,idx,idy,totx,toty) { int i,j,k=1; if(y<=inity+toty*idy+60&&y>=inity) { for(j=inity;j<=inity+toty*idy;j+=idy) { if(y>=j&&y<=j+70) { for(i=initx;i<=initx+idx*totx+60;i+=idx,k++) { if(x>=i&&x<=i+90) return k; } } } } return 0; 49 } int posx(x) { int i; for(i=38;i<=38+4*115;i+=115) { if(x>=i&&x<=i+115) return i; } } int posy(y) { int i; for(i=48;i<=48+2*105;i+=105) { if(y>=i&&y<=i+105) return i; } } /*the function genselection generates the selecting interface that is required throughout the program. this function is responsible for selection of options throughout the program except the startup screen and selection of theme. this function moves the selectbox around the displayed options and pass the certain value to function named callfunction*/ void genselection(initx,inity,idx,idy,totx,toty,k) { int a,cn=1,i,j,x=initx,y=inity,click=0,opt=0,mposx,mposy; union REGS in,out; totx--; toty--; selectbox(initx,inity,sbcol);//for displaying red selecting box resetmouse(); showmouse(); abcd: 50 cn=1; do { in.x.ax=3 ; int86(51,&in,&out); mposx=out.x.cx; mposy=out.x.dx; opt=gencheckmousepos(mposx,mposy,initx,inity,idx,idy,totx,toty); if(opt!=0) { clearbox(x,y); x=posx(mposx); y=posy(mposy); selectbox(x,y,4); delay(30); } if(opt!=0&&out.x.bx==1) { click=1; delay(100); break; } } while(!kbhit()) ; if(click==0) { a=getch(); clearbox(x,y); } if(a==13||click==1) { if(x==initx+idx*totx&&y==inity+idy*toty) { resetmouse(); 51 displayback(k); showmouse(); goto qwert; } for(j=0;j<=toty;j++)// for knowing the heading selected by the user. { for(i=0;i<=totx;i++) { if(x==initx+i*idx&&y==inity+j*idy) { resetmouse(); callfunction(k,cn); //cn is passed according to the coordinates of the selectbox showmouse(); } cn++; } } } if(a==77&&x!=initx+totx*idx) //these four condition is for moving the selectbox with help of keyboard x+=idx; if(a==75&&x!=initx) x-=idx; if(a==72&&y!=inity) y-=idy; if(a==80&&y!=inity+toty*idy) y+=idy; selectbox(x,y,sbcol); goto abcd; qwert: } void main() { int gdriver=0,gmode; initgraph(&gdriver,&gmode,"C:\\TC\\BGI"); frontselection(); 52 cleardevice(); printf("end"); getch(); } Under memo.h #ifndef memo_h #define memo_h #endif #include<stdio.h> #include<conio.h> #include<graphics.h> #include<dos.h> void savememo() { FILE *msfil1; FILE *msfil2; FILE *msfil3; FILE *msfil4; char fname[20],inp,fn=0;; gotoxy(10,25); printf("enter name of file: "); scanf("%s",fname); strcat(fname,".dat"); msfil1=fopen("write.dat","r"); msfil2=fopen(fname,"w"); msfil3=fopen("memofile.dat","a") ; msfil4=fopen("memonum.dat","a+"); fscanf(msfil4,"%d",&fn) ; if(fn>100) fn=0; fclose(msfil4); msfil4=fopen("memonum.dat","w"); fprintf(msfil4,"%d",fn+1); fclose(msfil4); 53 while(feof(msfil1)==0) { fscanf(msfil1,"%c",&inp); fprintf(msfil2,"%c",inp); } fprintf(msfil3,"%s\n",fname); fclose(msfil1); fclose(msfil2); fclose(msfil3); gotoxy(15,23); printf("The file has been saved sucessfully"); getch(); } void memory() { char achar; int a,i=11,ln=0; FILE *mfil; mfil=fopen("write.dat","w"); rectangle(50,150,580,400); gotoxy(10,5); printf("press esc after finished"); gotoxy(10,8); printf("Type your text here"); gotoxy(10,11); while(a!=27) { achar=getch(); a=achar; if(a==13) { fprintf(mfil,"\n"); printf("\n"); i++; gotoxy(10,i); 54 } else if(a!=27) { printf("%c",achar); fprintf(mfil,"%c",achar); } if(ln=wherex()>=70) { printf("\n"); fprintf(mfil,"\n"); i++; gotoxy(10,i); } if(i==25) break; } cleardevice(); displaybox(); outtextxy(100,100,"save?(y/n)"); achar=getch(); fclose(mfil); if(achar=='Y'||achar=='y') savememo(); } void loadmemo() { FILE *mfil1; char a; mfil1=fopen("write.dat","r"); while(feof(mfil1)==0) { fscanf(mfil1,"%c",&a); printf("%c",a); } } 55 void main() { int gdriver=0,gmode; initgraph(&gdriver,&gmode,"C:\\TC\\BGI"); displaybox(); memory(); cleardevice(); getch(); loadmemo(); getch(); } Under fifteen.h #ifndef fifteen_h #define fifteen_h #endif #include <stdio.h> #include <conio.h> #include <graphics.h> int number[100][100]; void box() { setcolor(8); rectangle (200,70,410,340); rectangle(200,160,410,250); rectangle(270,70,340,340); } void initialize() { int i, j, c=1; for (i=8;i<=22;i+=6) { for(j=30;j<=46;j+=8,c++) { number[j][i]=c; 56 gotoxy(j,i); printf("%d",c); } } } void ssdisplaynumber() { int i, j, c=1; for (i=8;i<=22;i+=6) { for(j=30;j<=46;j+=8,c++) { gotoxy(j,i); printf("%d",number[j][i]); } } } int sscheck() { int i,j,sum=0,chkval=0; for (i=8;i<=22;i+=6) { for(j=30;j<=46;j+=8) { sum+=number[j][i]; } gotoxy(j,i); printf(" "); gotoxy(j,i); printf("=%d",sum); if(sum!=15) chkval=1; sum=0; 57 } sum=0; for (j=30;j<=46;j+=8) { for(i=8;i<=22;i+=6) { sum+=number[j][i]; } gotoxy(j-1,24); printf(" "); gotoxy(j-1,24); printf("=%d",sum); if(sum!=15) chkval=1; sum=0; } return chkval; } void ssselectbox(x,y,col) { setcolor(col); rectangle(x,y,x+20,y+20); } void ssmove() { char achar; int a,x=225,y=107,nx=30,ny=8,count=1,temp,tempx,tempy; ssselectbox(x,y,3); abc: achar=getch(); a=achar; ssselectbox(x,y,0); if(a==13) 58 { if(count==1) { temp=number[nx][ny]; tempx=nx; tempy=ny; count++; } else { number[tempx][tempy]=number[nx][ny]; number[nx][ny]=temp; if(sscheck()==0) { ssdisplaynumber(); gotoxy(40,25); printf("you won!!!"); goto qwe; } count=1; } } if(a==72&&y!=107) { y-=95; ny-=6; } if(a==80&&y!=297) { y+=95; ny+=6; } if(a==77&&x!=351) { x+=63; 59 nx+=8; } if(a==75&&x!=225) { x-=63; nx-=8; } if(achar==27) goto qwe; ssdisplaynumber(); ssselectbox(x,y,3); goto abc; qwe: } void fifteenrule() { outtextxy(70,100,"The sum of elements of any row or column should be equal") outtextxy(70,110,"to 15. Move the box using arrow key. Press enter to select") ; ; outtextxy(70,120,"and move the box to new position and again press enter to swap"); outtextxy(70,200,"Press esc to exit"); } void fifteen() { int gdriver=0,gmode; initgraph(&gdriver,&gmode,"C:\\TC\\BGI"); displaybox(); fifteenrule(); getch(); cleardevice(); displaybox(); box(); initialize(); ssmove(); getch(); 60 } Under fight.h #ifndef fight_h #define fight_h #endif #include<stdio.h> #include<conio.h> #include<graphics.h> void warrior1(int,int,int); void move(void); void warrior2(int,int,int); void normalshot(int,int,int,int,int,int); void displayhealthbar() { int i; for(i=0;i<=99*2;i++) { setcolor(2); line(55+i,48,55+i,55); } for(i=0;i<=99*2;i++) { setcolor(3); line(370+i,48,370+i,55); } } void healthbar2(hit) { int health=99,i; for(i=0;i<=2*hit;i++) { setcolor(0); line(370+i,48,370+i,55); } } 61 void healthbar1(hit) { int health=99,i; for(i=0;i<=2*hit;i++) { setcolor(0); line(254-i,48,254-i,55); } } void displaykeys() { outtextxy(100,400,"M: Power Arrow"); outtextxy(400,400,"W: Flesh Hook"); outtextxy(400,410,"Q: Circle of Doom"); } void powerdescribtion() { outtextxy(80,190,"Player 1:"); outtextxy(80,200,"Power arrow(M): Fires a large arrow towards enemy"); outtextxy(80,210,"The arrow is slow but can be repositioned in vertical coordinate"); outtextxy(80,220,"by pressing M again. Deals 30 damage"); outtextxy(80,250,"Player 2:"); outtextxy(80,260,"Flesh Hook[W]: Throws a fast hook which grabs and pulls the"); outtextxy(80,270,"enemy towards it. Deals 20 damage"); outtextxy(80,280,"Circle of Doom[Q]: Fires very large but slow circle which deals"); outtextxy(80,290,"large damage. Deals 40 damage"); getch(); cleardevice(); displaybox(); } void displayrules() { outtextxy(100,200,"Player 1: movement by arrows keys") ; outtextxy(100,210,"Player 2: movement keys : E=up D=down S=left F=right") ; outtextxy(100,230,"Press any key...."); 62 getch(); cleardevice(); displaybox(); } void fight() { int gdriver=0,gmode; initgraph(&gdriver,&gmode,"C:\\TC\\BGI"); displaybox(); displayrules(); powerdescribtion(); displaykeys(); warrior1(100,80,2); warrior2(530,80,3); displayhealthbar(); gotoxy(10,20); printf("Press any key to start..."); getch(); gotoxy(10,20); printf(" "); move(); getch(); } void normalshot(x,y,x1,y1,k,k1) { setcolor(2); line(x+65+k,y+40,x+85+k,y+40); setcolor(3); circle(x1-45-k1,y1+40,3); delay(4); setcolor(0); line(x+65+k,y+40,x+85+k,y+40); circle(x1-45-k1,y1+40,3); 63 } void powershot11(x,y,pk) { setcolor(4); line(x+65+pk,y+40,x+105+pk,y+40) ; line(x+65+pk,y+43,x+105+pk,y+43) ; line(x+65+pk,y+37,x+105+pk,y+37); line(x+110+pk,y+40,x+103+pk,y+30); line(x+110+pk,y+40,x+103+pk,y+50); delay(6); setcolor(0); line(x+65+pk,y+40,x+105+pk,y+40) ; line(x+65+pk,y+43,x+105+pk,y+43) ; line(x+65+pk,y+37,x+105+pk,y+37); line(x+110+pk,y+40,x+103+pk,y+30); line(x+110+pk,y+40,x+103+pk,y+50); } void powershot21(x,y,pk,ln) { setcolor(3); line(x-pk,y+20,x-30-pk,y+20); circle(x-33-pk,y+20,3); line(x-36-pk,y+20,x-49-pk,y+20); line(x-50-pk,y+20,x-50-pk,y+10); line(x-50-pk,y+10,x-60-pk,y+10); line(x-60-pk,y+10,x-60-pk,y+20); delay(6); setcolor(0); //line(x,y+20,x-30,y+20); circle(x-33-pk,y+20,3); line(x-36-pk,y+20,x-49-pk,y+20); line(x-50-pk,y+20,x-50-pk,y+10); line(x-50-pk,y+10,x-60-pk,y+10); 64 line(x-60-pk,y+10,x-60-pk,y+20); } void powershot22(x,y,pk) { setcolor(4); circle(x-100-pk,y+20,50); delay(20); setcolor(0); circle(x-100-pk,y+20,50); } void move() { char achar; int ln=1,a,x=100,power11=0,power21=0,power22=0,y=80,x1=530,y1=80,k=1,pk11=1,pk21=1,pk22=1,hit1=0,hit2=0,k1=1,chk=1,initx=0,inity=0,initx1=0,i nity1=0,init2x1,init2y1,pk21x,pk21y,i; abc: do { normalshot(x,y,x1,y1,k,k1); if(power11==1) { powershot11(initx,inity,pk11); pk11+=2; } if(power21==1) { powershot21(initx1,inity1,pk21,ln); pk21+=(12*ln); } if(power22==1) { powershot22(init2x1,init2y1,pk22); pk22+=4; } if(pk21<1) 65 { ln*=-1; power21=0; pk21=1; } if(pk21>=325) { ln*=-1; if(inity1<=y+20&&inity1>=y) { hit2+=20; pk21x=x; pk21y=y; for(i=0;i<=300;i+=6) { warrior1(pk21x+i,pk21y,4); delay(15); warrior1(pk21x+i,pk21y,0); if(power22==1) pk22+=10; } warrior1(pk21x+i,pk21y,4); delay(200); warrior1(pk21x+i,pk21y,0); warrior1(x,y,2); } } if(pk22>=325) { pk22=1; power22=0; if(init2y1>=y-40&&init2y1<=y+20) hit2+=40; } 66 if(pk11>=325) { power11=0; pk11=0; if(inity==y1) { hit1+=30; warrior2(x1,y1,4); delay(500); warrior2(x1,y1,3); } } k+=2; k1+=2; healthbar1(hit2); healthbar2(hit1); if(k>=325) { if(y>=y1-40&&y<=y1+20) hit1+=2; k=1; } if(k1>=325) { if(y1>=y-40&&y1<=y+20) hit2+=1; k1=1; } if(hit2>=99||hit1>=99) goto zxc; } while(!kbhit()); achar=getch(); 67 a=achar; warrior1(x,y,0); warrior2(x1,y1,0); if(a==72&&y!=80) y-=20; if(a==80&&y!=280) y+=20; if(a==77&&x!=140) x+=20; if(a==75&&x!=100) x-=20; if(achar=='e'&&y1!=80) y1-=20; if(achar=='d'&&y1!=280) y1+=20; if(achar=='f'&&x1!=530) x1+=20; if(achar=='s'&&x1!=490) x1-=20; if(achar=='m') { power11=1; initx=x; inity=y; } if(achar=='w') { power21=1; initx1=x1; inity1=y1; } if(achar=='q'&&power22==0) { power22=1; gotoxy(45,8); 68 printf("ULTIMATE"); delay(500); gotoxy(45,8); printf(" "); init2x1=x1; init2y1=y1; } if(a==13) goto qwe; warrior1(x,y,2); warrior2(x1,y1,3); goto abc; zxc: printf("game over"); qwe: ppp: a=getch(); if(a!=13) goto ppp; } void warrior1(x,y,col) { setcolor(col); circle(x,y,20); line(x,y+20,x,y+70); line(x,y+20,x-20,y+40); line(x,y+20,x+20,y+40); line(x,y+70,x-20,y+90); line(x,y+70,x+20,y+90); line(x-20,y+40,x+20,y+50); line(x+30,y,x+30,y+80); line(x+30,y,x+60,y+40); line(x+60,y+40,x+30,y+80); line(x+30,y+40,x+65,y+40); line(x+65,y+40,x+60,y+35); 69 line(x+65,y+40,x+60,y+45); } void warrior2(x,y,col) { setcolor(col); circle(x,y,20); line(x,y+20,x,y+70); line(x,y+20,x-20,y+40); line(x,y+20,x+20,y+40); line(x-20,y+90,x,y+70); line(x+20,y+90,x,y+70); line(x+20,y+40,x-20,y+50); circle(x-30,y+45,5); line(x-38,y+38,x-43,y+33); line(x-38,y+52,x-43,y+58); line(x-48,y+45,x-40,y+45); line(x,y+20,x-30,y+20); circle(x-33,y+20,3); line(x-36,y+20,x-49,y+20); line(x-50,y+20,x-50,y+10); line(x-50,y+10,x-60,y+10); line(x-60,y+10,x-60,y+20); } Under flappy.h #ifndef flappy_h #define flappy_h #endif #include <stdio.h> #include <conio.h> #include <graphics.h> #include <dos.h> 70 #include<stdlib.h> void boundary() { setcolor(4); line(1,90,650,90); line(1,100,650,100); line(1,400,650,400); line(1,410,650,410); } int flapcheck(y1,y) { if(y1<=y+10&&y1>=y-10) return 1; else return 0; } void object() { int a,j,i=1, x=20,y=200,c1=650,c2=95,r=3,o1=620,o2=0,o3=320,o4,qq=0; abc: do { setcolor(2); rectangle(x,y,x+20,y+20); circle(c1,c2,r); circle(c1,c2+310,r); if(o1==620) o2 = rand () % 250; if(o3==620) o4= rand()%250 ; setcolor(2); circle(o1,o2+125,5); circle(o1+10,o2+125,5); circle(o1+20,o2+125,5); circle(o3,o4+125,5); circle(o3+10,o4+125,5); circle(o3+20,o4+125,5); 71 delay(100); setcolor(0); rectangle(x,y,x+20,y+20); circle(c1,c2,r); circle(c1,c2+310,r); circle(o1,o2+125,5); circle(o1+10,o2+125,5); circle(o1+20,o2+125,5); circle(o3,o4+125,5); circle(o3+10,o4+125,5); circle(o3+20,o4+125,5); y+=20; c1-=50; o1-=10; o3-=10; if(o1<=0||o3<=0) { if(o1<=0) o1=620; if(o3<=0) o3=620; gotoxy(2,4); printf("Score:%d",i); i++; } if(c1<=0) c1=650; if (y>380||y<140) goto qwe; if(o1<=20) qq=flapcheck(o2+125,y); if(qq==1) goto qwe; } while(!kbhit()); a=getch(); if(a==72&&y<=400) y-=60; 72 if(a==27) goto qwe; goto abc; qwe: boundary(); gotoxy(20,20); printf("Game Over.......Press Esc to exit."); a=getch(); if (a!=27) goto qwe; } void flappy() { int gdriver=0,gmode; initgraph(&gdriver,&gmode,"C:\\TC\\BGI"); displaybox(); outtextxy(100,100,"Press up arrow key to fly"); outtextxy(100,110,"And avoid touching ground or the sky"); outtextxy(100,120,"Avoid the obstacle from its core"); outtextxy(100,130,"Fly fly and make the high score"); getch(); cleardevice(); boundary(); object(); } Under chorp.h #ifndef chorp_h #define chorp_h #endif #include<stdio.h> #include<conio.h> #include<graphics.h> #include<dos.h> 73 #include<process.h> void chor(x,y,col) { setcolor(col); circle(x,y,15); } int cpcheck(x,y,x1,y1) { if(x1<=x+20&&x1>=x-20&&y1<=y+20&&y1>=y-20) return 1; else return 0; } void cpmove() { int a,x=300,y=200,click=0,x1=0,y1=0,score1=0,score2=0,ck=0,dist=310; union REGS in,out; chor(x,y); while(a!=27) { do { in.x.ax=3; int86(51,&in,&out); x1=out.x.cx; y1=out.x.dx; delay(20); if(out.x.bx!=0) { hidemouse(); delay(250); ck=cpcheck(x,y,x1,y1); setcolor(0); circle(dist,50,7); if(ck==1) 74 dist-=50; if(ck==0) dist+=10; setcolor(5); if(dist<120||dist>490) { if(dist>490) outtextxy(300,300,"Chor Wins!!"); else outtextxy(300,300,"Police Wins!!"); goto asdf; } circle(dist,50,7); } showmouse(); } while(!kbhit()) ; if(click==0) a=getch(); hidemouse(); chor(x,y,0); if(a==72&&y>=100) y-=60; if(a==80&&y<=360) y+=60; if(a==75&&x>=100) x-=60; if(a==77&&x<=500) x+=60; showmouse(); chor(x,y,3); } asdf: } void cpvictorybar() { setcolor(6); rectangle(120,40,500,60); 75 setcolor(1); outtextxy(65,45,"Police"); setcolor(4); outtextxy(510,45,"Chor"); setcolor(5); circle(310,50,7); } void helpchorp() { outtextxy(100,100,"Chor move the circle with arrow key") ; outtextxy(100,110,"Police try to catch the circle with mouse"); getch(); cleardevice(); } void chorpolice() { int gdriver=0,gmode; initgraph(&gdriver,&gmode,"C:\\TC\\BGI"); displaybox(); helpchorp(); displaybox(); cpvictorybar(); showmouse(); cpmove(); getch(); } Under calcula.h #ifndef calcula_h #define calcula_h #endif #include<stdio.h> #include<conio.h> #include<math.h> #include<graphics.h> void caldisplay(int,int); 76 void calcursor(int,int); void operate(int,int); int check(int,int); int posvalue(int,int); char posoperator(int,int); float answer(void); float num[10]; int cn=1,cn1=1; char oper[10]; int v=7; void calselectbox(x,y,col) { setcolor(col); rectangle(x,y,x+50,y+20); } void calgenselection(initx,inity,idx,idy,totx,toty) { int a,cn=1,i,j,x=initx,y=inity,x1=165,y1=107; totx--; toty--; calselectbox(x1,y1,4); abcd: cn=1; a=getch(); calselectbox(x1,y1,0); if(a==13) { operate(x,y); } if(a==77&&x!=initx+totx*idx) { x+=idx; x1+=60; } if(a==75&&x!=initx) 77 { x-=idx; x1-=60; } if(a==72&&y!=inity) { y-=idy; y1-=33; } if(a==80&&y!=inity+toty*idy) { y+=idy; y1+=33; } if(a==27) goto qwert; sound(500); delay(50); nosound(); calselectbox(x1,y1,4); goto abcd; qwert: } void caldisplay(x,y) { int i; gotoxy(30,6); printf("CALCULATOR"); gotoxy(20,8); printf(" 1 2 3 + sin"); 5 6 - cos"); 8 9 * tan"); gotoxy(20,10); printf(" 4 gotoxy(20,12); printf(" 7 gotoxy(20,14); 78 printf(" ^ 0 . / ="); gotoxy(20,23); printf("Press esc to exit"); gotoxy(15,17); } void calcursor(x,y) { int a; char achar; gotoxy(25,8); abc: achar=getch(); a=achar; if(a==13) operate(x,y); if(a==72&&y!=8) y-=2; if(a==80&&y!=14) y+=2; if(a==77&&x!=53) x+=7; if(a==75&&x!=25) x-=7; if(achar=='q') goto qwe; gotoxy(x,y); goto abc; qwe: } void operate(x,y) { int z,r,b,c; float ans; z=calcheck(x,y); 79 if(z==1) { r=posvalue(x,y); gotoxy(v,15); printf("%d",r); v++; gotoxy(x,y); num[cn]=r; c=cn%2; if(cn>1&&c==0) { b=10*num[cn-1]; num[cn-1]=b+num[cn]; b=0 ; cn-=1; } else { num[cn]=r; gotoxy(23,23); } cn++; } if(z==2) { oper[cn1]=posoperator(x,y); if(oper[cn1]=='s'||oper[cn1]=='c'||oper[cn1]=='t') cn+=2; else cn+=1; gotoxy(v,15); if(oper[cn1]=='s') { printf("sin"); v+=3; 80 } else if(oper[cn1]=='c') { printf("cos"); v+=3; } else if(oper[cn1]=='t') { printf("tan"); v+=3; } else { printf("%c",oper[cn1]); v++; } cn1++; gotoxy(x,y); } if(z==5) { int i; ans=answer(); gotoxy(20,15); printf(" = %f",ans); gotoxy(24,20); printf("Press any key to continue..."); getch(); cleardevice(); gotoxy(6,4); for(i=1;i<=cn;i++) { num[i]=0; } v=7; 81 cn=1; cn1=1; caldisplay(0,0); displaybox(); calgenselection(25,8,7,2,5,4); displaybox(); } } float answer() { int i,rem,j; float ab,bc=1,cd; cd=3.14159265/180; cn=1; for(j=1;j<=cn1;j++) { if(oper[j]=='+') ab = num[cn]+num[cn+2]; if(oper[j]=='-') ab = num[cn]-num[cn+2]; if(oper[j]=='*') ab = num[cn]*num[cn+2]; if(oper[j]=='/') ab = num[cn]/num[cn+2]; if(oper[j]=='^') { for(i=0;i<num[cn+2];i++) { bc*=num[cn]; } ab=bc; } if(oper[j]=='s') ab=sin(num[cn+2]*cd); if(oper[j]=='c') 82 ab=cos(num[cn+2]*cd); if(oper[j]=='t') ab=tan(num[cn+2]*cd); num[cn+2]=ab; cn+=2; } return ab; } char posoperator(x,y) { if(x==46&&y==8) return '+'; if(x==46&&y==10) return '-'; if(x==46&&y==12) return '*'; if(x==25&&y==14) return '^'; if(x==46&&y==14) return '/'; if(x==53&&y==8) return 's'; if(x==53&&y==10) return 'c'; if(x==53&&y==12) return 't'; } int calcheck(x,y) { if(x<=39&&y<=12) return 1; if(x==32&&y==14) return 1; if(x==46) 83 return 2; if(x==53&&y!=14) return 2; if(x==25&&y==14) return 2; if(x==39&&y==14) return 4; if(x==53&&y==14) return 5; } int posvalue(x,y) { if(x==25&&y==8) return 1; if(x==32&&y==8) return 2; if(x==39&&y==8) return 3; if(x==25&&y==10) return 4; if(x==32&&y==10) return 5; if(x==39&&y==10) return 6; if(x==25&&y==12) return 7; if(x==32&&y==12) return 8; if(x==39&&y==12) return 9; if(x==32&&y==14) return 0; } void calcula() { 84 displaybox(); caldisplay(0,0); calgenselection(25,8,7,2,5,4); } Under recorder.h #ifndef recorder_h #define recorder_h #endif #include<stdio.h> #include<conio.h> #include<dos.h> #include"music.h" void saverecord() { FILE *rfil1; FILE *rfil2; FILE *rfil3; FILE *rfil4; char fname[20],fname1[20],inp; int fn=0; cleardevice(); displaybox(); gotoxy(10,25); printf("enter name of file: "); scanf("%s",fname); strcpy(fname1,fname); strcat(fname,".dat"); rfil1=fopen("recording.dat","r"); rfil2=fopen(fname,"a"); rfil3=fopen("recordfile.dat","a") ; rfil4=fopen("recordnum.dat","a+"); 85 fscanf(rfil4,"%d",&fn); if(fn>100) fn=0; fclose(rfil4); rfil4=fopen("recordnum.dat","w"); fprintf(rfil4,"%d",fn+1); fclose(rfil4); while(inp!=EOF) { inp=fgetc(rfil1); fputc(inp,rfil2); } fprintf(rfil3,"%s\n",fname1); fclose(rfil1); fclose(rfil2); fclose(rfil3); gotoxy(10,25); printf("The file has been saved sucessfully!!!"); getch(); } void newrecord() { FILE *fil; char a,asdf; int time=0; displaybox(); //displaypiano(); gotoxy(10,10); printf("press to start"); gotoxy(10,13); printf("Keys are a s d f g h j k"); getch(); gotoxy(10,16); printf("press q to stop"); fil=fopen("recording.dat","w"); 86 abc: do { delay(1); time++; } while(!kbhit()); a=getch(); if(a=='q') { cleardevice(); displaybox(); outtextxy(100,200,"Save??(y/n)"); asdf=getch(); goto qwe; } fprintf(fil,"%d",time); time=0; if(a=='a') { playnote('c',180); fprintf(fil,"%c",'c'); } if(a=='s') { playnote('d',180); fprintf(fil,"%c",'d'); } if(a=='d') { playnote('e',180); fprintf(fil,"%c",'e'); } if(a=='f') { 87 playnote('f',180); fprintf(fil,"%c",'f'); } if(a=='g') { playnote('g',180); fprintf(fil,"%c",'g'); } if(a=='h') { playnote('a',180); fprintf(fil,"%c",'a'); } if(a=='j') { playnote('b',180); fprintf(fil,"%c",'b'); } if(a=='k') { playnote('C',180); fprintf(fil,"%c",'C'); } goto abc; qwe: fclose(fil); if(asdf=='y'||asdf=='Y') saverecord(); } void loadrecord() { FILE *rfil; char note; int time=0; 88 displaybox(); gotoxy(10,20); printf("Playing..."); rfil=fopen("recording.dat","r"); while(feof(rfil)==0) { fscanf(rfil,"%d",&time); fscanf(rfil,"%c",&note); nosound(); delay(time); playnote(note,180); } fclose(rfil); } Under piano.h #ifndef piano_h #define piano_h #endif #include<dos.h> #include<conio.h> #include<stdio.h> #include<graphics.h> void displaypiano() { int i,j,x1=95,y1=200; cleardevice(); displaybox(); setcolor(7); //rectangle(100,200,500,400); for(i=1;i<=350;i++) { setcolor(7); line(x1-5,200,x1-5,400); x1++; } 89 x1=100; for(i=1;i<=7;i++) { for(j=1;j<=30;j++) { setcolor(15); line(x1,y1+5,x1,y1+195); x1++; } if(i!=8&&i!=3&&i!=7) { for(j=1;j<=20;j++) { setcolor(0); line(x1,y1+5,x1,y1+100); x1++; } } } setcolor(7) ; line(230,200,230,400); line(231,200,231,400); line(410,200,410,400); } void pianokey() { outtextxy(100,100,"For white key: asdfghjk"); outtextxy(100,110,"For black key: wetyu"); } void playpiano() { int gdriver=0,gmode,x=180,aint; char a; initgraph(&gdriver,&gmode,"C:\\TC\\BGI"); displaypiano(); 90 pianokey(); while(aint!=27) { a=getch(); aint=a; if(a=='a') playnote('c',x); if(a=='s') playnote('d',x); if(a=='d') playnote('e',x); if(a=='f') playnote('f',x); if(a=='g') { sound(392); delay(x); nosound(); } if(a=='h') { sound(440); delay(x); nosound(); } if(a=='j') { sound(493); delay(x); nosound(); } if(a=='k') { sound(523); 91 delay(x); nosound(); } if(a=='w') { sound(277); delay(200) ; nosound(); } if(a=='e') { sound(311); delay(x) ; nosound(); } if(a=='t') { sound(369); delay(x) ; nosound(); } if(a=='y') { sound(415); delay(x); nosound(); } if(a=='u') { sound(466); delay(x) ; nosound(); } } getch(); 92 } Under gimage.h #ifndef gimage_h #define gimage_h #endif #include<stdio.h> #include<conio.h> #include<graphics.h> #include<dos.h> int val=1; int filenum; void arrow() { int i,j,k,l; rectangle(190,350,260,400); rectangle(330,350,400,400); for(i=200,j=375,k=375;i<=240;i+=2,j--,k++) { line(i,j,i,k); line(i+1,j,i+1,k); } for(i=350,j=355,k=395;i<=390;i+=2,j++,k--) { line(i,j,i,k); line(i+1,j,i+1,k); } outtextxy(200,410,"Press esc to exit"); } void openfile() { int q=0,a,i=0; FILE *gfil; FILE *gfil1; FILE *gfil3; 93 char sh,tfname[50]; int x,y,size,tool=1,col; char* fname; gfil3=fopen("drawnum.dat","r"); gfil=fopen("drawfile.dat","r"); fscanf(gfil3,"%d",&filenum); fclose(gfil3); for(i=1;i<=val;i++) { fscanf(gfil,"%s",fname); } strcat(fname,".dat"); cleardevice(); displaybox(); arrow() ; setcolor(1); gfil1=fopen(fname,"r"); gotoxy(29,21); printf("%s",fname); while(tool!=0) { fscanf(gfil1,"%d%d%d%d%d",&tool,&x,&y,&size,&col); drawtool(tool,x,y,size,col); if(kbhit()) break; } displaybox(); fclose(gfil); fclose(gfil1); } void opennote() { int q=0,a,i=0,ig=5,aint; FILE *gsfil; FILE *gsfil1; 94 FILE *gsfil3; char sh,tfname[50],as; int x; char* fname; gsfil3=fopen("memonum.dat","r"); gsfil=fopen("memofile.dat","r"); fscanf(gsfil3,"%d",&filenum); fclose(gsfil3); for(i=1;i<=val;i++) { fscanf(gsfil,"%s",fname); } cleardevice(); displaybox(); arrow() ; setcolor(1); gsfil1=fopen(fname,"r"); gotoxy(29,21); printf("%s",fname); gotoxy(10,5); while(feof(gsfil1)==0) { fscanf(gsfil1,"%c",&as); if(as=='\n') { ig++; gotoxy(10,ig); } else printf("%c",as); if(kbhit()) break; } displaybox(); fclose(gsfil); fclose(gsfil1); 95 } void opensound() { int q=0,a,i=0,ig=5,aint; FILE *gssfil; FILE *gssfil1; FILE *gssfil3; char sh,tfname[50],as; char* fname; gssfil3=fopen("recordnum.dat","r"); gssfil=fopen("recordfile.dat","r"); fscanf(gssfil3,"%d",&filenum); fclose(gssfil3); for(i=1;i<=val;i++) { fscanf(gssfil,"%s",fname); } cleardevice(); displaybox(); arrow() ; setcolor(1); strcat(fname,".dat"); gssfil1=fopen(fname,"r"); gotoxy(29,21); printf("%s",fname); gotoxy(10,5); printf("Playing..."); gotoxy(10,7); printf("Press any key to stop"); while(feof(gssfil1)==0) { fscanf(gssfil1,"%d%c",&aint,&as); nosound(); delay(aint); 96 playnote(as,180); if(kbhit()) break; } displaybox(); fclose(gssfil); fclose(gssfil1); } int gcheckpos(x,y) { if(y>=350&&y<=400) { if(x>=190&&x<=260) return 1; if(x>=330&&x<=400) return 2; } return 0; } void image(k) { int a,click=0,x,y,chk; // openfile(); while(a!=27) { do { in.x.ax=3; int86(51,&in,&out); x=out.x.cx ; y=out.x.dx ; click=out.x.bx; chk=gcheckpos(x,y); if(click==1&&chk!=0) { 97 if(chk==1) val--; if(chk==2) val++; if(val>filenum) val=1; if(val==0) val=filenum; if(k==1) openfile(); if(k==2) opennote(); if(k==3) opensound(); } delay(100); } while(!kbhit()||click==1); a=getch(); click=0; } } void gimage(k) { int gdriver=0,gmode; initgraph(&gdriver,&gmode,"C:\\TC\\BGI"); resetmouse(); showmouse(); displaybox(); arrow(); if(k==1) openfile(1); if(k==2) opennote(1); if(k==3) opensound(1); image(k); } Under clock.h #ifndef clock_h #define clock_h #endif #include <stdio.h> #include <conio.h> #include <dos.h> 98 #include <graphics.h> #include<math.h> #define pi 3.141592654 void all() { int a,a1,a2,o1,x1=525,y1=100; float b; struct time t; displaybox(); setcolor(5); circle(525,100,60); setcolor(6); circle(525,100,0); gettime(&t); a=t.ti_sec; a1=t.ti_min; a2=5* t.ti_hour; b = (6*pi)/180; // clockhand(x1,y1,a,a1,a2,b); setcolor(0); line(x1,y1,(x1+(40*sin((a1-1)*b))),(y1-(40*cos((a1-1)*b)))); setcolor(8);//for minute hand. line(x1,y1,(x1+(40*sin(a1*b))),(y1-(40*cos(a1*b)))); setcolor(0); line(x1,y1,(x1+(30*sin((a2-1)*b))),(y1-(30*cos((a2-1)*b)))); setcolor(8);//for hour hand. line(x1,y1,(x1+(30*sin(a2*b))),(y1-(30*cos(a2*b)))); setcolor(0); line(x1,y1,x1+(50*sin((a-1)*b)),y1-(50*cos((a-1)*b))); setcolor(4);//for second hand. line(x1,y1,(x1+(50*sin(a*b))),(y1-(50*cos(a*b)))); } /* void main(void) { 99 int gdriver=0,gmode; initgraph(&gdriver,&gmode,"C:\\TC\\BGI"); all(); getch(); } */ Under drawpad.h #ifndef drawpad_h #define drawpad_h #endif #include<stdio.h> #include<conio.h> #include<graphics.h> #include<dos.h> void savedraw(void); void selecttoolbox(x,y,col) { setcolor(col); rectangle(x,y,x+20,y+20); } void toolbox() { int x=400,y=365; setcolor(8); rectangle(x,y,x+180,y+30); rectangle(x+30,y,x+90,y+30); rectangle(x+60,y,x+120,y+30); line(x+150,y,x+150,y+30); setcolor(7); circle(x+15,y+15,7); rectangle(x+40,y+10,x+50,y+20); line(x+70,y+15,x+80,y+15); line(x+105,y+10,x+105,y+20); line(x+130,y+10,x+140,y+20); line(x+170,y+10,x+160,y+20); 100 } void colorbox() { int i,j,k,x=300,y=400; setcolor(8); rectangle(x,y,x+270,y+30); rectangle(x+30,y,x+90,y+30); rectangle(x+60,y,x+120,y+30); rectangle(x+150,y,x+210,y+30); rectangle(x+180,y,x+240,y+30); for(i=1;i<=9;i++,x+=30) { for(j=0;j<=9;j++) { for(k=0;k<=9;k++) { putpixel(x+j+10,y+k+10,i); } } } } int selecttool(x,y) { int a,val; val=(x-405)/30; return val+1; } int selectcolor(x,y) { int a,val; val=(x-305)/30; return val+1; } void drawtool(tool,x,y,size,col) { 101 setcolor(col); if(tool==1) circle(x,y,size); if(tool==2) rectangle(x-size,y-size,x+size,y+size); if(tool==3) line(x-size,y,x+size,y); if(tool==4) line(x,y-size,x,y+size); if(tool==5) line(x-size,y-size,x+size,y+size); if(tool==6) line(x+size,y-size,x-size,y+size); } void displaykeyhelp() { gotoxy(7,23); printf("w: increase size"); gotoxy(7,24); printf("s: decrease size"); gotoxy(18,25); printf("press q to quit"); } int getmx(x,y) { int i; if(y<=395) { for(i=435;i<=585;i+=30) { if(x<=i) return i-30; } } if(y>395) 102 { for(i=335;i<=585;i+=30) { if(x<=i) return i-30; } } } int getmy(x,y) { if(y<=395) return 370; if(y>395) return 405; } void newdraw() { FILE *fil; char achar,asdf,filename[20]; int a,i,x=200,y=200,tool=1,size=10,col=3,mxpos=0,mypos=0,click=0; resetmouse(); displaybox(); showmouse(); fil=fopen("draw.dat","w"); displaykeyhelp(); colorbox(); toolbox(); abc: do { in.x.ax=3; int86(51,&in,&out); mxpos=out.x.cx; mypos=out.x.dx; if(mxpos>=290&&mypos>=350&&mxpos<=590&&mypos<=430) { click=0; 103 selecttoolbox(x,y,0); x=getmx(mxpos,mypos); y=getmy(mxpos,mypos); selecttoolbox(x,y,4); for(i=1;i<=8;i++) { selecttoolbox(x-i*30,y,0); selecttoolbox(x+i*30,y,0); } displaybox(); delay(150); if(out.x.bx==1&&y<=395) { resetmouse(); showmouse(); tool=selecttool(x,y); } if(out.x.bx==1&&y>395) { resetmouse(); showmouse(); col=selectcolor(x,y); } } if(out.x.bx==1) { click=1; x=out.x.cx; y=out.x.dx; hidemouse(); drawtool(tool,x,y,size,col); showmouse(); delay(10); fprintf(fil,"%d %d %d %d %d ",tool,x,y,size,col); } 104 } while(!kbhit()); achar=getch(); a=achar; if(achar=='w'||achar=='W') size+=2; if(achar=='s'||achar=='S') size-=2; if(achar=='q'||achar=='Q') { cleardevice(); displaybox(); outtextxy(100,400,"Save??(y/n)"); asdf=getch(); goto qwe; } goto abc; qwe: fprintf(fil,"0"); fclose(fil); if(asdf=='y') savedraw(); displaybox(); fclose(fil); } void savedraw() { FILE *fil1; FILE *fil2; FILE *fil3; FILE *fil4; char fname[20],fname1[20],inp; int inpx,inpy,inpr,fn=0; cleardevice(); displaybox(); 105 gotoxy(10,25); printf("enter name of file: "); scanf("%s",fname); strcpy(fname1,fname); strcat(fname,".dat"); fil1=fopen("draw.dat","r"); fil2=fopen(fname,"a"); fil3=fopen("drawfile.dat","a") ; fil4=fopen("drawnum.dat","a+"); fscanf(fil4,"%d",&fn); if(fn>100) fn=0; fclose(fil4); printf("%d",fn); fil4=fopen("drawnum.dat","w"); fprintf(fil4,"%d",fn+1); fclose(fil4); while(inp!=EOF) { inp=fgetc(fil1); fputc(inp,fil2); } fprintf(fil3,"%s\n",fname1); fclose(fil1); fclose(fil2); fclose(fil3); gotoxy(10,25); printf("The file has been saved sucessfully!!!"); getch(); } void loaddraw() { FILE *fil; char sh; int x,y,size,tool=1,col; displaybox(); 106 setcolor(1); fil=fopen("draw.dat","r"); while(feof(fil)==0) { fscanf(fil,"%d%d%d%d%d",&tool,&x,&y,&size,&col); drawtool(tool,x,y,size,col); } getch(); displaybox(); fclose(fil); } void drawpad() { int gdriver=0,gmode; initgraph(&gdriver,&gmode,"C:\\TC\\BGI"); showmouse(); newdraw(2); cleardevice(); getch(); loaddraw(); getch(); } Under pattern.h #ifndef pattern_h #define pattern_h #endif #include<stdio.h> #include<conio.h> #include<graphics.h> #include<dos.h> int truepat[10],patn[10]; void displaypattern() { int i,j; setcolor(3); 107 for(i=200;i<=400;i+=100) { for(j=150;j<=350;j+=100) { circle(i,j,15); } } } int pcheckmpos(x,y) { int i,j,pcnt=0; for(j=150;j<=350;j+=100) { for(i=200;i<=400;i+=100) { pcnt++; if(x>=i-15&&x<=i+15&&y>=j-15&&y<=j+15) return pcnt; } } return 0; } int px(x) { int i; for(i=200;i<=400;i+=100) { if(x<=i+15) return i; } } int py(y) { int j; for(j=150;j<=350;j+=100) { 108 if(y<=j+15) return j; } } int drawpattern(dp) { FILE *ptfil; int i,click=0,click1=0,click3=0,initx,inity,x1,y1,pmxpos,pmypos,chk,chk2=0,pp,k=0,tchk2; char achar; if(dp==2) ptfil=fopen("tpattern.dat","w"); displaybox(); displaypattern(); do { in.x.ax=3; int86(51,&in,&out); click=out.x.bx; pmxpos=out.x.cx; pmypos=out.x.dx; if(click==1&&pcheckmpos(pmxpos,pmypos)!=0) { click3=1; chk=pcheckmpos(pmxpos,pmypos); if(chk!=0&&pp!=1) { initx=px(pmxpos) ; inity=py(pmypos); pp=1; } delay(100); hidemouse(); while(1) { setcolor(0); line(initx,inity,x1,y1); 109 in.x.ax=3; int86(51,&in,&out); click1=out.x.bx; x1=out.x.cx; y1=out.x.dx; if(click1==0) break; if(kbhit()) break; setcolor(2); line(initx,inity,x1,y1); displaypattern(); delay(10); chk2=pcheckmpos(x1,y1); if(chk2!=0&&tchk2!=chk2) { setcolor(0) ; line(initx,inity,x1,y1) ; setcolor(2); line(initx,inity,px(x1),py(y1)); initx=px(x1); inity=py(y1); patn[k]=chk2; if(dp==2) fprintf(ptfil,"%d\n",chk2); k++; tchk2=chk2; } } showmouse(); if(click3==1) { if(dp==2) { cleardevice(); displaybox(); setcolor(3); outtextxy(100,100,"Pattern saved successfully!!!"); 110 achar=getch(); fclose(ptfil); return 0; } pp=checkpattern(); return pp; } } if(kbhit()) break; } while(!kbhit()); } int checkpattern() { FILE *ptfil1; int k=0,i; ptfil1=fopen("tpattern.dat","r"); while(feof(ptfil1)==0) { fscanf(ptfil1,"%d",&truepat[k]); k++; } for(i=0;i<k;i++) { if(truepat[i]!=patn[i]) { fclose(ptfil1); return 0; } } fclose(ptfil1); return 1; } /* void main() 111 { int gdriver=0,gmode; initgraph(&gdriver,&gmode,"C:\\TC\\BGI") ; displaybox(); displaypattern(); resetmouse(); showmouse(); drawpattern(); getch(); } */ Under music.h #ifndef music_h #define music_h #endif void playnote(a,x) { if(a=='c') { sound(261); delay(x); nosound(); } if(a=='d') { sound(293); delay(x); nosound(); } if(a=='e') { sound(329); delay(x); nosound(); } if(a=='f') { 112 sound(349); delay(x); nosound(); } if(a=='g') { sound(392); delay(x); nosound(); } if(a=='a') { sound(440); delay(x); nosound(); } if(a=='b') { sound(493); delay(x); nosound(); } if(a=='C') { sound(523); delay(x); nosound(); } } Under myfunc.h #ifndef myfunc_h #define mufunc_h #endif union REGS in,out; void showmouse() { in.x.ax=1; int86(51,&in,&out); } 113 void hidemouse() { in.x.ax=2; int86(51,&in,&out); } void resetmouse() { in.x.ax=0; int86(51,&in,&out); } void displaybox() { setcolor(3); rectangle(30,30,600,450); rectangle(35,35,595,445); } 114 Discussion And Conclusion We have already mentioned much of the things about this project still our words are continuously flowing. Basically from this project we got the answers for the following questions: What is the meaning of a “C- project” and the features of a good customized software? How can we built ideas on developing some useful programs? What is the power of the “C-Programming” Language? In our point of view, good softwares are the ones which are user friendly, reliable, easy to understand and use. Ideas don’t get in one’s mind in a second, it takes time and such a project definitely helps you bring up an idea to do and learn something new. ‘C’ is the backbone of programming, it has got an immense power and one can use it to build even large projects. 115 Finally we conclude that one should use all the features of ‘C’ as far as possible to make a useful project and we would also like to add that projects shouldn’t be made just only for the sake of marks, it should be made to learn new things and apply them in the respective areas. Internet is the best resource to learn about any things related to “C-programming”. Some of the references books are listed below: Learning C by Examples Let us C Secrets of C programming A Book On C The ‘C’ Programming Language We would like to end up stating that everyone in this world should learn how to program a computer and enjoy programming. 116