⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tick.cpp

📁 数据结构电梯程序设计 数据结构电梯程序设计
💻 CPP
字号:
//tick.cpp
#include"All.h"

extern int arrivetime[30] ;

void tick()
{
	Clock k ;
	Floor a ;
	Elevator b ;
	Door c ;
	Light t ;
	Bell r ;
	Button n ;
	Person p ;

	long int currenttime = k.gettime() ;

	int d , f ;

	srand(time(0)) ;
	
	for( int i = 0 ; currenttime < k.gettime()+150 ; i++ )
	{
		d = a.changePosition() ;

		if( d == 1 )//判断电梯和人的位置
		{
			f = b.getfloor() ;

			if( f == 1 )
			{
				if( currenttime < arrivetime[i] )
				{
					if( i!=0 )
					{
						c.openORclose( 0 )  ;
						t.lightonORoff( 0 ) ;
					}

					while(currenttime < arrivetime[i])
					{
						if( time(0) == currenttime )
						{
							k.showtime() ;
							cout << endl ;
							currenttime++ ;
						}
					}
					while( time(0) < arrivetime[i] ) ;
					cout << "第  " << i+1 <<"  个人  " ;
					k.showtime() ;
					n.numbernButton( d ) ;
					c.openORclose( 1 ) ;
					t.lightonORoff( 1 ) ;
				}
				else
				{
					cout << "第  " << i+1 <<"  个人 " ;
					k.change( arrivetime[i] ) ;
					n.numbernButton( d ) ;
				}
				cout << "第  " << i+1 <<"  个人 " ;
				k.showtime() ;
				p.goOutORcomeIn( 1 ) ;
				c.openORclose( 0 ) ;
				t.lightonORoff( 0 ) ;
				b.up() ;
				while( time(0) < currenttime+5 ) ;
				r.bellRing( 1 ) ;
				r.bellRing( 0 ) ;	
				c.openORclose( 1 ) ;
				t.lightonORoff( 1 ) ;
				currenttime += 5 ;
				cout << "第  " << i+1 <<"  个人 " ;
				k.showtime() ;
				p.goOutORcomeIn( -1 ) ;
				b.returnposition( 2 ) ;
				
			}
			if( f == 2 )
			{
				c.openORclose( 0 ) ;
				t.lightonORoff( 0 ) ;

				if( currenttime < arrivetime[i] )
				{
					while(currenttime < arrivetime[i])
					{
						if( time(0) == currenttime )
						{
							k.showtime() ;
							cout << endl ;
							currenttime++ ;
						}
					}
				}
                while( time(0) < arrivetime[i] ) ;
				cout << "第  " << i+1 <<"  个人 " ;
				k.showtime() ;
				n.numbernButton( d ) ;
				b.down() ;
				while( time(0) < currenttime+5 ) ;
				r.bellRing( 1 ) ;
				r.bellRing( 0 ) ;
				c.openORclose( 1 ) ;
				t.lightonORoff( 1 ) ;
				currenttime += 5 ;
				cout << "第  " << i+1 <<"  个人 " ;
				k.showtime() ;
				p.goOutORcomeIn( 1 ) ;
				c.openORclose( 0 ) ;
				t.lightonORoff( 0 ) ;
				b.up() ;
				while( time(0) < currenttime+5 ) ;
				r.bellRing( 1 ) ;
				r.bellRing( 0 ) ;
				c.openORclose( 1 ) ;
				t.lightonORoff( 1 ) ;
				currenttime += 5 ;
				cout << "第  " << i+1 <<"  个人 " ;
				k.showtime() ;
				p.goOutORcomeIn( -1 ) ;
				b.returnposition( 2 ) ;
				
			}

		}

		if( d == 2 )
		{
			f = b.getfloor() ;

			if( f == 1 )
			{
				if( i!= 0 )
				{
					c.openORclose( 0 ) ;
					t.lightonORoff( 0 ) ;
				}

				if( currenttime < arrivetime[i] )
				{
					while(currenttime < arrivetime[i])
					{
						if( time(0) == currenttime )
						{
							k.showtime() ;
							cout << endl ;
							currenttime++ ;
						}
					}
				}
                while( time(0) < arrivetime[i] ) ;
				cout << "第  " << i+1 <<"  个人 " ;
				k.showtime() ;
				n.numbernButton( d ) ;
				b.up() ;
				while( time(0) < currenttime+5 ) ;
				r.bellRing( 1 ) ;
				r.bellRing( 0 ) ;
				c.openORclose( 1 ) ;
				t.lightonORoff( 1 ) ;
				currenttime += 5 ;
				cout << "第  " << i+1 <<"  个人 " ;
				k.showtime() ;
				p.goOutORcomeIn( 1 ) ;
				c.openORclose( 0 ) ;
				t.lightonORoff( 0 ) ;
				b.down() ;
				while( time(0) < currenttime+5 ) ;
				r.bellRing( 1 ) ;
				r.bellRing( 0 ) ;
				c.openORclose( 1 ) ;
				t.lightonORoff( 1 ) ;
				currenttime += 5 ;
				cout << "第  " << i+1 <<"  个人 " ;
				k.showtime() ;
				p.goOutORcomeIn( -1 ) ;
				b.returnposition( 1 ) ;
				
			}
			if( f == 2 )
			{
				if( currenttime < arrivetime[i] )
				{
					c.openORclose( 0 ) ;
					t.lightonORoff( 0 ) ;

					while(currenttime < arrivetime[i])
					{
						if( time(0) == currenttime )
						{
							k.showtime() ;
							cout << endl ;
							currenttime++ ;
						}
					}
					while( time(0) < arrivetime[i] ) ;
					cout << "第  " << i+1 <<"  个人 " ;
					k.showtime() ;
					n.numbernButton( d ) ;
					c.openORclose( 1 ) ;
					t.lightonORoff( 1 ) ;
				}
				else
				{
					cout << "第  " << i+1 <<"  个人 " ;
					k.change( arrivetime[i] ) ;
					n.numbernButton( d ) ;
				}
				cout << "第  " << i+1 <<"  个人 " ;
				k.showtime() ;
				p.goOutORcomeIn( 1 ) ;
				c.openORclose( 0 ) ;
				t.lightonORoff( 0 ) ;
				b.down() ;
				while( time(0) < currenttime+5 ) ;
				r.bellRing( 1 ) ;
				r.bellRing( 0 ) ;
				c.openORclose( 1 ) ;
				t.lightonORoff( 1 ) ;
				currenttime += 5 ;
				cout << "第  " << i+1 <<"  个人 " ;
				k.showtime() ;
				p.goOutORcomeIn( -1 ) ;
				b.returnposition( 1 ) ;
				
			}

		}

	}


}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -