| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 6253 人关注过本帖, 1 人收藏
标题:花了一个晚上做的汉诺塔动画,请大家看看!
只看楼主 加入收藏
Lydolphin
Rank: 1
等 级:新手上路
帖 子:50
专家分:0
注 册:2005-12-4
收藏
得分:0 

可以的!
我刚才在虚拟机中试验了一下!
可以这样定义!
如果还运行不了!就用这个吧!
我刚才修改一下在TC2.0运行了,可以运行!
/* ================================= Program Description ================================= */
/* Program Name : Hanoi.c */
/* Program Purpose : Simulate Hanoi */
/* Environment : TC2.0 */
/* Operating System : Windows.Server.2003.Standard */
/* Written By Lydolphin. */
/* ======================================================================================= */

/* --------------------------------------------------------------------------------------- */

#include <stdio.h>
#include <graphics.h>
#include <conio.h>
#include <dos.h>

/* --------------------------------------------------------------------------------------- */

#define PATH "D:\\Software\\Programs\\TC3.0\\BGI"
#define N 4
#define Rate 4

/* --------------------------------------------------------------------------------------- */

int x[N][2], y[N][2] ;
int countA, countB, countC ;

/* --------------------------------------------------------------------------------------- */

void init(int numT) ;
void Hanoi(char from, char to, char aux, int n) ;
void movTower(int n, char from, char to) ;
void movup(int arrayE, int x1, int x2) ;
void movdown(int arrayE, int x1, int x2, int countN) ;
void movright(int arrayE, int x, int n) ;
void movleft(int arrayE, int x, int n) ;

/* --------------------------------------------------------------------------------------- */

void main()
{
int gdriver=DETECT, gmode ;

initgraph(&gdriver, &gmode, PATH) ;

countA=N ;
countB=0 ;
countC=0 ;

init(N) ;
getch() ;
Hanoi('A', 'C', 'B', N) ;

getch() ;
closegraph() ;
}

/* --------------------------------------------------------------------------------------- */

void init(int numT)
{
int i ;
int count=0 ;

bar(10, 70, 629, 409) ;
setfillstyle(1, 0) ;
bar(30, 359, 609, 369) ;
bar(121, 150, 131, 358) ;
bar(314, 150, 324, 358) ;
bar(507, 150, 517, 358) ;
setcolor(8) ;
for(i=numT-1 ; i>=0 ; i--)
{
x[count][0]=121-(numT-i)*4 ;
x[count][1]=131+(numT-i)*4 ;
y[count][0]=348-i*11 ;
y[count][1]=358-i*11 ;
rectangle(x[count][0], y[count][0], x[count][1], y[count][1] ) ;
count++ ;
}
}

/* --------------------------------------------------------------------------------------- */

void Hanoi(char from, char to, char aux, int n)
{
if(n==1)
movTower(1, from, to) ;
else
{
Hanoi(from, aux, to, n-1) ;
movTower(n, from, to) ;
Hanoi(aux, to, from, n-1) ;
}
}

/* --------------------------------------------------------------------------------------- */

void movTower(int n, char from, char to)
{
int arrayE ;

arrayE=n-1 ;

if(from=='A' && to=='C')
{
countA-- ;

movup(arrayE, 121, 131) ;

movright(arrayE, 507, n) ;

movdown(arrayE, 507, 517, countC) ;

countC++ ;
}
if(from=='A' && to=='B')
{
countA-- ;

movup(arrayE, 121, 131) ;

movright(arrayE, 314, n) ;

movdown(arrayE, 314, 324, countB) ;

countB++ ;
}
if(from=='B' && to=='A')
{
countB-- ;

movup(arrayE, 314, 324) ;

movleft(arrayE, 121, n) ;

movdown(arrayE, 121, 131, countA) ;

countA++ ;
}
if(from=='B' && to=='C')
{
countB-- ;

movup(arrayE, 314, 324) ;

movright(arrayE, 507, n) ;

movdown(arrayE, 507, 517, countC) ;

countC++ ;
}
if(from=='C' && to=='A')
{
countC-- ;

movup(arrayE, 507, 517) ;

movleft(arrayE, 121, n) ;

movdown(arrayE, 121, 131, countA) ;

countA++ ;
}
if(from=='C' && to=='B')
{
countC-- ;

movup(arrayE, 507, 517) ;

movleft(arrayE, 314, n) ;

movdown(arrayE, 314, 324, countB) ;

countB++ ;
}
}

/* --------------------------------------------------------------------------------------- */

void movup(int arrayE, int x1, int x2)
{
while(y[arrayE][1] > 140)
{
delay(Rate) ;
setcolor(15) ;
rectangle(x[arrayE][0], y[arrayE][0], x[arrayE][1], y[arrayE][1] ) ;
setcolor(0) ;
if(y[arrayE][0] > 150)
line(x1, y[arrayE][0], x2, y[arrayE][0] ) ;
if(y[arrayE][1] > 150)
line(x1, y[arrayE][1], x2, y[arrayE][1] ) ;
y[arrayE][0] -- ;
y[arrayE][1] -- ;
setcolor(8) ;
rectangle(x[arrayE][0], y[arrayE][0], x[arrayE][1], y[arrayE][1] ) ;
}
}

