Help:Add an entry
From source code,code examples
There are several ways to contribute your code or articles. These can vary based on the type of page started, as well as the wiki and namespace.
Using Wikilinks
MediaWiki makes it very easy to link wiki pages using a standard syntax . If you (or anyone else) creates a link to an article that doesn't exist yet, the link will be coloured red, like this.
Clicking a red link, will take you to the edit page for the new article. Simply type your text, click save and the new page will be created.
Once the page has been created, the link will change from red to blue (purple for pages you've visited) indicating that the article now exists.
Usually this is the best way to create a new page, because it means that right from the start, the page will be linked from at least one other place on the wiki (and typically you will want to mesh it into other related pages later) If you are creating a new page without creating any link to it, you may need to ask yourself: Does this page really fit in with the topics already covered in the wiki? Also, how are you expecting visitors to find this page? Normally there is no reason to create a page without first creating a red link to it.
Here is the source code for the game of Tower Of Hanoi
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<iostream.h>
#include<process.h>
#include<dos.h>
#define xlt 6.5
#define xrt 19.5
#define ylo 4
#define yup 12
#define ms 10
int select,choice,no=0;
int pgcntr =0;
void ProgressBar(int );
void Game();
void txtmsg();
void txtmsg2();
void selectoption();
void checkkey();
void colorChnge();
void startup();
void paintScreen();
void ScrollText();
void showMenu();
void History();
void mainScreen();
void drwbox();
void Move1to2();
void Move2to1();
void Move2to3();
void Move3to2();
void movedisc();
void playGame();
void drwTower1();
void drwTower2();
void drwTower3();
void Move1to3();
void Move3to1();
void getxyoft1(int );
void getxyoft2(int );
void getxyoft3(int );
void check();
void printTowerChoice(int) ;
void selectTowerFrom();
void selectTowerTo();
void Instructions();
int t1x1c,t1y1c,t1x2c,t1y2c, t2x1c,t2y1c,t2x2c,t2y2c,t3x1c,t3y1c,t3x2c,t3y2c;
int t1[5]={0,0,0,0,0},t2[5]={0,0,0,0,0},t3[5]={0,0,0,0,0};
int t1p,t2p=0,t3p=0,tsf=0,tst=0,ok,t3cntr=0,tempy1,tempy2,tempy3,t1y1,t1y2,t2y1,t2y2,t3y1,t3y2;
int d0y1t1=334,d0y2t1=359,d1y1t1=309,d1y2t1=334,d2y1t1=284,d2y2t1=309,d3y1t1=259,d3y2t1=284;
int d0y1t2=334,d0y2t2=359,d1y1t2=309,d1y2t2=334,d2y1t2=284,d2y2t2=309,d3y1t2=259,d3y2t2=284;
int d0y1t3=334,d0y2t3=359,d1y1t3=309,d1y2t3=334,d2y1t3=284,d2y2t3=309,d3y1t3=259,d3y2t3=284;
void main()
{ int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc\\bgi");
startup();
delay(2000);
cleardevice();
// paintScreen();
delay(1000);
cleardevice();
mainScreen();
ScrollText();
cleardevice();
showMenu();
// rectangle(190,390,440,400);
getch();
}
void startup()
{
delay(2000);
setcolor(4);
rectangle(10,10,320,220);
delay(50);
//setcolor(RED);
///setfillstyle(1,4);
rectangle(330,10,630,220);
delay(50);
rectangle(330,230,630,440);
delay(50);
rectangle(10,230,320,440);
delay(200);
int b1x=10,b1y=10,b2x=320,b2y=220,c1x=330,c1y=10,c2x=630,c2y=220,d1x=10,d1y=230,d2x=320,d2y=440,e1x=330,e1y=230,e2x=630,e2y=440;
for (int i=1;i<=20;i++)
{
cleardevice();
//setbkcolor(BLACK);
b1x =b1x+xlt;
b2x = b2x -xlt;
b1y = b1y +ylo;
b2y =b2y -ylo;
c1x =c1x+xlt;
c2x = c2x -xlt;
c1y = c1y +ylo;
c2y =c2y -ylo;
d1x =d1x+xlt;
d2x = d2x -xlt;
d1y = d1y +ylo;
d2y =d2y -ylo;
e1x =e1x+xlt;
e2x = e2x -xlt;
e1y = e1y +ylo;
e2y =e2y -ylo;
/* setcolor(RED);
rectangle(b1x,b1y,b2x,b2y);
//setcolor(RED);
setfillstyle(1,4);
rectangle(c1x,c1y,c2x,c2y);
rectangle(d1x,d1y,d2x,d2y);
rectangle(e1x,e1y,e2x,e2y);
delay(30);
cleardevice(); */
//setbkcolor(0);
b1x = b1x -xlt;
b2x = b2x -xlt;
b1y = b1y +yup;
b2y = b2y +yup;
c1x = c1x -xrt;
c2x = c2x -xrt;
c1y = c1y +yup;
c2y = c2y +yup;
d1x = d1x -xlt;
d2x = d2x -xlt;
d1y = d1y +ylo;
d2y = d2y +ylo;
e1x = e1x -xrt;
e2x = e2x -xrt;
e1y = e1y +ylo;
e2y = e2y +ylo;
if(i==20)
{
setcolor(WHITE);
}
else
{
setcolor(RED);
}
rectangle(b1x,b1y,b2x,b2y);
//setcolor(RED);
setfillstyle(1,4);
rectangle(c1x,c1y,c2x,c2y);
rectangle(d1x,d1y,d2x,d2y);
rectangle(e1x,e1y,e2x,e2y);
delay(30);
}
delay(50);
// setfillstyle(1,15);
floodfill(b1x+(int)(b2x-b1x)/2,b1y+(int)(b2y-b1y)/2,15);
delay(50);
floodfill(70,355,15);
delay(50);
floodfill(70,415,15);
delay(50);
floodfill(20,415,15);
settextstyle(3,0,5);
floodfill(20,415,15);
txtmsg2();
setcolor(WHITE);
line( 120,430,600,430);
for(i=0;i<=20;i++)
{
circle(120+(24*i),430,2);
line(120,431,120+24*i,431);
delay(50);
}
}
void paintScreen()
{
setcolor(4);
setfillstyle(1,4);
rectangle(0,135,220,335); //2
floodfill(110,235,4);
delay(ms);
rectangle(0,50,50,135); //3
floodfill(25,92,4);
delay(ms);
rectangle(50,185,150,235); //4
floodfill(100,210,4);
delay(ms);
rectangle(0,0,100,50); //5
floodfill(50,25,4);
delay(ms);
rectangle(0,185,50,285); //6
floodfill(25,235,4);
delay(ms);
rectangle(50,50,100,135); //7
floodfill(75,92,4);
delay(ms);
rectangle(100,0,180,80); //8
floodfill(140,40,4);
delay(ms);
rectangle(100,235,150,335); //9
floodfill(125,285,4);
delay(ms);
rectangle(100,80,180,135); //10
floodfill(150,107,4);
delay(ms);
rectangle(50,235,100,335); //11
floodfill(75,285,4);
delay(ms);
rectangle(180,0,260,50); //12
floodfill(220,25,4);
delay(ms);
rectangle(180,50,200,135); //13
floodfill(190,92,4);
delay(ms);
rectangle(0,285,50,440); //14
floodfill(25,362,4);
delay(ms);
rectangle(50,390,100,440); //15
floodfill(75,415,4);
delay(ms);
/*rectangle(0,200,150,440);
floodfill(75,320,4);
delay(ms); */
rectangle(200,100,330,135); //16
floodfill(265,117,4);
delay(ms);
rectangle(50,335,100,390); //17
floodfill(75,362,4);
delay(ms);
rectangle(200,50,415,100); //18
floodfill(307,75,4);
delay(ms);
rectangle(170,335,250,350); //19
floodfill(210,342,4);
delay(ms);
rectangle(260,0,500,70); //20
floodfill(380,35,4);
delay(ms);
rectangle(100,335,300,440); //21
floodfill(200,387,4);
delay(ms);
rectangle(300,50,550,135); //22
floodfill(442,92,4);
delay(ms);
rectangle(500,0,630,67); //23
floodfill(565,33,4);
delay(ms);
rectangle(300,335,335,370); //24
floodfill(317,352,4);
delay(ms);
rectangle(500,67,630,250); //25
floodfill(590,133,4);
delay(ms);
rectangle(300,370,370,440); //26
floodfill(335,405,4);
delay(ms);
rectangle(500,135,630,250); //27
floodfill(565,192,4);
delay(ms);
rectangle(335,335,400,370);
floodfill(367,352,4); //28
delay(ms);
rectangle(500,250,570,320);
floodfill(535,285,4); //29
delay(ms);
rectangle(570,250,630,390); //30
floodfill(600,320,4);
delay(ms);
rectangle(370,335,450,440); //31
floodfill(410,387,4);
delay(ms);
rectangle(570,390,630,440); //32
floodfill(600,415,4);
delay(ms);
rectangle(500,320,570,390); //33
floodfill(535,355,4);
delay(ms);
rectangle(335,335,570,415); //34
floodfill(452,375,4);
delay(ms);
rectangle(335,415,570,440); //35
floodfill(452,427,4);
delay(ms);
}
void mainScreen()
{
/*Drw borders on each corners*/
setcolor(WHITE);
line(10,10,50,10);
line(10,10,10,50);
line(0,430,50,430);
line(0,430,0,380);
line(630,10,580,10);
line(630,10,630,50);
line(630,430,580,430);
line(630,430,630,380);
setcolor(7);
line(10,110,10,330);
line(110,10,530,10);
line(630,110,630,330);
line(110,430,530,430);
setcolor(4);
delay(1000);
setfillstyle(1,4);
rectangle(190,50,273,87); //0
floodfill(231,68,4);
delay(ms);
rectangle(273,50,356,87); //1
floodfill(314,68,4);
delay(ms);
rectangle(190,87,273,124); //2
floodfill(231,105,4);
delay(ms);
rectangle(273,87,356,124); //3
floodfill(314,105,4);
delay(ms);
rectangle(190,124,273,161); //4
floodfill(231,142,4);
delay(ms);
rectangle(356,50,440,87); //5
floodfill(398,68,4);
delay(ms);
rectangle(273,124,356,161); //6
floodfill(314,142,4);
delay(ms);
rectangle(356,87,440,124); //7
floodfill(398,105,4);
delay(ms);
rectangle(190,161,273,198); //8
floodfill(231,179,4);
delay(ms);
rectangle(273,161,356,198); //9
floodfill(314,179,4);
delay(ms);
rectangle(356,124,440,161); //10
floodfill(398,142,4);
delay(ms);
rectangle(356,161,440,198); //11
floodfill(398,179,4);
delay(ms);
//textcolor(15);
setcolor(15);
settextstyle(1,0,3);
delay(30);
txtmsg();
drwbox();
delay(30);
drwbox();
// delay(30);
// drwbox();
}
void drwbox()
{
setcolor(7);
for(int i=0;i<8;i++)
{
line(220,70,220+(i*13),70);
line(220,70,220,70+(i*8));
line(220,180,220+(i*13),180);
line(220,180,220,180-(i*7));
line(400,70,400-(i*12),70);
line(400,70,400,70+(i*8));
line(400,180,400,180-(i*7));
line(400,180,400-(i*12),180);
delay(70);
}
setcolor(WHITE);
for(i=0;i<8;i++)
{
line(220,70,220+(i*13),70);
line(220,70,220,70+(i*8));
line(220,180,220+(i*13),180);
line(220,180,220,180-(i*7));
line(400,70,400-(i*12),70);
line(400,70,400,70+(i*8));
line(400,180,400,180-(i*7));
line(400,180,400-(i*12),180);
delay(70);
}
}
void ScrollText()
{
pgcntr =1;
char str[9][30]={"+++THE TOWER OF HANOI+++","Developed By:","_____PANCHAL RAJAN_____","Year:3rd Roll No:6126","Semester:5","C.K.Pithwalla College of","Engg. & Technology,Surat","panchal.rajan@gmail.com "};
//initgraph(&gd,&gm,"c:\\tc\\bgi");
setcolor(15);
line(250,249,380,249);
line(250,326,380,326);
setcolor(7);
line(220,250,410,250);
line(220,325,410,325);
//gotoxy(230*0.125,307*0.068);
//clrscr();
rectangle(190,390,440,400);
settextstyle(0,0,1);
setcolor(WHITE);
outtextxy(190,380,"Loading..Please Wait!");
delay(500);
setcolor(RED);
int y = 325;
for(int i =1;i<5;i++)
{
y=325;
y = y-(18*i);
for(int k =0;k<i;k++)
{
gotoxy(235*0.125,y*0.068) ;
int j =0;
while(str[k][j]!='\0')
{
cout<<str[k][j];
j++;
}
y = y+(18);
}
delay(200);
drwbox();
ProgressBar(pgcntr);
y=325; /*Loop for ersing the content*/
y = y-(18*i);
for(int kj =0;kj<i;kj++)
{
gotoxy(235*0.125,y*0.068) ;
// int jk =0;
//while(jk!=30)
{
cout<<" ";
// jk++;
}
// cout<<endl;
// delay(1000);
y = y+(18);
}
y = 325;
pgcntr++;
}
//cout<<str[1][i];
y = 271;
int strt =1;int ed = 4;
for(i=1;i<8;i++)
{
y=271;
y=y-18;
for(int k = strt;k<=ed;k++)
{
gotoxy(235*0.125,y*0.068);
int j=0;
while(str[k][j]!='\0')
{
cout<<str[k][j];
j++ ;
}
y=y+18;
// delay(1000);
}
delay(200);
drwbox();
ProgressBar(pgcntr);
/*LOOP for ersing the lines*/
// y = 271;
y=271;
y=y-18;
for(int jk = 1; jk<5;jk++)
{
gotoxy(235*0.125,y*0.068);
// int j=0;
//while(str[k][j]!='\0')
//{
cout<<" ";
// j++ ;
//}
y=y+18;
}
strt++;
ed++;
if(ed>7)
{
ed--;
}
pgcntr++;
}
}
void ProgressBar(int pgcntr)
{
if(pgcntr<11)
{
setcolor(RED) ;
line(191,391,191+(pgcntr*24.8),391);
line(191,392,191+(pgcntr*24.8),392);
line(191,393,191+(pgcntr*24.8),393);
line(191,394,191+(pgcntr*24.8),394);
line(191,395,191+(pgcntr*24.8),395);
line(191,396,191+(pgcntr*24.8),396);
line(191,397,191+(pgcntr*24.8),397);
line(191,398,191+(pgcntr*24.8),398) ;
line(191,399,191+(pgcntr*24.8),399);
}
}
void showMenu()
{
delay(500);
setcolor(RED);
setfillstyle(1,4);
rectangle(150,135,500,335); //0
floodfill(320,235,4);
setcolor(7);
settextstyle(0,0,1);
outtextxy(280,185,"NEW GAME");
outtextxy(280,215,"INSTRUCTIONS");
outtextxy(280,245,"HISTORY");
outtextxy(280,275,"EXIT");
//selectoption();
// getch();
setcolor(4);
delay(500);
setfillstyle(1,4);
rectangle(150,135,500,335); //0
floodfill(320,235,4);
selectoption();
}
void selectoption()
{
select = 0;
select = getch();
checkkey();
}
void checkkey()
{
if(select ==80)
{
no++;
if(no>4)
{
no =4;
}
colorChnge();
selectoption();
}
else if(select ==72)
{
no--;
if(no<1)
{
no=1;
}
select =0;
colorChnge();
selectoption();
}
else if(select ==13)
{
switch(no)
{
case 1:
{
paintScreen();
delay(500);
no=0;
cleardevice();
Game();
// cout<<"NEW GME SELECTED";
break;
}
case 2:
{
paintScreen();
delay(500);
no=-2;
Instructions();
// cout<<"HISTORY selected";
break;
}
case 3:
{
paintScreen();
delay(500);
History();
no=0;
// cout<<"INSTRUCTIONS SELECTED";
break;
}
case 4:
{
paintScreen();
delay(500);
no=0;
exit(0);
break;
default:
no=-2;
selectoption();
}
}
}
else
{
selectoption();
}
// delay(1000);
}
void colorChnge()
{
switch(no)
{
case 1:
{
setcolor(WHITE);
outtextxy(280,185,"NEW GAME");
setcolor(7);
outtextxy(280,215,"INSTRUCTIONS");
outtextxy(280,245,"HISTORY");
outtextxy(280,275,"EXIT");
break;
}
case 2:
{
setcolor(WHITE);
outtextxy(280,215,"INSTRUCTIONS");
setcolor(7);
outtextxy(280,185,"NEW GAME");
outtextxy(280,245,"HISTORY");
outtextxy(280,275,"EXIT");
break;
}
case 3:
{
setcolor(WHITE);
outtextxy(280,245,"HISTORY");
setcolor(7);
outtextxy(280,185,"NEW GAME");
outtextxy(280,215,"INSTRUCTIONS");
outtextxy(280,275,"EXIT");
break;
}
case 4:
{
setcolor(WHITE);
outtextxy(280,275,"EXIT");
setcolor(7);
outtextxy(280,185,"NEW GAME");
outtextxy(280,215,"INSTRUCTIONS");
outtextxy(280,245,"HISTORY");
break;
}
}
}
void History()
{
cleardevice();
setcolor(4);;
setfillstyle(1,4);
//rectangle(115,100,515,350);
//floodfill(315,225,4);
setcolor(15);
outtextxy(280,120,"HISTORY");
gotoxy(120*0.125,150*0.068);
cout<<"The Tower of Hanoi was invented by the French mathematician, Edouard Lucas, in 1883.";
cout<<"He was inspired by a legend that tells of a Hindu temple where the pyramid puzzle might have been used for the mental discipline of young priests. Legend says that at the beginning of time the priests in the temple were given a stack of 64 gold disks, each one a little smaller than the one beneath it. Their assignment was to transfer the 64 disks from one of the three poles to another, with one important proviso that disk could never be placed on top of a smaller one. The priests worked very efficiently, day and night. When they finished their work, the myth said, the temple would crumble into dust and the world would vanish.";
outtextxy(170,350,"Press Enter to return to menu");
getch();
cleardevice();
showMenu();
}
void Game()
{
setcolor(WHITE);
line(10,10,50,10);
line(10,10,10,50);
delay(100);
line(0,460,50,460);
line(0,460,0,410);
delay(100);
line(630,10,580,10);
line(630,10,630,50);
delay(100);
line(630,460,580,460);
line(630,460,630,410);
//__________________________________________________________
setcolor(8);
rectangle(125,360,490,440);
setfillstyle(1,8);
floodfill(307,400,8);
setcolor(15);
rectangle(157,380,457,420);
setcolor(4);
setfillstyle(1,4);
floodfill(307,400,15);
setcolor(15);
setcolor(7);
setfillstyle(1,7);
rectangle(180,180,205,360); /*Tower one*/
floodfill(192,260,7);
rectangle(295,180,320,360); // tower two
floodfill(307,260,7);
rectangle(410,180,435,360); //tower three
floodfill(422,260,7);
setcolor(15);
rectangle(142,335,242,359); //disc 0
setfillstyle(1,4) ;
floodfill(191,347,15);
rectangle(147,310,237,334); //disc1
floodfill(192,322,15);
rectangle(152,285,232,309); //disc 2
floodfill(192,297,15);
rectangle(157,260,227,284);
floodfill(192,272,15); //disc 3;
setcolor(WHITE);
outtextxy(180,450,"To Exit anytime press BACKSPACE");
rectangle(125,10,490,90);
setfillstyle(2,4);
floodfill(307,55,15);
settextstyle(0,0,3);
outtextxy(200,15,"THE TOWER");
outtextxy(290,40,"OF");
outtextxy(255,65,"HANOI");
settextstyle(0,0,1);
t1x1c = 142,t1y1c=335,t1x2c = 242,t1y2c =359;
t2x1c =257 ,t2y1c=359,t2x2c = 357,t2y2c =384;
t3x1c = 372,t3y1c=359,t3x2c = 472,t3y2c =384;
tempy1=t1y1c,tempy2=t2y1c,tempy3=t3y1c;
for(int i =0;i<=4;i++)
{
t1[i] = i;
}
t1p = 4;
playGame();
}
void movedisc()
{
int t1pc,t2pc,t3pc;
t1pc = t1p,t2pc =t2p,t3pc =t3p;
if(tsf ==49 && tst ==50)
{ //move from 1 to 2
if(t1[t1p]<t2[t2p])
{
setcolor(4);
outtextxy(200,400,"脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹");
setcolor(15);
outtextxy(180,400," Invalid move!") ;
delay(1500);
playGame();
}
else if(t1[t1p]>t2[t2p])
{
t2p = t2p+1;
getxyoft1(t1[t1pc]);
t2[t2p] = t1[t1p];
getxyoft2(t1[t1pc]);
t2y2c =tempy2-1; /*problem here*/
t2y1c = tempy2-25;
tempy2 = t2y1c;
if(t1[t1p]==4)
{
d3y1t2 = t2y1c;
d3y2t2 =t2y2c;
}
if (t1[t1p]==3)
{
d2y1t2 = t2y1c;
d2y2t2 =t2y2c;
}
if(t1[t1p]==2)
{
d1y1t2 = t2y1c;
d1y2t2 =t2y2c;
}
if(t1[t1p]==1)
{
d0y1t2 = t2y1c;
d0y2t2 =t2y2c;
}
t1[t1p]=0;
t1p = t1p-1;
Move1to2();
t1y1c =t1y1c+25 ;
t1y2c= t1y2c+25;
tempy1= t1y1c;
}
}//END OFMOVE 1 to2
else if(tsf ==49 && tst ==51)
{
//move from 1 to 3
if(t1[t1p]<t3[t3p])
{
setcolor(4);
outtextxy(200,400,"脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹");
setcolor(15);
outtextxy(180,400," Invalid move!") ;
delay(1500);
playGame();
}
else if(t1[t1p]>t3[t3p])
{
//move from 1 to3
t3p = t3p+1;
getxyoft1(t1[t1pc]);
t3[t3p] = t1[t1p];
t3cntr=t3cntr+1;
getxyoft3(t1[t1pc]);
t3y2c =tempy3-1;;
t3y1c = tempy3-25;
tempy3 = t3y1c;
if(t1[t1p]==4)
{
d3y1t3 = t3y1c;
d3y2t3 =t3y2c;
}
if (t1[t1p]==3)
{
d2y1t3 = t3y1c;
d2y2t3 =t3y2c;
}
if(t1[t1p]==2)
{
d1y1t3 = t3y1c;
d1y2t3 =t3y2c;
}
if(t1[t1p]==1)
{
d0y1t3 = t3y1c;
d0y2t3 =t3y2c;
}
t1[t1p]=0;
t1p = t1p-1;
Move1to3();
t1y1c =t1y1c+25 ;
t1y2c= t1y2c+25;
tempy1= t1y1c;
}
}
else if(tsf == 50 && tst ==49)
{
//move from 2 to1
if(t2[t2p]<t1[t1p])
{
setcolor(4);
outtextxy(200,400,"脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹");
setcolor(15);
outtextxy(180,400," Invalid move!") ;
delay(1500);
playGame();
}
else if(t2[t2p]>t1[t1p])
{
//move from 2 to1
t1p = t1p+1;
getxyoft2(t2[t2pc]);
t1[t1p] = t2[t2p];
getxyoft1(t2[t2pc]);
t1y2c =tempy1-1; /*problem here*/
t1y1c = tempy1-25;
tempy1 = t1y1c;
if(t2[t2p]==4)
{
d3y1t1 = t1y1c;
d3y2t1 =t1y2c;
}
if (t2[t2p]==3)
{
d2y1t1 = t1y1c;
d2y2t1 =t1y2c;
}
if(t2[t2p]==2)
{
d1y1t1 = t1y1c;
d1y2t1 =t1y2c;
}
if(t2[t2p]==1)
{
d0y1t1 = t1y1c;
d0y2t1 =t1y2c;
}
t2[t2p]=0;
t2p = t2p-1;
Move2to1();
t2y1c =t2y1c+25 ;
t2y2c= t2y2c+25;
tempy2= t2y1c;
}
}
else if(tsf ==50 && tst ==51)
{
//move 2 to 3
if(t2[t2p]<t3[t3p])
{
setcolor(4);
outtextxy(200,400,"脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹");
setcolor(15);
outtextxy(180,400," Invalid move!") ;
delay(1500);
playGame();
}
else if(t2[t2p]>=t3[t3p])
{
//move from 2 to3
t3p = t3p+1;
getxyoft2(t2[t2pc]);
t3[t3p] = t2[t2p];
t3cntr=t3cntr+1;
getxyoft3(t2[t2pc]);
t3y2c =tempy3-1;
t3y1c = tempy3-25;
tempy3 = t3y1c;
if(t2[t2p]==4)
{
d3y1t3 = t3y1c;
d3y2t3 =t3y2c;
}
if (t2[t2p]==3)
{
d2y1t3 = t3y1c;
d2y2t3 =t3y2c;
}
if(t2[t2p]==2)
{
d1y1t3 = t3y1c;
d1y2t3 =t3y2c;
}
if(t2[t2p]==1)
{
d0y1t3 = t3y1c;
d0y2t3 =t3y2c;
}
t2[t2p]=0;
t2p = t2p-1;
Move2to3();
t2y1c =t2y1c+25 ;
t2y2c= t2y2c+25;
tempy2= t2y1c;
}
}
else if(tsf ==51 && tst ==49)
{
//move from 3 to1
if(t3[t3p]<t1[t1p])
{
setcolor(4);
outtextxy(200,400,"脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹");
setcolor(15);
outtextxy(180,400," Invalid move!") ;
delay(1500);
playGame();
}
else if(t3[t3p]>t1[t1p])
{
//move from3 to1
t1p = t1p+1;
getxyoft3(t3[t3pc]);
t1[t1p] = t3[t3p];
t3cntr=t3cntr-1;
getxyoft1(t3[t3pc]);
t1y2c =tempy1-1;
t1y1c = tempy1-25;
tempy1 = t1y1c;
if(t3[t3p]==4)
{
d3y1t1 = t1y1c;
d3y2t1 =t1y2c;
}
if (t3[t3p]==3)
{
d2y1t1 = t1y1c;
d2y2t1=t1y2c;
}
if(t3[t3p]==2)
{
d1y1t1 = t1y1c;
d1y2t1 =t1y2c;
}
if(t3[t3p]==1)
{
d0y1t1 = t1y1c;
d0y2t1 =t1y2c;
}
t3[t3p]=0;
t3p = t3p-1;
Move3to1();
t3y1c =t3y1c+25 ;
t3y2c= t3y2c+25;
tempy3= t3y1c;
}
}
else if(tsf ==51 && tst ==50)
{
//move from 3 to2
if(t3[t3p]<t2[t2p])
{
setcolor(4);
outtextxy(200,400,"脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹");
setcolor(15);
outtextxy(180,400," Invalid move!") ;
delay(1500);
playGame();
}
else if(t3[t3p]>t2[t2p])
{
t2p = t2p+1;
getxyoft3(t3[t3pc]);
t2[t2p] = t3[t3p];
t3cntr=t3cntr-1;
getxyoft2(t3[t3pc]);
t2y2c =tempy2-1;
t2y1c = tempy2-25;
tempy2 = t2y1c;
if(t3[t3p]==4)
{
d3y1t2 = t2y1c;
d3y2t2 =t2y2c;
}
if (t3[t3p]==3)
{
d2y1t2 = t2y1c;
d2y2t2 =t2y2c;
}
if(t3[t3p]==2)
{
d1y1t2 = t2y1c;
d1y2t2 =t2y2c;
}
if(t3[t3p]==1)
{
d0y1t2 = t2y1c;
d0y2t2 =t2y2c;
}
t3[t3p]=0;
t3p = t3p-1;
Move3to2();
t3y1c =t3y1c+25 ;
t3y2c= t3y2c+25;
tempy3= t3y1c;
}
}
}
void Move3to1()
{
/*Erase disc from 1st tower*/
setcolor(BLACK);
rectangle(t3x1c,t3y1c,t3x2c,t3y2c);
setfillstyle(1,0);
setcolor(0);
floodfill(t3x1c+(t3x2c-t3x1c)/2,t3y1c+(t3y2c-t3y1c)/2,0);
/*Drw tower 1 again*/
drwTower3();
/*Draw Disc at tower 3*/
setcolor(15);
rectangle(t1x1c,t1y1c,t1x2c,t1y2c);
setcolor(4);
setfillstyle(1,4) ;
floodfill(t1x1c+(t1x2c-t1x1c)/2,t1y1c+(t1y2c-t1y1c)/2,15);
}
void Move1to3()
{
/*Erase disc from 1st tower*/
setcolor(BLACK);
rectangle(t1x1c,t1y1c,t1x2c,t1y2c);
setfillstyle(1,0);
setcolor(0);
floodfill(t1x1c+(t1x2c-t1x1c)/2,t1y1c+(t1y2c-t1y1c)/2,0);
/*Drw tower 1 again*/
drwTower1();
/*Draw Disc at tower 3*/
setcolor(15);
rectangle(t3x1c,t3y1c,t3x2c,t3y2c);
setcolor(4);
setfillstyle(1,4) ;
floodfill(t3x1c+(t3x2c-t3x1c)/2,t3y1c+(t3y2c-t3y1c)/2,15);
}
void Move2to3()
{
/*Erase disc from 2st tower*/
setcolor(BLACK);
rectangle(t2x1c,t2y1c,t2x2c,t2y2c);
setfillstyle(1,0);
setcolor(0);
floodfill(t2x1c+(t2x2c-t2x1c)/2,t2y1c+(t2y2c-t2y1c)/2,0);
/*Drw tower 1 again*/
drwTower2();
/*Draw Disc at tower 3*/
setcolor(15);
rectangle(t3x1c,t3y1c,t3x2c,t3y2c);
setcolor(4);
setfillstyle(1,4) ;
floodfill(t3x1c+(t3x2c-t3x1c)/2,t3y1c+(t3y2c-t3y1c)/2,15);
}
void Move3to2()
{
/*Erase disc from 2st tower*/
setcolor(BLACK);
rectangle(t3x1c,t3y1c,t3x2c,t3y2c);
setfillstyle(1,0);
setcolor(0);
floodfill(t3x1c+(t3x2c-t3x1c)/2,t3y1c+(t3y2c-t3y1c)/2,0);
/*Drw tower 1 again*/
drwTower3();
/*Draw Disc at tower 3*/
setcolor(15);
rectangle(t2x1c,t2y1c,t2x2c,t2y2c);
setcolor(4);
setfillstyle(1,4) ;
floodfill(t2x1c+(t2x2c-t2x1c)/2,t2y1c+(t2y2c-t2y1c)/2,15);
}
void Move1to2()
{
/*Erase disc from 1st tower*/
setcolor(BLACK);
rectangle(t1x1c,t1y1c,t1x2c,t1y2c);
setfillstyle(1,0);
setcolor(0);
floodfill(t1x1c+(t1x2c-t1x1c)/2,t1y1c+(t1y2c-t1y1c)/2,0);
/*Drw tower 1 again*/
drwTower1();
/*Draw Disc at tower 3*/
setcolor(15);
rectangle(t2x1c,t2y1c,t2x2c,t2y2c);
setcolor(4);
setfillstyle(1,4) ;
floodfill(t2x1c+(t2x2c-t2x1c)/2,t2y1c+(t2y2c-t2y1c)/2,15);
}
void Move2to1()
{
/*Erase disc from 1st tower*/
setcolor(BLACK);
rectangle(t2x1c,t2y1c,t2x2c,t2y2c);
setfillstyle(1,0);
setcolor(0);
floodfill(t2x1c+(t2x2c-t2x1c)/2,t2y1c+(t2y2c-t2y1c)/2,0);
/*Drw tower 1 again*/
drwTower2();
/*Draw Disc at tower 3*/
setcolor(15);
rectangle(t1x1c,t1y1c,t1x2c,t1y2c);
setcolor(4);
setfillstyle(1,4) ;
floodfill(t1x1c+(t1x2c-t1x1c)/2,t1y1c+(t1y2c-t1y1c)/2,15);
}
void check()
{
if(tsf==tst)
{
setcolor(4);
outtextxy(200,400,"脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹");
setcolor(15);
outtextxy(180,400,"Same Towers Selected.choose again") ;
delay(1500);
playGame();
}
}
void selectTowerFrom()
{
setcolor(4);
outtextxy(180,400,"脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹");
setcolor(15);
outtextxy(200,400,"Select Tower from:");
tsf =0;
ok=0;
while(ok!=13)
{
ok = getch();
if(ok!=13)
{
tsf=ok;
}
printTowerChoice(ok);
}
}
void selectTowerTo()
{
setcolor(4);
outtextxy(200,400,"脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹");
setcolor(15);
outtextxy(200,400,"Select Tower to:");
tst =0;
ok=0;
while(ok!=13)
{
ok = getch();
if(ok!=13)
{
tst=ok;
}
printTowerChoice(ok);
}
}
void printTowerChoice(int choice)
{
switch(choice)
{
case 49:
setcolor(4);
outtextxy(350,400,"脹脹脹脹脹脹脹脹脹脹脹");
setcolor(15);
outtextxy(350,400,"Tower 1");
break;
case 50:
setcolor(4);
outtextxy(350,400,"脹脹脹脹脹脹脹脹脹脹脹 ");
setcolor(15);
outtextxy(350,400,"Tower 2");
break;
case 51:
setcolor(4);
outtextxy(350,400,"脹脹脹脹脹脹脹脹脹脹脹");
setcolor(15);
outtextxy(350,400,"Tower 3 ");
break;
case 13:
setcolor(4);
outtextxy(200,400,"脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹");
setcolor(15);
outtextxy(200,400," Done!");
delay(1000);
break;
case 8:
setcolor(4);
setcolor(4);
outtextxy(200,400,"脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹");
setcolor(15);
outtextxy(200,400," Are You Sure to Quit?(y/n)");
int Quit;
Quit = getch();
if(Quit ==121)
{
cleardevice();
showMenu();
}
else
playGame();
break;
}
}
void getxyoft1(int t1pc)
{
switch(t1pc)
{
case 1:
t1x1c =142,t1y1c=d0y1t1,t1x2c=242,t1y2c=d0y2t1;
break;
case 2:
t1x1c =147,t1y1c=d1y1t1,t1x2c=237,t1y2c=d1y2t1;
break;
case 3:
t1x1c =152,t1y1c=d2y1t1,t1x2c=232,t1y2c=d2y2t1;
break;
case 4:
t1x1c =157,t1y1c=d3y1t1,t1x2c=227,t1y2c=d3y2t1;
break;
}
}
void getxyoft2(int t2pc)
{
switch(t2pc)
{
case 1:
t2x1c =257,t2y1c=d0y1t2,t2x2c=357,t2y2c=d0y2t2;
break;
case 2:
t2x1c =262,t2y1c=d1y1t2,t2x2c=352,t2y2c=d1y2t2;
break;
case 3:
t2x1c =267,t2y1c=d2y1t2,t2x2c=347,t2y2c=d2y2t2;
break;
case 4:
t2x1c =272,t2y1c=d3y1t2,t2x2c=342,t2y2c=d3y2t2;
break;
}
}
void getxyoft3(int t3pc)
{
switch(t3pc)
{
case 1:
t3x1c =372,t3y1c=d0y1t3,t3x2c=472,t3y2c=d0y2t3;
break;
case 2:
t3x1c =377,t3y1c=d1y1t3,t3x2c=467,t3y2c=d1y2t3;
break;
case 3:
t3x1c =382,t3y1c=d2y1t3,t3x2c=462,t3y2c=d2y2t3;
break;
case 4:
t3x1c =387,t3y1c=d3y1t3,t3x2c=457,t3y2c=d3y2t3;
break;
}
}
void drwTower1()
{
setcolor(7);
rectangle(180,t1y2c-26,205,t1y2c);
setfillstyle(1,7);
floodfill(192,t1y2c-26+(t1y2c-(t1y2c-26))/2,7);
}
void drwTower2()
{
setcolor(7);
rectangle(295,t2y2c-26,320,t2y2c);
setfillstyle(1,7);
floodfill(307,t2y2c-26+(t2y2c-(t2y2c-26))/2,7);
}
void drwTower3()
{
setcolor(7);
rectangle(410,t3y2c-26,435,t3y2c);
setfillstyle(1,7);
floodfill(422,t3y2c-26+(t3y2c-(t3y2c-26))/2,7);
}
void playGame()
{
while(t3cntr!=4)
{
selectTowerFrom();
selectTowerTo();
check();
movedisc();
}
outtextxy(200,400,"脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹脹");
setcolor(15);
outtextxy(200,400," You Won!");
delay(2000);
cleardevice();
showMenu();
getch();
}
void Instructions()
{
cleardevice();
setcolor(4);
setfillstyle(1,4);
setcolor(15);
outtextxy(250,150,"INSTRUCTIONS");
gotoxy(120*0.125,180*0.068);
cout<<"OBJECTIVE: Your objective is to move all the Discs from Tower 1 to Tower 3,but with a constraint that no bigger disc can be placed upon a smaller disc."<<endl;
cout<<endl<<"1. Press Numeric key 1,2 or 3 for selecting a tower."<<endl;
cout<<"2.Press enter to confirm Tower selection."<<endl;
cout<<"3.Press Enter to move Disc form two selected Towers."<<endl;
cout<<"4.To Return to Menu anytime during play press Backspace key."<<endl;
outtextxy(190,350,"Press Enter to return to menu");
getch();
cleardevice();
showMenu();
}
void txtmsg()
{
struct palettetype pal;
int r=3,g=3,b=3;
getpalette(&pal);
for(int i=0;i<=pal.size;i++)
{
setrgbpalette(pal.colors[10],r*i,g*i,b*i);
setcolor(10);
outtextxy(250,80,"THE TOWER");
outtextxy(300,110,"OF");
outtextxy(280,140,"HANOI");
delay(150);
}
setcolor(15);
outtextxy(250,80,"THE TOWER");
outtextxy(300,110,"OF");
outtextxy(280,140,"HANOI");
}
void txtmsg2()
{
struct palettetype pal;
int r=3,g=3,b=3;
getpalette(&pal);
for(int i=0;i<=pal.size;i++)
{
setrgbpalette(pal.colors[10],r*i,g*i,b*i);
setcolor(10);
outtextxy(120,380,"SoftMagic Game Studio");
delay(150);
}
setcolor(15);
outtextxy(120,380,"SoftMagic Game Studio");
}
Protecting your new page
Normally a new wiki page can be edited by other people (that is one of the main ideas of a wiki!) However, you could 'protect' the page, if desired, to prevent normal users from editing it. This requires sysop permissions.

