Forum PersianCoder

زمان کنونی: ۱/۳/۱۳۹۱, ۰۴:۴۹ صبح درود کاربر مهمان (ورودثبت نام)




ارسال پاسخ 
 
امتیاز موضوع:
  • 0 رای - 0 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
برج هانوی با زبان c  
نویسنده پیام
soroush_tayyebi آفلاین
کاربر تازه وارد

ارسال ها: 4
تاریخ عضویت: آذر ۱۳۸۹
اعتبار: 0
سپاس ها 1
سپاس شده 4 بار در 3 ارسال
ارسال: #1
برج هانوی با زبان c
سلام
این سورسش که با borland نوشته شده و گرافیکی هم هستش.

کد PHP:
#include <stdio.h>
#include <dos.h>
#include <conio.h>

int counterL,counterR=0,counterC=0;
void paye();
void mile();
void mohre(int n);
void transfer(int nchar fromchar tochar temp);
void counter(char from,char to);
void move(int n,char from,char to,int counterL,int counterC,int counterR);
void pak(int n,int x,int y);
void chap(int n,int x,int y);

void main()
{
int n;
printf("chand disk?" );
printf("[0<n<11]");
scanf("%d",&n);
if(
n>10||n<1)
{
printf("tedad eshtebah ast\n");
getch();
}
else
{
counterL=n;
textbackground(7);
clrscr();
mile();
paye();
mohre(n);
printf"\n" );
transfer(n,'L','R','C');
getch();}
}
/*end main*/
void transferint nchar fromchar tochar temp)
{
if (
0) {
transfer(n-1fromtemp,to);
counter(from,to);
move(n,from,to,counterL,counterC,counterR);
transfer(n-1,temp,to,from);
}
return;
}
/*end transfer*/
void paye()
{
 for(
int i=5;i<=75;i++)
 {if(
i>=5&&i<=25)
 {
gotoxy(i,23);
textcolor(4);
cprintf("%c",219);}
else
if(
i>=30&&i<=50)
 {
gotoxy(i,23);
textcolor(4);
cprintf("%c",219);}
else
if(
i>=55&&i<=75)
 {
gotoxy(i,23);
textcolor(4);
cprintf("%c",219);}}
}
/*end paye*/
void mile()
{
for(
int i=10;i<=22;i++)
{
gotoxy(15,i);
textcolor(12);
textbackground(4);
cprintf("%c",'|');}
for(
int i=10;i<=22;i++)
{
gotoxy(40,i);
textcolor(12);
textbackground(4);
cprintf("%c",'|');}
for(
int i=10;i<=22;i++)
{
gotoxy(65,i);
textcolor(12);
textbackground(4);
cprintf("%c",'|');}}
/*end mile*/
void mohre(int n)
{
int x,y=22;
x=15-n;
for(
int i=n;i>=1;i--)
{
gotoxy(x,y);
for(
int j=2*i+1;j>=1;j--)
{
textcolor(1);
cprintf("%c",219);}
x++;
y--;}
mile();
}
/*end mohre*/
void counter(char from,char to)
{
switch(
from)
{
case 
'L':counterL--;break;
case 
'R':counterR--;break;
case 
'C':counterC--;break;}
switch(
to)
{
case 
'L':counterL++;break;
case 
'R':counterR++;break;
case 
'C':counterC++;break;}
}
/*end counter*/

void move(int n,char from,char to,int counterL,int counterC,int counterR)
{
int x,y,x1,y1,x2;
switch(
from)
{
case 
'C':x=40-n;y=22-counterC;pak(n,x,y);break;
case 
'L':x=15-n;y=22-counterL;pak(n,x,y);break;
case 
'R':x=65-n;y=22-counterR;pak(n,x,y);break;}
switch(
to)
{
case 
'C':x1=40-n;y1=23-counterC;break;
case 
'L':x1=15-n;y1=23-counterL;break;
case 
'R':x1=65-n;y1=23-counterR;break;}
while(
y>=10)
{
y-=1;
chap(n,x,y);
sleep(0.5);
pak(n,x,y);}
//------------------------------------------------------------
x2=x1-x;
if(
x2>0)
{for(
int i=1;i<=x2;i++)
{
chap(n,x,y);
 
sleep(0.25);
 
pak(n,x,y);
 
x+=1;}}
//-------------------------------------------------------------
 
else{
 for(
int i=1;i<=-x2;i++)
{
chap(n,x,y);
 
sleep(0.25);
 
pak(n,x,y);
 
x-=1;}}
//---------------------------------------------------------------
while(y<y1)
{
y+=1;
chap(n,x,y);
sleep(0.5);
pak(n,x,y);}

switch(
to)
{
case 
'C':x1=40-n;y1=23-counterC;chap(n,x1,y1);break;
case 
'L':x1=15-n;y1=23-counterL;chap(n,x1,y1);break;
case 
'R':x1=65-n;y1=23-counterR;chap(n,x1,y1);break;}
}
/*end move*/
void pak(int n,int x,int y)
{
for(
int i=1;i<=2*n+1;i++)
{
gotoxy(x,y);
textcolor(7);
cprintf("%c",219);
x++;}}
/*end pak*/
void chap(int n,int x,int y)
{
for(
int i=1;i<=2*n+1;i++)
{
gotoxy(x,y);
textcolor(1);
cprintf("%c",219);
x++;
}
mile();
}
/*end chap*/ 
(آخرین ویرایش در این ارسال ۱۹/۹/۱۳۸۹ ۰۵:۰۴ عصر توسط soroush_tayyebi.)
۱۹/۹/۱۳۸۹ ۰۵:۰۴ عصر
یافتن تمامی ارسال های این کاربر نقل قول این ارسال در یک پاسخ
 سپاس شده توسط Rasoul ، ruhollah2009
ارسال پاسخ 


پرش به انجمن:

Powered by MyBB | Copyright © 2010 MyBB Group
Element Blue by MyBB Mod