#include #include #include #include #include using namespace std; char locker_frame[9][77] = {"+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+", "| | | | | | | | | | | Locker | | | | | | | | | | | |", "+--+--+--+--+--+--+--+--+--+--+ +--+--+--+--+--+--+--+--+--+--+--+", "| | | | | | | | | | | Control | | | | | | | | | | | |", "+--+--+--+--+--+--+--+--+--+--+ +--+--+--+--+--+--+--+--+--+--+--+", "| | | | | | | | | | | Panel | | | | | | | | | | | |", "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+", "| | | | | | | | | | | | | | | | | | | | | | | | | |", "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+"}; string locker_data[4][4][25]; static HANDLE hOut; int clicked; #define FW FOREGROUND_RED |\ FOREGROUND_GREEN |\ FOREGROUND_BLUE void gotoxy(unsigned short x, unsigned short y); void rent_locker(); void cancel_locker(); void admin_mode(); void draw_locker(int location); void initialize_locker_data(); void highlight(int x_coor1, int y_coor1,int x_coor2,int y_coor2, int color); int check_available(int location,int row,int col); int locker_remain(int location,int row,int col,int direction); void main(){ //do{ // system("cls"); // gotoxy(0,0); // cout << " " << GetAsyncKeyState(13) << " "; //}while(2>1); SetConsoleTitle("Locker Rental System"); hOut = GetStdHandle(STD_OUTPUT_HANDLE); initialize_locker_data(); main_menu: system("cls"); char menu_option[3][30]={"1)Rent a locker\n", "2)Cancel a locker rental\n", "3)Administrator mode\n"}; cout << "Please Select an Option\n"; cout << " ==>" << menu_option[0]; cout << " " << menu_option[1]; cout << " " << menu_option[2]; int key=1; do{ if(GetAsyncKeyState(VK_UP) != 0){ if(key>1){key-=1;} }else if(GetAsyncKeyState(VK_DOWN) != 0){ if(key<3){key+=1;} } if(key!=1){ gotoxy(0,key-1); cout << " "; SetConsoleTextAttribute(hOut,FW | 0); cout << menu_option[key-2]; } if(key!=3){ gotoxy(0,key+1); cout << " "; SetConsoleTextAttribute(hOut,FW | 0); cout << menu_option[key]; } gotoxy(0,key); cout << " ==>"; SetConsoleTextAttribute(hOut,BACKGROUND_GREEN |BACKGROUND_INTENSITY); cout << menu_option[key-1]; SetConsoleTextAttribute(hOut,FW | 0); Sleep(200); }while(!GetAsyncKeyState(13)); switch(key){ case 1: rent_locker(); break; case 2: cancel_locker(); break; case 3: admin_mode(); } goto main_menu; } void gotoxy(unsigned short x, unsigned short y) { COORD WritePos; WritePos.X = x; WritePos.Y = y; SetConsoleCursorPosition(hOut,WritePos); } void rent_locker(){ char building[8][30]={"_____________________________", "| Second Floor |", "_____________________________", "| First Floor |", "_____________________________", "| Ground Floor Shops |", "_____________________________", "| Basement Car Park |"}; int stack_no=0; rent_step1: system("cls"); cout << "Step 1: Please select a locker stack location:\n"; for(int i=0;i<8;i++){cout << " " << building[i] << endl;} cout << "\nPress \"Back Space\" to return previous page"; clicked=1; do{ if(GetAsyncKeyState(VK_UP) != 0){ if(stack_no>0){ stack_no-=1; clicked=1; } }else if(GetAsyncKeyState(VK_DOWN) != 0){ if(stack_no<3){ stack_no+=1; clicked=1; } }else if(GetAsyncKeyState(8) != 0){ return; } if(clicked==1){ if(stack_no!=0){ gotoxy(0,stack_no*2-1); cout << " "; SetConsoleTextAttribute(hOut,FW | 0); cout << building[stack_no*2-2] << endl; cout << " " << building[stack_no*2-1] << endl; } if(stack_no!=3){ gotoxy(0,stack_no*2+3); cout << " "; SetConsoleTextAttribute(hOut,FW | 0); cout << building[stack_no*2+2] << endl; cout << " " << building[stack_no*2+3] << endl; } gotoxy(0,stack_no*2+1); cout << " " << building[stack_no*2] << endl; cout << " ==>" << building[stack_no*2+1] << endl; highlight(8,stack_no*2+1,36,stack_no*2+2,BACKGROUND_GREEN |BACKGROUND_INTENSITY); clicked=0; } Sleep(200); gotoxy(0,0); }while(!GetAsyncKeyState(13)); rent_step2: system("cls"); string location_name; switch(stack_no){ case 3:location_name="Basement Car Park"; break; case 2:location_name="Ground Floor Shops"; break; case 1:location_name="First Floor"; break; case 0:location_name="Second Floor"; } cout << "Locker Stack Location no. " << abs(stack_no-4) << " - " << location_name << endl; cout << "Daily charges: Top=$20, Bottom=$10, The Rest=$15\n\n"; draw_locker(stack_no); gotoxy(0,13); cout << "Press \"Back Space\" to return previous page"; int x_position=0,y_position=0; for(i=0;i<4;i++){ for(int j=0;j<25;j++){ if(check_available(stack_no,i,j)==1){ x_position=j; y_position=i; break; } } if(x_position!=0 || y_position !=0 || check_available(stack_no,0,0) == 1){break;} if(check_available(stack_no,0,0) == 0 && x_position == 0 && y_position == 0 ){ system("cls"); cout << "The Lockers in this location are full\n"; Sleep(3000); goto rent_step1; } } clicked=1; do{ if(GetAsyncKeyState(VK_UP) != 0){ if(locker_remain(stack_no,y_position,x_position,0) != -1){ highlight(x_position*3,y_position*2+3, x_position*3+3,y_position*2+5, FW | 0); y_position=locker_remain(stack_no,y_position,x_position,0); clicked=1; } }else if(GetAsyncKeyState(VK_DOWN) != 0){ if(locker_remain(stack_no,y_position,x_position,1) != -1){ highlight(x_position*3,y_position*2+3, x_position*3+3,y_position*2+5, FW | 0); y_position=locker_remain(stack_no,y_position,x_position,1); clicked=1; } }else if(GetAsyncKeyState(VK_LEFT) != 0){ if(locker_remain(stack_no,y_position,x_position,2) != -1){ highlight(x_position*3,y_position*2+3, x_position*3+3,y_position*2+5, FW | 0); x_position=locker_remain(stack_no,y_position,x_position,2); clicked=1; } }else if(GetAsyncKeyState(VK_RIGHT) != 0){ if(locker_remain(stack_no,y_position,x_position,3) != -1){ highlight(x_position*3,y_position*2+3, x_position*3+3,y_position*2+5, FW | 0); x_position=locker_remain(stack_no,y_position,x_position,3); clicked=1; } }else if(GetAsyncKeyState(8) != 0){ goto rent_step1; } if(clicked==1){ highlight(x_position*3,y_position*2+3, x_position*3+3,y_position*2+5, BACKGROUND_GREEN |BACKGROUND_INTENSITY); clicked=0; } gotoxy(59,0); string rental_price (locker_data[stack_no][y_position][x_position],2,2); cout << "Rental Price: "; SetConsoleTextAttribute(hOut,FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY); cout << "$" << rental_price; SetConsoleTextAttribute(hOut,FW |0); gotoxy(0,0); Sleep(300); }while(!(GetAsyncKeyState(13)));// & 0x8000; rent_step3: gotoxy(0,16); string rental_price (locker_data[stack_no][y_position][x_position],2,2); cout << "The rental price is $" << rental_price << endl; fflush(stdin); char confirm[10]; confirm[0]='u'; do{ cout << "Rent Paid(y/n): "<< flush; fflush(stdin); cin.clear(); cin >> confirm; }while(strlen(confirm)>1 || !(confirm[0]=='y'||confirm[0]=='Y'|| confirm[0]=='n'||confirm[0]=='N')); fflush(stdin); if(confirm[0]=='y' || confirm[0]=='Y'){ confirm[0]='u'; cout << "*** PAID!!! ***"; }else if(confirm[0]=='n' || confirm[0]=='N'){ confirm[0]='u'; goto rent_step2; } return; } void cancel_locker(){ system("cls"); return; } void admin_mode(){ system("cls"); return; } void draw_locker(int location){ int i,j,k; char temp_locker_frame[9][77]; for(i=0;i<9;i++){ for(j=0;j<77;j++){ temp_locker_frame[i][j]=locker_frame[i][j]; } } for(j=0;j<4;j++){ for(k=0;k<25;k++){ string available (locker_data[location][j][k],0,1); if(available=="n"){ temp_locker_frame[j*2+1][k*3+1]='X'; temp_locker_frame[j*2+1][k*3+2]='X'; } } } for(i=0;i<9;i++){ for(j=0;j<77;j++){ if(temp_locker_frame[i][j]=='X'){ SetConsoleTextAttribute(hOut,FOREGROUND_RED |FOREGROUND_INTENSITY); cout << temp_locker_frame[i][j]; SetConsoleTextAttribute(hOut,FW | 0); }else{ cout << temp_locker_frame[i][j]; } } cout << endl; } } void initialize_locker_data(){ for(int i=0;i<4;i++){ for(int j=0;j<4;j++){ for(int k=0;k<25;k++){ if(j==0){ locker_data[i][j][k]="y,20,"; }else if(j==3){ locker_data[i][j][k]="y,10,"; }else{ locker_data[i][j][k]="y,15,"; } if(0<=j && j<=2 && 10<=k && k<=13){ locker_data[i][j][k]="control_panel"; } } } } locker_data[0][0][3]="n,15,"; locker_data[1][1][4]="n,15,"; locker_data[2][2][5]="n,15,"; locker_data[3][3][9]="n,15,"; locker_data[3][3][1]="n,15,"; locker_data[3][3][2]="n,15,"; locker_data[3][3][3]="n,15,"; locker_data[3][3][4]="n,15,"; locker_data[3][3][5]="n,15,"; locker_data[3][3][6]="n,15,"; locker_data[3][3][7]="n,15,"; locker_data[3][0][0]="n,15,"; } void highlight(int x_coor1, int y_coor1,int x_coor2,int y_coor2, int color){ char temp[50]; COORD Where; DWORD NumRead; for(int i=y_coor1;i<=y_coor2;i++){ Where.X = x_coor1; Where.Y = i; ReadConsoleOutputCharacter(hOut, temp, x_coor2 - x_coor1 + 1, Where, &NumRead); gotoxy(x_coor1,i); int k=0; for(int j=x_coor1;j<=x_coor2;j++){ SetConsoleTextAttribute(hOut,color); if(temp[k]=='X'){ SetConsoleTextAttribute(hOut,FOREGROUND_RED |FOREGROUND_INTENSITY); cout << temp[k++]; }else{ cout << temp[k++]; } } } SetConsoleTextAttribute(hOut,FW | 0); } int check_available(int location,int row,int col){ string available (locker_data[location][row][col],0,1); if(available=="n"){ return 0; }else if(available=="y"){ return 1; } return -1; } int locker_remain(int location,int row,int col,int direction){ int i; if(direction==0){ //up if(row<1){return -1;} for(i=row-1;i>=0;i--){ if(check_available(location,i,col)==1){ return i; } } }else if(direction==1){ //down if(row>2){return -1;} for(i=row+1;i<=3;i++){ if(check_available(location,i,col)==1){ return i; } } }else if(direction==2){ //left if(col<1){return -1;} for(i=col-1;i>=0;i--){ if(check_available(location,row,i)==1){ return i; } } }else if(direction==3){ //right if(col>23){return -1;} for(i=col+1;i<=24;i++){ if(check_available(location,row,i)==1){ return i; } } } return -1; }