-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOutput.cpp
More file actions
817 lines (608 loc) · 27.8 KB
/
Copy pathOutput.cpp
File metadata and controls
817 lines (608 loc) · 27.8 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
#include "Output.h"
#include "Input.h"
#include <iostream>
#include <unordered_map>
//////////////////////////////////////////////////////////////////////////////////////////
Output::Output()
{
// Initialize user interface parameters
UI.InterfaceMode = MODE_DESIGN;
// Widths and Heights
UI.StatusBarHeight = 60;
UI.CommandsBarHeight = 100;
UI.CommandItemWidth = 70;
UI.ToolBarHeight = 55;
UI.MenuItemWidth = 55;
UI.width = 1210; // make it divisible by NumHorizontalCells
UI.height = 610;
UI.wx = 5;
UI.wy = 5;
UI.CellWidth = UI.width / NumHorizontalCells;
UI.CellHeight = (UI.height - UI.ToolBarHeight - UI.StatusBarHeight - UI.CommandsBarHeight) / NumVerticalCells;
// Pen Colors of messages of status bar and players' info
UI.MsgColor = DARKRED;
UI.PlayerInfoColor = DARKSLATEBLUE;
// Background Colors of toolbar and statusbar
UI.ToolBarColor = WHITE;
UI.StatusBarColor = LIGHTGRAY;
UI.CommandBarColor = BLACK;
// Line Colors of the borders of each cell
UI.GridLineColor = WHITE;
// Cell Color if Empty & Cell Number Font & Color
UI.CellColor = LIGHTSLATEBLUE;
UI.CellNumFont = 13;
UI.CellNumColor = UI.GridLineColor;
// Belt Line Width and Color
UI.BeltLineWidth = 6;
UI.BeltColor = DARKSLATEBLUE;
// The X and Y Offsets of the Space BEFORE Drawing the Belt (offset from the start X and Y of the Cell)
UI.BeltXOffset = (UI.CellWidth - 2 * UI.BeltLineWidth) / 5;
UI.BeltYOffset = (UI.CellHeight / 4) * 3;
// Flag and Flag Pole Colors
UI.FlagPoleWidth = 4;
UI.FlagPoleHeight = UI.CellHeight / 2;
UI.FlagWidth = UI.CellWidth / 4;
UI.FlagHeight = UI.FlagPoleHeight / 2;
UI.FlagColor = RED;
UI.FlagPoleColor = GHOSTWHITE;
// Commands X and Y Coordinates
UI.SpaceBetweenCommandsSlots = 10;
UI.AvailableCommandsXOffset = ( UI.CommandItemWidth + UI.SpaceBetweenCommandsSlots ) * 6;
// Colors of the 2 Players
UI.PlayerColors[0] = GOLD;
UI.PlayerColors[1] = DARKSLATEBLUE;
/*UI.PlayerColors[2] = KHAKI;
UI.PlayerColors[3] = CHOCOLATE;*/
// Create the output window
pWind = CreateWind(UI.width + 15, UI.height, UI.wx, UI.wy);
// Change the title
pWind->ChangeTitle("RoboRally");
// Create the toolbar, grid area and status bar
CreateDesignModeToolBar();
ClearGridArea();
ClearStatusBar();
ClearCommandsBar();
}
//////////////////////////////////////////////////////////////////////////////////////////
window* Output::CreateWind(int w, int h, int x, int y) const
{
// The Window Object is created inside the Ouput class
window* pW = new window(w, h, x, y);
return pW;
}
//////////////////////////////////////////////////////////////////////////////////////////
Input* Output::CreateInput() const
{
// The Input Object is created inside the Output class
Input* pIn = new Input(pWind);
return pIn;
}
//======================================================================================//
// Some Utility Functions //
//======================================================================================//
int Output::GetCellStartX(const CellPosition & cellPos) const
{
///TODO: implement the following function as described in Output.h file
if (cellPos.IsValidCell())
{
return cellPos.HCell() * UI.CellWidth;
}
else
{
return 0;
}
}
//////////////////////////////////////////////////////////////////////////////////////////
int Output::GetCellStartY(const CellPosition & cellPos) const
{
///TODO: implement the following function as described in Output.h file
if (cellPos.IsValidCell())
{
return cellPos.VCell() * UI.CellHeight + UI.ToolBarHeight;
}
else
{
return 0;
}
}
//////////////////////////////////////////////////////////////////////////////////////////
void Output::ClearToolBar() const
{
// Clear by drawing a rectangle filled with toolbar background color
pWind->SetPen(UI.ToolBarColor, 1);
pWind->SetBrush(UI.ToolBarColor);
pWind->DrawRectangle(0, 0, UI.width, UI.ToolBarHeight);
}
//////////////////////////////////////////////////////////////////////////////////////////
void Output::DrawTriangle(int triangleCenterX, int triangleCenterY, int triangleHeight, int triangleWidth, Direction direction, color triangleColor, drawstyle style, int penWidth) const
{
int x1, y1, x2, y2, x3, y3;
///TODO: Calculate the coordiantes of the 3 vertices of the triangle based on the passed parameters
if (direction == UP)
{
x1 = triangleCenterX - triangleWidth / 2;
y1 = triangleCenterY + triangleHeight / 2;
x2 = triangleCenterX + triangleWidth / 2;
y2 = triangleCenterY + triangleHeight / 2;
x3 = triangleCenterX;
y3 = triangleCenterY - triangleHeight / 2;
}
///TODO: Continue the implementation
else if (direction == DOWN) {
x1 = triangleCenterX - triangleWidth / 2;
y1 = triangleCenterY - triangleHeight / 2;
x2 = triangleCenterX + triangleWidth / 2;
y2 = triangleCenterY - triangleHeight / 2;
x3 = triangleCenterX;
y3 = triangleCenterY + triangleHeight / 2;
}
else if (direction == LEFT) {
x1 = triangleCenterX + triangleWidth / 2;
y1 = triangleCenterY - triangleHeight / 2;
x2 = triangleCenterX + triangleWidth / 2;
y2 = triangleCenterY + triangleHeight / 2;
x3 = triangleCenterX - triangleWidth / 2;
y3 = triangleCenterY;
}
else if (direction == RIGHT) {
x1 = triangleCenterX - triangleWidth / 2;
y1 = triangleCenterY - triangleHeight / 2;
x2 = triangleCenterX - triangleWidth / 2;
y2 = triangleCenterY + triangleHeight / 2;
x3 = triangleCenterX + triangleWidth / 2;
y3 = triangleCenterY;
}
// Set the pen and brush style
pWind->SetPen(triangleColor, penWidth);
pWind->SetBrush(triangleColor);
// Draw the triangle:
pWind->DrawTriangle(x1, y1, x2, y2, x3, y3, FILLED);
}
//////////////////////////////////////////////////////////////////////////////////////////
void Output::DrawImageInCell(const CellPosition& cellPos, string image, int width, int height) const
{
//########DONE TODO: Validate the cell position
if (!cellPos.IsValidCell()) {
return;
}
if (cellPos.GetCellNum() == 1) {
return;
}
int x = GetCellStartX(cellPos) + (UI.CellWidth )/4 ;
int y = GetCellStartY(cellPos) + (UI.CellHeight ) /4 ;
width = UI.CellWidth /2 ;
height = UI.CellHeight/2 ;
// TODO: Complete the implementation of this function
pWind->DrawImage(image, x, y, width, height);
}
//======================================================================================//
// Interface Functions //
//======================================================================================//
void Output::ClearStatusBar() const
{
// Clear drawing a rectangle filled with statusbar background color
pWind->SetPen(UI.StatusBarColor, 1);
pWind->SetBrush(UI.StatusBarColor);
pWind->DrawRectangle(0, UI.height - UI.StatusBarHeight, UI.width, UI.height);
}
void Output::ClearCommandsBar() const
{
// Clear drawing a rectangle filled with command bar background color
pWind->SetPen(UI.CommandBarColor, 1);
pWind->SetBrush(UI.CommandBarColor);
pWind->DrawRectangle(0, UI.height - UI.StatusBarHeight - UI.CommandsBarHeight, UI.width, UI.height - UI.StatusBarHeight);
}
//////////////////////////////////////////////////////////////////////////////////////////
void Output::ClearGridArea() const
{
// Draw each cell in the Grid: ( NumVerticalCells * NumberHorizontalCells )
for (int i = 0; i < NumVerticalCells; i++)
{
for (int j = 0; j < NumHorizontalCells; j++)
{
CellPosition cellPos(i, j);
DrawCell(cellPos);
}
}
}
//////////////////////////////////////////////////////////////////////////////////////////
void Output::CreateDesignModeToolBar() const
{
UI.InterfaceMode = MODE_DESIGN;
ClearToolBar(); // in order not to draw above the icons of the other mode when you switch
// You can draw the tool bar icons in any way you want.
// Below is one possible way
// First prepare List of images for each menu item
// To control the order of these images in the menu,
// reoder them in UI_Info.h ==> enum DESIGN_MODE_ITEMS
// ** MAKE SURE THAT THE IMAGES ARE .JPG FILES **
string MenuItemImages[DESIGN_ITM_COUNT];
MenuItemImages[ITM_EXIT] = "images\\Menu_Exit.jpg";
MenuItemImages[ITM_SWITCH_TO_PLAY_MODE] = "images\\Menu_SwitchToGame.jpg";
///TODO: Change the path of the images as needed
MenuItemImages[ITM_SET_FLAG_CELL] = "images\\Redflag.jpg";
///TODO: Prepare images for each menu item and add it to the list
MenuItemImages[ITM_ADD_ANTENNA] = "images\\Antenna.jpg";
MenuItemImages[ITM_ADD_BELT] = "images\\Belt.jpg";
MenuItemImages[ITM_ADD_WATER_PIT] = "images\\WaterPit.jpg";
MenuItemImages[ITM_ADD_DANGER_ZONE] = "images\\Dangerzone.jpg";
MenuItemImages[ITM_ADD_WORKSHOP] = "images\\Workshop.jpg";
MenuItemImages[ITM_ADD_ROTATING_GEAR_CLOCKWISE] = "images\\Clock.jpg";
MenuItemImages[ITM_ADD_ROTATING_GEAR_COUNTER_CLOCKWISE] = "images\\C Clock.jpg";
MenuItemImages[ITM_COPY_GAME_OBJECT] = "images\\Copy.jpg";
MenuItemImages[ITM_CUT_GAME_OBJRCT] = "images\\cut 1.jpg";
MenuItemImages[ITM_PASTE_GAME_OBJECT] = "images\\Paste.jpg";
MenuItemImages[ITM_DELETE_GAME_OBJECT] = "images\\delete 1.jpg";
MenuItemImages[ITM_SAVE_GRID] = "images\\save.jpg";
MenuItemImages[ITM_LOAD_and_OPEN_GRID] = "images\\load.jpg";
// Draw menu item one image at a time
for(int i=0; i < DESIGN_ITM_COUNT; i++)
pWind->DrawImage(MenuItemImages[i], i*UI.MenuItemWidth, 0, UI.MenuItemWidth, UI.ToolBarHeight);
}
//////////////////////////////////////////////////////////////////////////////////////////
void Output::CreatePlayModeToolBar() const
{
UI.InterfaceMode = MODE_PLAY;
ClearToolBar(); // in order not to draw above the icons of the other mode when you switch
// You can draw the tool bar icons in any way you want.
// Below is one possible way
// First prepare List of images for each menu item
// To control the order of these images in the menu,
// reoder them in UI_Info.h ==> enum DESIGN_MODE_ITEMS
// ** MAKE SURE THAT THE IMAGES ARE .JPG FILES **
string MenuItemImages[PLAY_ITM_COUNT];
MenuItemImages[ITM_SWITCH_TO_DESIGN_MODE] = "images\\repair.jpg";
///TODO: Change the path of the images as needed
MenuItemImages[ITM_EXECUTE_COMMANDS] = "images\\excute.jpg";
MenuItemImages[ITM_SELECT_COMMAND] = "images\\select.jpg";
///TODO: Prepare images for each menu item and add it to the list
MenuItemImages[ITM_REBOOT_AND_REPAIR] = "images\\whe.jpg";
MenuItemImages[ITM_USE_CONSUMABLE] = "images\\Menu_SwitchToGrid.jpg";
MenuItemImages[ITM_NEW_GAME] = "images\\cons.jpg";
MenuItemImages[ITM_EXIT_1] = "images\\newgame.jpg";
MenuItemImages[ITM_EXIT_2] = "images\\Menu_Exit.jpg";
// Draw menu item one image at a time
for(int i=0; i < PLAY_ITM_COUNT; i++)
pWind->DrawImage(MenuItemImages[i], i*UI.MenuItemWidth, 0, UI.MenuItemWidth, UI.ToolBarHeight);
}
void Output::CreateCommandsBar(Command savedCommands[], int savedCommandsCount, Command availableCommands[], int availableCommandsCount) const
{
ClearCommandsBar();
UI.InterfaceMode = MODE_PLAY;
string CommandItemImages[COMMANDS_COUNT];
CommandItemImages[NO_COMMAND] = "images\\CommandSlot-grey.jpg";
CommandItemImages[MOVE_FORWARD_ONE_STEP] = "images\\MoveForwardCard.jpg";
CommandItemImages[MOVE_BACKWARD_ONE_STEP] = "images\\MoveBackwardCard.jpg";
// TODO: Prepare images for more items with .jpg extensions and add them to the list
CommandItemImages[MOVE_FORWARD_TWO_STEPS] = "images\\MoveForward_2S_Card.jpg";
CommandItemImages[MOVE_BACKWARD_TWO_STEPS] = "images\\MoveBackward_2S_Card.jpg";
CommandItemImages[MOVE_FORWARD_THREE_STEPS] = "images\\MoveForward_3S_Card.jpg";
CommandItemImages[MOVE_BACKWARD_THREE_STEPS] = "images\\MoveBackward_3S_Card.jpg";
CommandItemImages[ROTATE_CLOCKWISE] = "images\\MoveClockwiseCard.jpg";
CommandItemImages[ROTATE_COUNTERCLOCKWISE] = "images\\MoveC_ClockwiseCard.jpg";
DrawSavedCommands(savedCommands, savedCommandsCount, CommandItemImages);
DrawAvailableCommands(availableCommands, availableCommandsCount, CommandItemImages);
}
//////////////////////////////////////////////////////////////////////////////////////////
void Output::DrawSavedCommands(Command savedCommands[], int savedCommandsCount, string CommandItemImages[]) const
{
if (UI.InterfaceMode == MODE_DESIGN)
return;
int spaceBetweenSlots = 10;
for (int i = 0; i < savedCommandsCount; ++i)
{
int x = i * (UI.CommandItemWidth + spaceBetweenSlots);
int y = UI.height - UI.StatusBarHeight - UI.CommandsBarHeight;
pWind->DrawImage(CommandItemImages[savedCommands[i]], x, y, UI.CommandItemWidth, UI.CommandsBarHeight);
}
}
//////////////////////////////////////////////////////////////////////////////////////////
void Output::DrawAvailableCommands(Command availableCommands[], int availableCommandsCount, string CommandItemImages[]) const
{
if (UI.InterfaceMode == MODE_DESIGN)
return;
// Define the size and spacing for the available commands
int availableCommandWidth = UI.CommandItemWidth / 2;
int availableCommandHeight = UI.CommandsBarHeight / 2;
// Define the starting position for the available commands
int startX = UI.AvailableCommandsXOffset;
int startY = UI.height - UI.StatusBarHeight - UI.CommandsBarHeight;
// Draw the "Available Commands" text above the command slots
pWind->SetPen(WHITE);
pWind->SetFont(UI.CellNumFont, BOLD, BY_NAME, "Arial");
string availableCommandsText = "Available Commands";
int textWidth = 0, textHeight = 0; // to be used in the next line as they are passed by reference
pWind->GetStringSize(textWidth, textHeight, availableCommandsText);
pWind->DrawString(startX, startY, availableCommandsText);
UI.AvailableCommandsYOffset = textHeight + 10; // vertical space between the start of the command bar and the cards of available commands
// will be used in detecting selected command from the user click
for (int i = 0; i < availableCommandsCount; ++i)
{
int x = startX + i * (availableCommandWidth);
int y = startY + UI.AvailableCommandsYOffset; // Adjust the Y position to be below the text
// Draw the command slot (assuming you have an image for the available commands)
if (availableCommands[i] != NO_COMMAND)
pWind->DrawImage(CommandItemImages[availableCommands[i]], x, y, availableCommandWidth, availableCommandHeight);
// Draw the command number below the card
pWind->SetPen(UI.CellNumColor);
pWind->SetFont(UI.CellNumFont, BOLD | ITALICIZED, BY_NAME, "Arial");
int w = 0, h = 0;
pWind->GetIntegerSize(w, h, i + 1);
int numX = x + (availableCommandWidth - w) / 2;
int numY = y + availableCommandHeight + 5; // Adjust the Y position to be below the card
pWind->DrawInteger(numX, numY, i + 1);
}
}
//////////////////////////////////////////////////////////////////////////////////////////
void Output::PrintMessage(string msg) const //Prints a message on status bar
{
ClearStatusBar(); // First clear the status bar from any previous writing
// Set pen and font before drawing the string on the window
pWind->SetPen(UI.MsgColor);
pWind->SetFont(18, BOLD , BY_NAME, "Verdana");
pWind->DrawString(10, UI.height - (int)(UI.StatusBarHeight/1.3), msg);
}
//////////////////////////////////////////////////////////////////////////////////////////
void Output::PrintPlayersInfo(string info)
{
///TODO: Clear what was written on the toolbar
// One of the correct ways to implement the above TODO is to call CreatePlayModeToolBar();
// to clear what was written in the player info (there are other ways too � You are free to use any)
CreatePlayModeToolBar();
// Set the pen and font before drawing the string on the window
pWind->SetPen(UI.PlayerInfoColor);
pWind->SetFont(20, BOLD , BY_NAME, "Verdana");
int w=0, h=0;
///TODO: Calculate the Width and Height of the string if drawn using the current font
// (Use GetStringSize() window function) and set the "w" and "h" variables with its width and height\
pWind->GetStringSize(w, h,info);
// Set the start X & Y coordinate of drawing the string
int x = UI.width - w - 20; // space 20 before the right-side of the window
// ( - w ) because x is the coordinate of the start point of the string (upper left)
int y = (UI.ToolBarHeight - h) / 2; // in the Middle of the toolbar height
///TODO: Draw the string "info" in the specified location (x, y)
pWind->DrawString(x, y, info);
}
//======================================================================================//
// Game Drawing Functions //
//======================================================================================//
void Output::DrawCell(const CellPosition & cellPos, color cellColor) const
{
// Get the Cell Number (from 1 to NumVerticalCells*NumHorizontalCells) and the X & Y of its upper left corner
int cellNum = cellPos.GetCellNum();
int cellStartX = GetCellStartX(cellPos);
int cellStartY = GetCellStartY(cellPos);
// ----- 1- Draw the cell itself (background) --> Filled Rectangle -----
pWind->SetPen(UI.GridLineColor, 1);
pWind->SetBrush(cellColor);
///TODO: Draw the Cell Rectangle using the appropriate coordinates
// using cellStartX, cellStartY, UI.CellWidth, UI.CellHeight
pWind->DrawRectangle(cellStartX, cellStartY, cellStartX + UI.CellWidth, cellStartY + UI.CellHeight);
// ----- 2- Draw the CELL number (the small number at the bottom right of the cell) -----
pWind->SetPen(UI.CellNumColor);
pWind->SetFont(UI.CellNumFont, BOLD , BY_NAME, "Verdana");
int w=0, h=0;
///TODO: Get the Width and Height of the Cell Number if written using the current font
// (Use GetIntegerSize() window function) and set the "w" and "h" variables with its width and height
pWind->GetIntegerSize(w, h, cellNum);
// Calculate X & Y coordinate of the start point of writing the card number (upper left point of the cell num)
int x = cellStartX + (UI.CellWidth - w - 1); // space 1 from the end of the cell width
// ( - w ) because x is for the start point of cell num (num's left corner)
int y = cellStartY + (UI.CellHeight - h - 1); // space 1 from the end of the cell height
// ( - w ) because y is for the start point of cell num (num's upper corner)
///TODO: Draw the cell number in the x and y location
pWind->DrawInteger(x, y, cellNum);
}
//////////////////////////////////////////////////////////////////////////////////////////
void Output::DrawPlayer(const CellPosition& cellPos, int playerNum, color playerColor, Direction direction) const
{
// TODO: Validate the cell position and the playerNum, if not valid return
if (!cellPos.IsValidCell()) {
return;
}
// Get the X & Y coordinates of the start point of the cell (its upper left corner)
int cellStartX = GetCellStartX(cellPos);
int cellStartY = GetCellStartY(cellPos);
// Calculate the Radius of the Player's Triangle
int radius = UI.CellWidth / 14; // proportional to cell width
// Calculate the horizontal space before drawing players triangles (space from the left border of the cell)
int ySpace = UI.CellHeight / 6; // proportional to cell height
// Note: Players' Triangles Locations depending on "playerNum" is as follows:
// Player_0
// Player_1
if (playerNum > 1 || playerNum < 0) {
return;
}
// Calculate the Y coordinate of the center of the player's triangle (based on playerNum)
int y = cellStartY + ySpace + radius + 2;
if (playerNum == 1)
y += 2 * (radius + 2); // because playerNum 1 is drawn in the second row of triangles
// Calculate the X coordinate of the center of the player's triangle (based on playerNum)
int x = cellStartX + UI.BeltXOffset + radius + 4; // UI.BeltXOffset is used to draw players' triangles
// AFTER the Belt start vertical line (assuming there is a belt)
// for not overlapping with belts
// TODO: Draw the player triangle in center(x,y) and filled with the playerColor passed to the function (Done)
// First : We Will Define the Width and Height of the triangle:
int trianglewidth = 2 * radius;
int triangleheight = 2 * radius;
//Second: We Will use DrawTriangle Function above :
DrawTriangle(x, y, triangleheight, trianglewidth, direction, playerColor, FILLED);
}
//////////////////////////////////////////////////////////////////////////////////////////
void Output::DrawBelt(const CellPosition& fromCellPos, const CellPosition& toCellPos) const
{
// // TODO: Validate the fromCell and toCell (Must be Horizontal or Vertical, and we can't have the first cell as a starting cell for a belt)
if (!fromCellPos.IsValidCell() || !toCellPos.IsValidCell())
return;
if (!(fromCellPos.VCell() == toCellPos.VCell() || fromCellPos.HCell() == toCellPos.HCell()))
return;
if (fromCellPos.GetCellNum() == 1) {
return;
}
// Get the start X and Y coordinates of the upper left corner of the fromCell and toCell
int fromCellStartX = GetCellStartX(fromCellPos);
int fromCellStartY = GetCellStartY(fromCellPos);
int toCellStartX = GetCellStartX(toCellPos);
int toCellStartY = GetCellStartY(toCellPos);
Direction d;
// TODO: Draw the belt line and the triangle at the center of the line pointing to the direction of the belt
// TODO: 1. Set pen color and width using the appropriate parameters of UI_Info object (UI)
pWind->SetPen(UI.BeltColor, UI.BeltLineWidth);
// 2. Draw the line of the belt using the appropriate coordinates
if (fromCellPos.VCell() == toCellPos.VCell()) {
if (fromCellPos.GetCellNum() < toCellPos.GetCellNum()) { // Right
int beltFromCellX = fromCellStartX + (UI.CellWidth / 2) + UI.BeltXOffset;
int beltToCellX = toCellStartX + UI.BeltXOffset;
int beltFromCellY = fromCellStartY + UI.BeltYOffset;
int beltToCellY = toCellStartY + UI.BeltYOffset;
pWind->DrawLine(beltFromCellX, beltFromCellY, beltToCellX, beltToCellY); // Horizontal line
// center of triangle :
int x = (beltFromCellX + beltToCellX) / 2;
int y = (beltFromCellY + beltToCellY) / 2;
//dimensions of triangle :
int triangleWidth = UI.CellWidth / 4;
int triangleHeight = UI.CellHeight / 4;
d = RIGHT;
DrawTriangle(x, y, triangleHeight, triangleWidth, d, UI.BeltColor); // Horizontal triangle
}
else { // left
int beltFromCellX = fromCellStartX + UI.BeltXOffset;
int beltToCellX = toCellStartX + 4 * UI.BeltXOffset;
int beltFromCellY = fromCellStartY + UI.BeltYOffset;
int beltToCellY = toCellStartY + UI.BeltYOffset;
pWind->DrawLine(beltFromCellX, beltFromCellY, beltToCellX, beltToCellY); // Horizontal line
// center of triangle :
int x = (beltFromCellX + beltToCellX) / 2;
int y = (beltFromCellY + beltToCellY) / 2;
//dimensions of triangle :
int triangleWidth = UI.CellWidth / 4;
int triangleHeight = UI.CellHeight / 4;
d = LEFT;
DrawTriangle(x, y, triangleHeight, triangleWidth, d, UI.BeltColor); // Horizontal triangle
}
}
else if (fromCellPos.HCell() == toCellPos.HCell()) {
if (fromCellPos.GetCellNum() < toCellPos.GetCellNum()) { // Up Directiin
int beltFromCellX = fromCellStartX + (UI.CellWidth / 2) + UI.BeltXOffset;
int beltToCellX = toCellStartX + 4 * UI.BeltXOffset;
int beltFromCellY = fromCellStartY + UI.BeltYOffset/2;
int beltToCellY = toCellStartY + UI.BeltYOffset;
pWind->DrawLine(beltFromCellX, beltFromCellY, beltToCellX, beltToCellY); // Vertical line
// center of triangle :
int x = (beltFromCellX + beltToCellX) / 2;
int y = (beltFromCellY + beltToCellY) / 2;
//dimensions of triangle :
int triangleWidth = UI.CellWidth / 4;
int triangleHeight = UI.CellHeight / 4;
d = UP;
DrawTriangle(x, y, triangleHeight, triangleWidth, d, UI.BeltColor); // Horizontal triangle
}
else { // down direction
int beltFromCellX = fromCellStartX + (UI.CellWidth / 2) + UI.BeltXOffset;
int beltToCellX = toCellStartX + 4 * UI.BeltXOffset;
int beltFromCellY = fromCellStartY + UI.BeltYOffset;
int beltToCellY = toCellStartY + UI.BeltYOffset / 2;
pWind->DrawLine(beltFromCellX, beltFromCellY, beltToCellX, beltToCellY); // Vertical line
// center of triangle :
int x = (beltFromCellX + beltToCellX) / 2;
int y = (beltFromCellY + beltToCellY) / 2;
//dimensions of triangle :
int triangleWidth = UI.CellWidth / 4;
int triangleHeight = UI.CellHeight / 4;
d = DOWN;
DrawTriangle(x, y, triangleHeight, triangleWidth, d, UI.BeltColor); // Horizontal triangle
}
}
// TODO: Draw the triangle at the center of the belt line pointing to the direction of the belt
}
//////////////////////////////////////////////////////////////////////////////////////////
void Output::DrawFlag(const CellPosition& cellPos) const
{
// TODO: Validate the cell position
if (!cellPos.IsValidCell()) {
return;
}
//implement here if there exist flag in the same cell so return:
//Only one flag can exist on the grid
// Get the X and Y coordinates of the start point of the cell (its upper left corner)
int cellStartX = GetCellStartX(cellPos);
int cellStartY = GetCellStartY(cellPos);
// TODO: Draw the flag as a line with a triangle connected to it directed to right
// TODO: 1. Draw the flag pole (the line)
int flagPoleStartX = cellStartX + UI.CellWidth / 2;
int flagPoleStartY = cellStartY + UI.CellHeight / 5;
int flagPoleEndY = cellStartY + (7 * UI.CellHeight) / 10;
pWind->SetPen(WHITE, 3);
pWind->DrawLine(flagPoleStartX, flagPoleStartY, flagPoleStartX, flagPoleEndY, FRAME);
// Draw the triangle :
// identfiy the vertices of the triangle:
int x1 = flagPoleStartX; int y1 = flagPoleStartY;
int x2 = flagPoleStartX; int y2 = cellStartY + (2 * UI.CellHeight) / 5;
int x3 = cellStartX + (3 * UI.CellWidth) / 4; int y3 = cellStartY + (3 * UI.CellHeight) / 10;
//
pWind->SetPen(RED, 1);
pWind->SetBrush(RED);
pWind->DrawTriangle(x1, y1, x2, y2, x3, y3, FILLED);
}
void Output::DrawRotatingGear(const CellPosition& cellPos, bool clockwise) const
{
// Step 1: upload the RotatingGear image:
string gearImage;
if (clockwise) {
gearImage = "images\\Clock.jpg";
}
else {
gearImage = "images\\C Clock.jpg";
}
// Step 2: draw the RotatingGear image in the cell:
int imagewidth = UI.CellWidth;
int imageheight = UI.CellHeight;
DrawImageInCell(cellPos, gearImage, imagewidth, imageheight);
}
void Output::DrawAntenna(const CellPosition& cellPos) const
{
//implement here if there exist another antenna so return:
//Only one antenna can exist on the grid
// Step 1: upload the antenna image:
string AntennaImage = "images\\Antenna.jpg";
// Step 2: draw the antenna image in the cell:
int antennaimagewidth = UI.CellWidth;
int antennaimageheight = UI.CellHeight;
DrawImageInCell(cellPos, AntennaImage, antennaimagewidth, antennaimageheight);
}
void Output::DrawWorkshop(const CellPosition& cellPos) const
{
// Step 1: upload the Workshop image:
string workshopImage = "images\\WorkShop.jpg";
// Step 2: draw the Workshop image in the cell:
int workshopimagewidth = UI.CellWidth;
int workshopimageheight = UI.CellHeight;
DrawImageInCell(cellPos, workshopImage, workshopimagewidth, workshopimageheight);
}
void Output::DrawDangerZone(const CellPosition& cellPos) const
{
// Step 1: Validate the cell position
if (!cellPos.IsValidCell()) {
return;
}
if (cellPos.GetCellNum() == 1) {
return;
}
DrawCell(cellPos, RED);
}
void Output::DrawWaterPit(const CellPosition& cellPos) const
{
// Step 1: Validate the cell position
if (!cellPos.IsValidCell()) {
return;
}
if (cellPos.GetCellNum() == 1) {
return;
}
DrawCell(cellPos, DARKBLUE);
}
Output::~Output()
{
// deallocating the window object
delete pWind;
}