-
Notifications
You must be signed in to change notification settings - Fork 0
/
UI.cpp
171 lines (141 loc) · 3.68 KB
/
UI.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#include "UI.h"
#include"Cargo.h"
#include"Truck.h"
#include"Company.h"
#include<Windows.h>
UI::UI()
{
int x;
cout << "Choose Mode\n0 - interactive\n1 - Step By Step\n2 - Silent\nEnter Number : ";
cin >> x;
mode = Mode(x);
cout << "\nSimulation Starts ...";
Line();
}
void UI::InterActiveMode(Company* cPtr) {
getchar();
PrintScreen(cPtr);
}
void UI::StepByStepMode(Company* cPtr) {
PrintScreen(cPtr);
Sleep(1000);
}
int UI::Readmanual()
{
int x;
cout << "Enter Test Case Number: \n";
cin >> x;
return x;
}
void UI::Output(string s)
{
cout << s;
}
void UI::Line()
{
cout << "\n";
for (int i = 0; i < 50; i++)
{
cout << "-";
}
cout << "\n";
}
void UI::PrintScreen(Company* Cptr) {
Line();
char open[3] = { '[', '(', '{' };
char close[3] = { ']', ')', '}' };
cout << "Current Time (Day:Hour):" << Cptr->getCurrentTime().TimePrint() << '\n';
// Waiting Cargos:
Output(to_string(Cptr->getWaitingCargosCount()) + " Waiting Cargos: ");
if (Cptr->getWaitingNormalCargo().getSize() != 0){
cout << '[';
Cptr->getWaitingNormalCargo().Print(this);
cout << "] ";
}
if(Cptr->getWaitingSpecialCargo().getSize() != 0) {
cout << '(';
Cptr->getWaitingSpecialCargo().Print(this);
cout << ") ";
}
if (Cptr->getWaitingVIPCargo().getSize() != 0) {
cout << '{';
Cptr->getWaitingVIPCargo().Print(this);
cout << "} ";
}
Line();
// Loading Trucks:
cout << Cptr->getLoadingTrucksCount() << " Loading Trucks: ";
Cptr->getLoadingTrucks().Print(this, ' ');
Line();
// Empty Trucks:
for (int Truck_Mode = DAY; Truck_Mode <= NIGHT; Truck_Mode++) {
Output(to_string(Cptr->getEmptyTrucksCount()[Truck_Mode]) + " Empty " + (Truck_Mode ? "Night" : "Day") + " Trucks: ");
for (int Truck_Type = Normal; Truck_Type <= VIP; Truck_Type++) {
if (!Cptr->getEmptyTrucks(Truck_Mode)[Truck_Type].isEmpty()) {
cout << open[Truck_Type];
Cptr->getEmptyTrucks(Truck_Mode)[Truck_Type].Print(this);
cout << close[Truck_Type];
}
}
Line();
}
// Moving Cargos:
Output(to_string(Cptr->getMovingCargosCount()) + " Moving Cargos: ");
Cptr->getMovingTrucks()->Print(this);
Line();
// Check-up Trucks:
for(int Truck_Mode = DAY; Truck_Mode <= NIGHT;Truck_Mode++){
Output(to_string(Cptr->getMaintainingTrucksCount()[Truck_Mode]) + " In-Checkup " + (Truck_Mode ? "Night" : "Day") + " Trucks: ");
for (int Truck_Type = Normal; Truck_Type <= VIP; Truck_Type++) {
if (!Cptr->getMaintainingTrucks(Truck_Mode)[Truck_Type].isEmpty()) {
cout << open[Truck_Type];
Cptr->getMaintainingTrucks(Truck_Mode)[Truck_Type].Print(this);
cout << close[Truck_Type];
}
}
Line();
}
// Delivered Cargos:
Output(to_string(Cptr->getDeliveredCargosCount()) + " Delivered Cargos: ");
for (int Truck_Type = Normal; Truck_Type <= VIP; Truck_Type++) {
if (!Cptr->getDeliveredCargo()[Truck_Type].isEmpty()) {
cout << open[Truck_Type];
Cptr->getDeliveredCargo()[Truck_Type].Print(this);
cout << close[Truck_Type];
}
}
Line();
}
void UI::Print(Cargo* c, char seperator) { cout << to_string(c->getID()) << seperator; }
void UI::Print(Truck* t, char seprator) {
if (!t) return;
cout << to_string(t->getID());
if (!t->getCargoList()->isEmpty()) {
char open[3] = { '[', '(', '{' };
char close[3] = { ']', ')', '}' };
cout << open[t->getCargoType()];
t->getCargoList()->Print(this, ',');
cout << close[t->getCargoType()] ;
}
cout << seprator;
}
void UI::Print(int n, char seperator)
{
cout << n << seperator;
}
void UI::Print(Company* cPtr) {
(mode)
{
case Interactive:
InterActiveMode(cPtr);
break;
case StepByStep:
StepByStepMode(cPtr);
break;
}
}
UI::~UI()
{
cout << "\nSimulation ends, Output file created \n";
Line();
}