-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPaste.cpp
More file actions
170 lines (142 loc) · 4.82 KB
/
Copy pathPaste.cpp
File metadata and controls
170 lines (142 loc) · 4.82 KB
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
#include "Paste.h"
Paste::Paste(ApplicationManager* pApp) : Action(pApp)
{
}
void Paste::ReadActionParameters()
{
Pastegrid = pManager->GetGrid();
Output* pOut = Pastegrid->GetOutput();
Input* pIn = Pastegrid->GetInput();
pOut->PrintMessage("click on cell to Paste object");
Pasteposition = pIn->GetCellClicked();
pOut->ClearStatusBar();
}
void Paste::Execute()
{
ReadActionParameters();
clipobject= Pastegrid->GetClipboard(); //calling clipboard
if (clipobject == NULL) // if we didn't make any copyor cut
{
Pastegrid->PrintErrorMessage("error :you don't have any object to paste ! click to continue..");
return;
}
else if (dynamic_cast<Antenna*>(clipobject)) //clipboard had been save antenna
{
CellPosition* checkcell = new CellPosition;
CellPosition celledcheck;
bool hasantenna = false;
if (Pastegrid->Getobjectfromcelllist(Pasteposition)) // to know if cell is empty or not
{
Pastegrid->PrintErrorMessage("error:cell has object! click to continue..");
}
for (int i = 1; i < +55; i++)
{
celledcheck = checkcell->GetCellPositionFromNum(i);
if (dynamic_cast<Antenna*>(Pastegrid->Getobjectfromcelllist(celledcheck))) // to check is there any antenna in grid
{
hasantenna = true;
}
}
if (hasantenna == true)
{
Pastegrid->PrintErrorMessage("error:you have Antenna in grid ! click to continue");
}
else // set the antenna
{
Antenna* pAntenna = new Antenna(Pasteposition);
bool paste = Pastegrid->AddObjectToCell(pAntenna);
}
}
else if (dynamic_cast<Flag*>(clipobject)) //clipboard had been save flag
{
CellPosition* checkcell = new CellPosition;
CellPosition celledcheck;
bool hasflag = false;
if (Pastegrid->Getobjectfromcelllist(Pasteposition)) // to know if cell is empty or not
{
Pastegrid->PrintErrorMessage("error:cell has object! click to continue..");
}
for (int i = 1; i <+ 55; i++)
{
celledcheck = checkcell->GetCellPositionFromNum(i);
if (dynamic_cast<Flag*>(Pastegrid->Getobjectfromcelllist(celledcheck))) // to check is there any flag in grid
{
hasflag = true;
}
}
if (hasflag == true)
{
Pastegrid->PrintErrorMessage("error:you have flag in grid ! click to continue");
}
else
{
Flag* pFlag = new Flag(Pasteposition);
bool paste = Pastegrid->AddObjectToCell(pFlag);
}
}
else if (dynamic_cast<WaterPit*>(clipobject)) //clipboard had been save waterpit
{
WaterPit* pWaterPit= new WaterPit(Pasteposition);
bool paste = Pastegrid->AddObjectToCell(pWaterPit);
if (!paste)
{
Pastegrid->PrintErrorMessage("error:cell has object! click to continue..");
}
}
else if (dynamic_cast<DangerZone*>(clipobject)) //clipboard had been save dangerzone
{
DangerZone* pDangerZone = new DangerZone(Pasteposition);
bool paste = Pastegrid->AddObjectToCell(pDangerZone);
if (!paste)
{
Pastegrid->PrintErrorMessage("error:cell has object! click to continue..");
}
}
else if (dynamic_cast<RotatingGear*>(clipobject)) //clipboard had been save rotating gear
{
bool clockwise = dynamic_cast<RotatingGear*>(clipobject)->GetisClockWise();
RotatingGear* pRotatingGear = new RotatingGear(Pasteposition, clockwise);
bool paste = Pastegrid->AddObjectToCell(pRotatingGear);
if (!paste)
{
Pastegrid->PrintErrorMessage("error:cell has object! click to continue..");
}
}
else if (dynamic_cast<Belt*>(clipobject)) //clipboard had been save belt
{
int distancebelt ;
CellPosition endpasteBelt;
CellPosition startbelt= dynamic_cast<Belt*>(clipobject)->GetstartPosition();
CellPosition endBelt = dynamic_cast<Belt*>(clipobject)->GetEndPosition();
if (startbelt.VCell() == endBelt.VCell()) //if belt is in horizontal line
{
distancebelt = endBelt.HCell() - startbelt.HCell(); //To calculate the length of the belt
endpasteBelt.SetVCell(Pasteposition.VCell());
endpasteBelt.SetHCell(Pasteposition.HCell() + distancebelt);
}
else if (startbelt.HCell() == endBelt.HCell()) //if belt is in vertical line
{
distancebelt = endBelt.VCell() - startbelt.VCell(); //To calculate the length of the belt
endpasteBelt.SetHCell(Pasteposition.HCell());
endpasteBelt.SetVCell(Pasteposition.VCell() + distancebelt);
}
Belt* pBelt = new Belt(Pasteposition, endpasteBelt);
bool paste = Pastegrid->AddObjectToCell(pBelt);
if (!paste)
{
Pastegrid->PrintErrorMessage("error:cell has object! click to continue..");
}
}
else if (dynamic_cast<Workshop*>(clipobject)) //clipboard had been save workshop
{
Workshop* pWorkshop = new Workshop(Pasteposition);
bool paste = Pastegrid->AddObjectToCell(pWorkshop);
if (!paste)
{
Pastegrid->PrintErrorMessage("error:cell has object! click to continue..");
}
}
}
Paste::~Paste()
{
}