0% found this document useful (0 votes)
4 views4 pages

No Puzzle

This document contains a C++ program for a 15-puzzle game where players can move numbered tiles to arrange them in ascending order. The game initializes a 4x4 grid with random numbers and allows movement using arrow keys. The program includes graphics for displaying the game and congratulates the player upon winning.

Uploaded by

bunty_arnab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

No Puzzle

This document contains a C++ program for a 15-puzzle game where players can move numbered tiles to arrange them in ascending order. The game initializes a 4x4 grid with random numbers and allows movement using arrow keys. The program includes graphics for displaying the game and congratulates the player upon winning.

Uploaded by

bunty_arnab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

#include<iostream.

h>
#include<conio.h>
#include<stdlib.h>
#include"dos.h"
#include<graphics.h>
#include<time.h>
#include<stdio.h>
int getkey();
void main()
{
clrscr();
int i,j,a,x,y;
//int arr[4][4]={1,4,15,7,8,10,2,11,14,3,6,13,12,9,5};
int arr[4][4];
randomize();
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
arr[i][j]=random(16);
}
}
x=3,y=3;
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:\TC\bgi");
cout<<"

W E L C O M E

T O N U M B E R G A M
E

programmed by ::

SUPRAKASH
CHATTOPADHYAY
[email protected] ";
cout<<"

Very often in fairs we come across a puzzle that


contains

15 numbered suare piecesmounted on a frame. These pieces can be moved

horizontally or vertically. A possible arrangement of these pieces is


shown
below ::<BR>;
cout<<"
";
for(i=0;i<4;i++)
{
cout<<"
";
for(j=0;j<4;j++)
{
if(i==3&&j==3)
cout<<" ";
else
cout<<arr[i][j]<<" ";
}
}
rectangle(170,260,600,295);
rectangle(170,290,600,325);
rectangle(170,320,600,355);
rectangle(170,350,600,385);
rectangle(170,260,280,385);
rectangle(280,260,430,385);
rectangle(430,260,540,385);
cout<<"
As you can see there is a blank right corner, Use ARROWS KEYS
to
move the blank so that rest numbers get arranged in ASCENDING
ORDER.

UP ARROW :: MOVE UP DOWN ARROW :: MOVE DOWN


LEFT ARROW ::
MOVE
LEFT RIGHT ARROW :: MOVE RIGHT<BR>;
setbkcolor(4);
getch();
closegraph();
restorecrtmode();
clrscr();
cout<<"

W E L C O M E
T O
N U M B E R
G
A M E

programmed by ::

SUPRAKASH
CHATTOPADHYAY
[email protected] ";
cout<<"

Let's play now , Use ARROW KEYS .................<BR>;


do
{

cout<<"
";
for(i=0;i<4;i++)
{
cout<<"
";
for(j=0;j<4;j++)
{
if(i==x&&j==y)
cout<<" ";
else
cout<<arr[i][j]<<" ";
}
}
if(x==3&&y==3&&arr[0][0]==1&&arr[0][1]==2&&arr[0][2]==3&&arr[0][3]==4&&arr
[1][0]==5&&arr[1][1]==6&&arr[1][2]==7&&arr[1][3]==8&&arr[2][0]==9&&arr[2][
1]==10&&arr[2][2]==11&&arr[2][3]==12&&arr[3][0]==13&&arr[3][1]==14&&arr[3]
[2]==15)
{ cout<<"

U R THE WINNER...........CONGRATS.....

THANKS FOR PLAYING !!!!";delay(3000);getch(); exit(1); }

cout<<"

Press any other key to exit................THANKS";


a=getkey();
{
if(a==72)
{
if(x!=0)
{ arr[x][y]=arr[x-1][y]; x=x-1; }
else
cout<<" wrong input";
}
if(a==75)
{
if(y!=0)
{ arr[x][y]=arr[x][y-1];y=y-1; }
else
cout<<" wrong input";
}
if(a==77)
{
if(y<3)
{ arr[x][y]=arr[x][y+1];y=y+1; }
else
cout<<" wrong input";
}
if(a==80)
{
if(x<3)
{ arr[x][y]=arr[x+1][y];x=x+1; }
else
cout<<" wrong input";
}

}
clrscr();
}while(a==72||a==75||a==77|a==80);

int getkey()
{
union REGS i,o;
while(!kbhit())
;
i.h.ah=0;
int86(22,&i,&o);
return(o.h.ah);
}

You might also like