//elevator.h
#include "passenger.h"
class Elevator : public Passenger
{
public:
int floorNo,
x, y; // ==> (x,y) position of elevator
/* constructor of the elevator for displaying on the screen */
/* the arguments are the position of elevator */
Elevator (int, int);
/* member function used to move elevator by displaying and clearing */
/* the elevator every step it moves */
void move(int);
/* member function to move elevator down */
void movedown(int);
/* member function to move elevator up */
void moveup(int);
/* member function that will decide whether the elevator should move */
/* down or up by accepting the destination position of elevator */
void movewhere(int);
};
Elevator :: Elevator ( int xpos, int ypos )
{
x = xpos;
y = ypos;
int i;
textattr(15 | 4*16);
for (i=1; i<y; i++)
{
gotoxy(x+2,i); cprintf("³");
}
gotoxy(x,y); cprintf("ÚÄÁÄ¿");
gotoxy(x,y+1); cprintf("³ ³");
gotoxy(x,y+2); cprintf("ÀÄÄÄÙ");
}
void Elevator :: move( int y )
{
textattr(15 | 4*16);
int i;
for(i=1; i<y; i++)
{ gotoxy(x+2,y-1); cprintf("³");
}
gotoxy(x,y); cprintf("ÚÄÁÄ¿");
gotoxy(x,y+1); cprintf("³ ³");
gotoxy(x,y+2); cprintf("ÀÄÄÄÙ");
Sleep(500);
gotoxy(x,y); cprintf(" ");
gotoxy(x,y+1); cprintf(" ");
gotoxy(x,y+2); cprintf(" ");
}
void Elevator :: movedown (int dest)
{
int i;
for( i=y ; i<=dest; ++i) { move(i); }
y = i-1;
Elevator(x,y);
}
void Elevator :: moveup (int dest)
{
int i;
for( i=y ; i>=dest; i--) { move(i); }
y = i+1;
Elevator(x,y);
}
void Elevator :: movewhere ( int ypos )
{
int decidemove;
decidemove = ypos - y;
if (decidemove > 0) movedown (ypos);
else moveup (ypos);
}