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

Home » C++ Home » Algorithms Home » POW_BOX (Mini Project)

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

Search Projects & Source Codes:

Title POW_BOX (Mini Project)
Author Prashant Srivastava
Author Email powdab [at] indiatimes.com
Description Just arrange box from 1-15,teasing your brain
Category C++ » Algorithms
Hits 382248
Code Select and Copy the Code
Code : #include<graphics.h> #include<conio.h> #include<malloc.h> #include<stdlib.h> #include<bios.h> #include<stdio.h> #define L 75 #define R 77 #define U 72 #define D 80 #define __LARGE__ int getboxpos(); int check_box(); void quit(void) ; int finish(void); int x,y,d,locx,locy; int tboxx[]={50,80,110,140,50,80,140,140,50,80,110,110,50,80,140}; int tboxy[]={200,200,200,200,235,235,235,270,270,270,305,270,305,305,305}; int winx[]={50,80,110,140,50,80,110,140,50,80,110,140,50,80,110}; int winy[]={200,200,200,200,235,235,235,235,270,270,270,270,305,305,305}; int Vx[]={50,50,50,50,80,80,80,80,110,110,110,110,140,140,140}; int Vy[]={200,235,270,305, 200,235,270,305, 200,235,270,305, 200,235,270}; struct BOX{ int boxx,boxy; void *box; }b[15]; int empty_x=110; int empty_y=235; int play=0; char arrange; void display(void) { cleardevice(); for(int q=0;q<15;q++) putimage(b[q].boxx,b[q].boxy,b[q].box,1); gotoxy(10,2);printf("Arrangement Range :[1 - %2d]",play); if(arrange=='h'){ gotoxy(10,3);printf("Arrangement Style :Horizontal");} else { gotoxy(10,3);printf("Arrangement Style :Vertical");} } void main(void) { char st[2]; for(int q=0;q<15;q++) b[q].boxx=b[q].boxy=NULL; int driver=DETECT,mode; int deck_color=0,no_color=0; clrscr(); dd: gotoxy(10,5); printf("Deck Color :"); scanf("%d",&deck_color); gotoxy(10,6); printf("No. Color :"); scanf("%d",&no_color); printf("Arrangement Range upto:[4,8,10,12,15]"); scanf("%d",&play); printf("Arrangement Style :[H]orizontal,[V]ertical"); arrange=getche(); if(deck_color==0 )goto dd; else if(no_color==deck_color)goto dd; if(play>15 || play<1)play=10; if(arrange!='h' && arrange!='v')arrange='h'; initgraph(&driver,&mode,""); settextstyle(1,0,1); for(int j=0;j<15;j++) { cleardevice(); setcolor(deck_color); for(int i=1;i<=25;i++) rectangle(0,0,i,i); itoa(j+1,st,10); setcolor(no_color); outtextxy(5,2,st); b[j].box= malloc(imagesize(0,0,25,25)); getimage(0,0,25,25,b[j].box); } cleardevice(); setlinestyle(SOLID_LINE,1,3); setcolor(4); rectangle(0,0,28,28); void *select= malloc(imagesize(0,0,28,28)); getimage(0,0,28,28,select); randomize(); for(q=0;q<15;q++) { aa: int s=rand()%16; if(b[s].boxx==NULL){b[s].boxx=tboxx[q]; b[s].boxy=tboxy[q]; } else goto aa; } locx=x=50;locy=y=200; display(); putimage(x,y,select,1); char ch; while(1) { int key=bioskey(2); if((key & 0x40) && (key & 0x20))quit(); int ans= finish(); gotoxy(10,24);printf("Remaining :%2d",ans); if(!ans){ getch ();quit(); } xx: ch=NULL; while(ch!=13){ ch=getch(); switch (ch) {case L:x-=30;break; case R:x+=30;break; case D:y+=35;break; case U:y-=35;break; } if(x>140)x=50;if(y>305)y=200; if(x<50)x=140;if(y<200)y=305; putimage(locx,locy,select,1); d= getboxpos(); putimage(locx,locy,select,1); } if(!check_box())goto xx; putimage(locx,locy,b[d].box,1); putimage(empty_x,empty_y,b[d].box,1); b[d].boxx=empty_x;b[d].boxy=empty_y; empty_x=locx; empty_y=locy; } } /*~~~~~~~~~~~~~~~~~~~~~Subroutines~~~~~~~~~~~~~*/ int getboxpos() { for(int a=0;a<15;a++) { if(x>=b[a].boxx && x<=b[a].boxx+25) {locx=b[a].boxx;break;} else continue; } for(a=0;a<15;a++) { if(y>=b[a].boxy && y<=b[a].boxy+25) {locy=b[a].boxy;break;} else continue; } for(a=0;a<15;a++) { if(locx==b[a].boxx && locy==b[a].boxy)return a; else continue; } return 0; } int check_box() { if(abs(locx-empty_x)==30 && abs(locy-empty_y)==0) { gotoxy(60,12); printf(" "); return 1; } else if(abs(locx-empty_x)==0 && abs(locy-empty_y)==35) { gotoxy(40,16); printf(" "); return 1; } else { gotoxy(40,16); printf("Invalid Selection."); } return 0; } void quit(void) { closegraph(); restorecrtmode(); printf(" Hoped you Enjoyed ! -Prashant Srivastava"); if(play!=15) printf(" Try arranging other ranges."); exit(0); } int finish(void) { if(arrange=='h'){ for(int t=0;t<play;t++) { if(b[t].boxx!=winx[t] || b[t].boxy!=winy[t]) return (play-t); else continue; } } else { for(int t=0;t<play;t++) { if(b[t].boxx!=Vx[t] || b[t].boxy!=Vy[t]) return (play-t); else continue; } } return 0; }

Related Source Codes

Script Name Author
Moving ball screen saver karlmarx
The Classic Game of Snake & Ladder Lakshmi Narayana .A
Railway seat reservation question which comes in sapient VyomWorld
To calculate percentile Ravi Mathur
Send to folder ANIMESH SAHU
Analog clock and calendar Nazia & Rida
HIGH/LOW GAME MOLLY ARORA
Data structure (stack Implimentation) Swapnil B Adsure
Memory Game AnirudhSanyal
Easy Calc Anirudh Sanyal
GK Quiz Anirudh Sanyal
Hangman Game Manish Jain
Snakeman Manish Jain
Full month Calendar Nigi
Cursor shapes nigi

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


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