/* --------------------------------------------------------------------------------------- */

void movdown(int arrayE, int x1, int x2, int countN)
{
int botCPos ;

botCPos=358-countN*11 ;
while(y[arrayE][1] < botCPos)
{
delay(Rate) ;
setcolor(15) ;
rectangle(x[arrayE][0], y[arrayE][0], x[arrayE][1], y[arrayE][1] ) ;
setcolor(0) ;
if(y[arrayE][0] > 150)
line(x1, y[arrayE][0], x2, y[arrayE][0] ) ;
if(y[arrayE][1] > 150)
line(x1, y[arrayE][1], x2, y[arrayE][1] ) ;
y[arrayE][0] ++ ;
y[arrayE][1] ++ ;
setcolor(8) ;
rectangle(x[arrayE][0], y[arrayE][0], x[arrayE][1], y[arrayE][1] ) ;
}
}

/* --------------------------------------------------------------------------------------- */

void movright(int arrayE, int x1, int n)
{
int movCPos ;

movCPos=x1-n*4 ;
while(x[arrayE][0] < movCPos)
{
delay(Rate) ;
setcolor(15) ;
rectangle(x[arrayE][0], y[arrayE][0], x[arrayE][1], y[arrayE][1] ) ;
x[arrayE][0] ++ ;
x[arrayE][1] ++ ;
setcolor(8) ;
rectangle(x[arrayE][0], y[arrayE][0], x[arrayE][1], y[arrayE][1] ) ;
}
}

/* --------------------------------------------------------------------------------------- */

void movleft(int arrayE, int x1, int n)
{
int movCPos ;

movCPos=x1-n*4 ;
while(x[arrayE][0] > movCPos)
{
delay(Rate) ;
setcolor(15) ;
rectangle(x[arrayE][0], y[arrayE][0], x[arrayE][1], y[arrayE][1] ) ;
x[arrayE][0] -- ;
x[arrayE][1] -- ;
setcolor(8) ;
rectangle(x[arrayE][0], y[arrayE][0], x[arrayE][1], y[arrayE][1] ) ;
}
}

/* --------------------------------------------------------------------------------------- */


PHP:http://www.
ASP:http://www.
HTML:http://www.
2006-02-10 20:20
Fjcyz
Rank: 2
等 级:论坛游民
威 望:1
帖 子:175
专家分:25
注 册:2006-2-6
收藏
得分:0 
强! 佩服!

真想拜你为师.

最好的域名、虚拟主机、VPS  www.
2006-02-10 20:50
Lydolphin
Rank: 1
等 级:新手上路
帖 子:50
专家分:0
注 册:2005-12-4
收藏
得分:0 

谢谢夸奖!
拜师就算了!
我也是刚学不久的菜鸟而已....
可以的话,交个朋友吧!
呵呵.................
反正大家都在这泡的......


PHP:http://www.
ASP:http://www.
HTML:http://www.
2006-02-10 21:04
Fjcyz
Rank: 2
等 级:论坛游民
威 望:1
帖 子:175
专家分:25
注 册:2006-2-6
收藏
得分:0 
有没有ICQ号或MSN . 学习学习...
唉,感慨! 真强.

最好的域名、虚拟主机、VPS  www.
2006-02-10 21:12
Lydolphin
Rank: 1
等 级:新手上路
帖 子:50
专家分:0
注 册:2005-12-4
收藏
得分:0 

有啊!!
QQ:114606599!!



PHP:http://www.
ASP:http://www.
HTML:http://www.
2006-02-10 21:20
Fjcyz
Rank: 2
等 级:论坛游民
威 望:1
帖 子:175
专家分:25
注 册:2006-2-6
收藏
得分:0 

晕,是ICQ非QQ.


最好的域名、虚拟主机、VPS  www.
2006-02-10 21:28
Lydolphin
Rank: 1
等 级:新手上路
帖 子:50
专家分:0
注 册:2005-12-4
收藏
得分:0 

呵呵!
ICQ我不用...


PHP:http://www.
ASP:http://www.
HTML:http://www.
2006-02-10 21:32
hty
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2006-2-11
收藏
得分:0 
老兄 不错

2006-02-11 22:30
hty
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2006-2-11
收藏
得分:0 
qq 79819960 也想请老兄指教指教 注明 c友

2006-02-11 22:35
kangbry
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2008-3-11
收藏
得分:0 
qiang  无语 ,看到楼主,深感惭愧
2008-03-26 22:52
快速回复:花了一个晚上做的汉诺塔动画,请大家看看!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018008 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved