-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
875 lines (675 loc) · 24.7 KB
/
mainwindow.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
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
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <string>
#include <iostream>
#include "game.h"
#include "state.h"
#include "node.h"
#include "qpainter.h"
#include "monsters.h"
#include "QMessageBox"
#include "playercard.h"
#include "player.h"
#include "phaseobserver.h"
#include "subject.h"
#include "aggressivestrategy.h"
#include "popup.h"
#include "diceeffectobserver.h"
const int SIZE_OF_DECK = 8;
const int SIZE_OF_BOARD = 3;
int currentCard = 0;
Card deck[SIZE_OF_DECK];
Card board[SIZE_OF_BOARD];
Card *nextCard = &deck[0];
DeckOfCards doc(deck);
const int SHIFT = 50;
const int IMAGE_SIZE = 250;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
//Player data observer
Player *player = new Player;
PlayerCard *playerCard = new PlayerCard(player, ui);
Game *game = Game::getInstance();
for (int i = 0; i < game->getNumOfPlayers(); i++) {
Player *p = &game->getPlayers()[i];
playerCard->observe(p);
}
// Phase Observer
PhaseObserver *phaseObserver = new PhaseObserver(ui);
game->Attach(phaseObserver);
// Dice Effect Observer
DiceEffectObserver *diceEffectObserver = new DiceEffectObserver(this);
dr.Attach(diceEffectObserver);
for (int i = 0; i < 8; i++) {
rolls[i] = 0;
}
// Background Board
updateMap();
// Player Card
ui->victoryPointsLabel->setScaledContents(true);
string vplPath = "../KONY/res/Images/victoryPoints.png";
QPixmap vplPixmap = QPixmap (vplPath.c_str());
ui->victoryPointsLabel->setPixmap(vplPixmap);
ui->healthPointsLabel->setScaledContents(true);
string hplPath = "../KONY/res/Images/healthPoints.png";
QPixmap hplPixmap = QPixmap (hplPath.c_str());
ui->healthPointsLabel->setPixmap(hplPixmap);
ui->energyPointsLabel->setScaledContents(true);
string eplPath = "../KONY/res/Images/energyPoints.png";
QPixmap eplPixmap = QPixmap (eplPath.c_str());
ui->energyPointsLabel->setPixmap(eplPixmap);
// Create Tiles
Game::getInstance()->createTiles();
// Dice Labels
setDiceImage(ui->diceLabel1, 1);
setDiceImage(ui->diceLabel2, 2);
setDiceImage(ui->diceLabel3, 3);
setDiceImage(ui->diceLabel4, 4);
setDiceImage(ui->diceLabel5, 5);
setDiceImage(ui->diceLabel6, 6);
setDiceImage(ui->diceLabel7, 1);
setDiceImage(ui->diceLabel8, 2);
// Prepare StartupPhase
Game::getInstance()->Startup();
set8DiceEnabled(false);
doc.shuffleDeck(deck, SIZE_OF_DECK);
doc.initializeBoard(deck, board, nextCard, SIZE_OF_BOARD);
//dot.shuffleTiles(tileDeck, NUM_OF_TILES);
setCardImage(ui->cardLabel_1, board[0].displayId());
setCardImage(ui->cardLabel_2, board[1].displayId());
setCardImage(ui->cardLabel_3, board[2].displayId());
// If computer player is playing first
// Computer Player
int turn = game->getTurn();
Player *p = &game->getPlayers()[turn];
if (p->getPlayerType() != 0) {
p->getStrategy()->execute(game->getState());
game->advanceGame();
}
}
void MainWindow::setDiceImage(QLabel *label, int dice_roll) {
label->setScaledContents(true);
DiceRoll dr;
string diceName = dr.transform(dice_roll);
string path = "../KONY/res/Images/" + diceName + ".PNG";
QPixmap pixmap = QPixmap (path.c_str());
label->setPixmap(pixmap);
}
void MainWindow::setCardImage(QLabel *label, int id){
label->setScaledContents(true);
string cardName = std::to_string(id);
string cardPath = "../KONY/res/Images/cards/" + cardName + ".jpg";
QPixmap pixmap = QPixmap (cardPath.c_str());
label->setPixmap(pixmap);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_rollButton_clicked()
{
bool diceToRoll [8];
diceToRoll[0] = ui->diceCheckBox_1->isChecked();
diceToRoll[1] = ui->diceCheckBox_2->isChecked();
diceToRoll[2] = ui->diceCheckBox_3->isChecked();
diceToRoll[3] = ui->diceCheckBox_4->isChecked();
diceToRoll[4] = ui->diceCheckBox_5->isChecked();
diceToRoll[5] = ui->diceCheckBox_6->isChecked();
diceToRoll[6] = ui->diceCheckBox_7->isChecked();
diceToRoll[7] = ui->diceCheckBox_8->isChecked();
//DiceRoll dr;
dr.rollDice(diceToRoll, rolls);
log("-");
log("Rolls:");
string rollsString = "";
for (int i = 0; i < 8; i++) {
rollsString += dr.transform(rolls[i]) + " ";
}
log(rollsString);
// Dice Labels
setDiceImage(ui->diceLabel1, rolls[0]);
setDiceImage(ui->diceLabel2, rolls[1]);
setDiceImage(ui->diceLabel3, rolls[2]);
setDiceImage(ui->diceLabel4, rolls[3]);
setDiceImage(ui->diceLabel5, rolls[4]);
setDiceImage(ui->diceLabel6, rolls[5]);
setDiceImage(ui->diceLabel7, rolls[6]);
setDiceImage(ui->diceLabel8, rolls[7]);
int size = 8;
Game *game = Game::getInstance();
if (game->getState() == STARTUP_ROLL) { // Startup roll
// Count Attacks
// Save rolls in array
int attacks = 0;
for (int i = 0; i < size; i++) {
if (dr.transform(rolls[i]) == "Attack") {
attacks++;
}
}
log("Player " + to_string(game->getTurn()+1) + " rolled " + to_string(attacks) + " Attacks.");
game->registerStartupRoll(game->getTurn(), attacks);
game->advanceGame();
// Check if finished startup roll
if (game->getState()== STARTUP_LOCATION) {
log("-");
log("Player " + to_string(game->getTurn()+1) + " Has the most Attacks. They play First.");
lockUnlockUI();
fillMoveLocations();
}
} else if (game->getState() == ROLLING_DICE) { // Roll Dice
// Disable last 2 dice
rolls[6] = -1;
rolls[7] = -1;
// Dice Labels
setDiceImage(ui->diceLabel7, rolls[6]);
setDiceImage(ui->diceLabel8, rolls[7]);
set6DiceEnabled(true);
numberOfRolls++;
if (numberOfRolls == 3) {
// finish phase
game->advanceGame();
lockUnlockUI();
fillResolveDice();
}
}
}
void MainWindow::log(string str) {
QString qs;
string line = "----------------------------------------";
if (str == "-") {
qs.append(line.c_str());
} else {
qs.append(str.c_str());
}
ui->plainTextEdit->appendPlainText(qs);
}
void MainWindow::on_buyCards_clicked()
{
bool cardToBuy[3];
cardToBuy[0] = ui->cardCheckBox_1->isChecked();
cardToBuy[1] = ui->cardCheckBox_2->isChecked();
cardToBuy[2] = ui->cardCheckBox_3->isChecked();
int playerNumber = Game::getInstance()->getTurn();
for(int i = 0; i < SIZE_OF_BOARD; i++){
if(cardToBuy[i] == 1){
if(currentCard >= (SIZE_OF_DECK - SIZE_OF_BOARD)){
board[i].setId(0);
}
else{
if(Game::getInstance()->buyCard(playerNumber, board[i].getId(), board[i].getCost(), board[i].getVp(), board[i].getEnergy(), board[i].getHealth())){
doc.fillCard(board, i, nextCard);
currentCard++;
}
else{
log("not enough energy to buy cards");
}
}
}
}
setCardImage(ui->cardLabel_1, board[0].displayId());
setCardImage(ui->cardLabel_2, board[1].displayId());
setCardImage(ui->cardLabel_3, board[2].displayId());
}
void MainWindow::on_wipeBoard_clicked()
{
int playerNumber = Game::getInstance()->getTurn();
if(stoi(Game::getInstance()->getPlayerEnergy(playerNumber)) >= 2){
for(int i = 0; i < SIZE_OF_BOARD; i++){
if(currentCard >= (SIZE_OF_DECK - SIZE_OF_BOARD)){
board[i].setId(0);
}
else {
doc.fillCard(board, i, nextCard);
currentCard++;
}
}
Game::getInstance()->decreasePlayerEnergy(playerNumber);
}
setCardImage(ui->cardLabel_1, board[0].displayId());
setCardImage(ui->cardLabel_2, board[1].displayId());
setCardImage(ui->cardLabel_3, board[2].displayId());
}
void MainWindow::set6DiceEnabled(bool flag) {
ui->diceCheckBox_1->setEnabled(flag);
ui->diceCheckBox_2->setEnabled(flag);
ui->diceCheckBox_3->setEnabled(flag);
ui->diceCheckBox_4->setEnabled(flag);
ui->diceCheckBox_5->setEnabled(flag);
ui->diceCheckBox_6->setEnabled(flag);
}
void MainWindow::set8DiceEnabled(bool flag) {
set6DiceEnabled(flag);
ui->diceCheckBox_7->setEnabled(flag);
ui->diceCheckBox_8->setEnabled(flag);
}
void MainWindow::lockUnlockUI() {
State state = Game::getInstance()->getState();
int winner = -1;
switch (state) {
case STARTUP_LOCATION:
ui->rollButton->setEnabled(false);
ui->moveGroup->setEnabled(true);
break;
case ROLLING_DICE:
ui->finishTurnButton->setEnabled(false);
// Check if there's a winner
winner = Game::getInstance()->checkGameOver();
if (winner != -1) {
// show message
QMessageBox Msgbox;
string msg = "Game won by Player " + to_string(winner);
Msgbox.setText(QString(msg.c_str()));
Msgbox.exec();
return;
}
ui->moveGroup->setEnabled(false);
ui->rollButton->setEnabled(true);
set8DiceEnabled(false);
ui->diceCheckBox_7->setChecked(false);
ui->diceCheckBox_8->setChecked(false);
ui->diceLabel7->setEnabled(false);
ui->diceLabel8->setEnabled(false);
numberOfRolls = 0;
break;
case RESOLVING_DICE:
set6DiceEnabled(false);
check6Dice(true);
ui->rollButton->setEnabled(false);
ui->resolveGroup->setEnabled(true);
break;
case MOVING:
ui->resolveGroup->setEnabled(false);
ui->moveGroup->setEnabled(true);
fillMoveLocations();
break;
case BUYING_CARDS:
ui->cardsGroup->setEnabled(true);
ui->moveGroup->setEnabled(false);
break;
case FINISHING_TURN:
ui->cardsGroup->setEnabled(false);
ui->finishTurnButton->setEnabled(true);
break;
}
}
void MainWindow::fillMoveLocations() {
State state = Game::getInstance()->getState();
switch (state) {
case STARTUP_LOCATION: {
// Fill locations with less that two players
// Count players in each location
ui->locationCombo->clear();
int numOfRegions = Game::getInstance()->getMap()->getGraph()->getNumOfNodes();
for (int i = 0; i < numOfRegions; i++) {
if (Game::getInstance()->getMap()->getGraph()->nodes[i]->hasSubRegions()) {
continue;
}
if (Game::getInstance()->playersInRegion(i) == 2) {
continue;
}
string regionName = Game::getInstance()->getMap()->getGraph()->nodes[i]->getName();
ui->locationCombo->addItem(regionName.c_str());
}
break;
}
case MOVING: {
// Differentiate 4 cases
// 1. Must move to lower manhattan
// 2. Move anywhere (restrictions apply)
// 3. Advance in manhattan
// 4. No valid move(upper manhattan)
ui->locationCombo->clear();
Game *game = Game::getInstance();
int turn = game->getTurn();
int zone = game->getPlayers()[turn].getZone();
int rank = game->getPlayers()[turn].getRank();
int numOfRanks = game->getMap()->getSubgraph()->getNumOfNodes();
if (zone != 0 && game->isEmptyMainRegion()) { // Case 1
string mainRegion = game->getMap()->getGraph()->getNodes()[0]->getName();
string firstSubRegion = game->getMap()->getSubgraph()->getNodes()[0]->getName();
string location = mainRegion + " - " + firstSubRegion;
ui->locationCombo->addItem(QString(location.c_str()));
} else if (zone != 0 && !game->isEmptyMainRegion()) { // Case 2
Graph *graph = game->getMap()->getGraph();
Node **nodes = graph->getNodes();
for (int i = 1; i < graph->getNumOfNodes(); i++) {
string location = nodes[i]->getName();
ui->locationCombo->addItem(QString(location.c_str()));
}
} else if (zone == 0 && rank != numOfRanks - 1) { // Case 3
string mainRegion = game->getMap()->getGraph()->getNodes()[0]->getName();
string nextSubRegion = game->getMap()->getSubgraph()->getNodes()[rank+1]->getName();
string location = mainRegion + " - " + nextSubRegion;
ui->locationCombo->addItem(QString(location.c_str()));
} else { // Case 4
string mainRegion = game->getMap()->getGraph()->getNodes()[0]->getName();
string lastSubRegion = game->getMap()->getSubgraph()->getNodes()[numOfRanks-1]->getName();
string location = mainRegion + " - " + lastSubRegion;
ui->locationCombo->addItem(QString(location.c_str()));
}
break;
}
}
}
void MainWindow::on_moveButton_clicked()
{
State state = Game::getInstance()->getState();
if (state == STARTUP_LOCATION) { // Startup Location
Game* game = Game::getInstance();
int turn = game->getTurn();
string regionString = ui->locationCombo->currentText().toStdString();
int regionInt = game->getRegionNumberFromStr(regionString);
game->movePlayer(turn, regionInt);
log("-");
log("Player " + to_string(turn+1) + " Has moved to " + regionString);
game->advanceGame();
fillMoveLocations();
// Locations();
lockUnlockUI();
updateMap();
} else if (state == MOVING) { // Main game moving
string input = ui->locationCombo->currentText().toStdString();
// Differentiate 4 cases
// 1. Must move to lower manhattan
// 2. Move anywhere (restrictions apply)
// 3. Advance in manhattan
// 4. No valid move(upper manhattan)
Game *game = Game::getInstance();
int turn = game->getTurn();
Player player = game->getPlayers()[turn];
string playerName = game->getPlayerName(turn);
int zone = player.getZone();
int rank = player.getRank();
int numOfRanks = game->getMap()->getSubgraph()->getNumOfNodes();
if (zone != 0 && game->isEmptyMainRegion()) { // Case 1
game->getPlayers()[turn].setZone(0);
game->getPlayers()[turn].setRank(0);
} else if (zone != 0 && !game->isEmptyMainRegion()) { // Case 2
Graph *graph = game->getMap()->getGraph();
int zoneId = graph->getNodeNumberByName(input);
game->getPlayers()[turn].setZone(zoneId);
} else if (zone == 0 && rank != numOfRanks - 1) { // Case 3
game->getPlayers()[turn].setRank(rank+1);
} else { // Case 4
// Player stays in place
}
log ("Player " + playerName + " has moved to " + input + ".");
game->advanceGame();
lockUnlockUI();
updateMap();
}
}
void MainWindow::check6Dice(bool flag) {
ui->diceCheckBox_1->setChecked(flag);
ui->diceCheckBox_2->setChecked(flag);
ui->diceCheckBox_3->setChecked(flag);
ui->diceCheckBox_4->setChecked(flag);
ui->diceCheckBox_5->setChecked(flag);
ui->diceCheckBox_6->setChecked(flag);
}
void MainWindow::fillResolveDice() {
ui->resolveCombo->clear();
// Get dice type in a boolean
bool diceTally [6];
for (int i = 0; i < 6; i++) {
diceTally[i] = false;
}
for (int i = 0; i < 6; i++) {
if (rolls[i] == -1) continue;
int tallyIndex = rolls[i] - 1;
diceTally[tallyIndex] = true;
}
for (int i = 0; i < 6; i++) {
if (diceTally[i] == true) {
ui->resolveCombo->addItem(dr.transform(i+1).c_str());
}
}
}
void MainWindow::on_resolveButton_clicked()
{
// Get diceNumber
string diceToResolve = ui->resolveCombo->currentText().toStdString();
int diceId = 0;
for (int i = 1; i < 7; i++) {
if (dr.transform(i) == diceToResolve) {
diceId = i;
break;
}
}
// Get Number of Dice
int numOfDice = 0;
for (int i = 0; i < 6; i++) {
if (rolls[i] == diceId) {
numOfDice++;
rolls[i] = -1;
}
}
fillResolveDice();
log("-");
log("Resolving " + to_string(numOfDice) + " " + diceToResolve);
// Resolve Dice
Game *game = Game::getInstance();
// Special Case for tiles
if (dr.transform(diceId) == "Destruction") {
// Unlock Destruction
remainingDestruction = numOfDice;
fillTilesCombo();
if (ui->tileCombo->count() > 0) {
ui->tilesGroup->setEnabled(true);
ui->resolveGroup->setEnabled(false);
}
} else {
string resolveMessage = game->resolveDice(diceId, numOfDice, 0);
log(resolveMessage);
int turn = game->getTurn();
if(game->playersInRegion(0) == 1 && game->getPlayers()[turn].getZone() != 0){
// Someone has to make a choice in Manhattan
// Make sure it's not a computer
for (int i = 0; i < game->getNumOfPlayers(); i++) {
if (game->getPlayers()[i].getZone() == 0 && game->getPlayers()[i].getPlayerType() == 0) {
if(dr.transform(diceId) == "Attack"){
pu = new Popup(this);
pu->show();
}
}
}
}
// Check if finished resolving
if (ui->resolveCombo->count() == 0) { // Finished resolving
Game::getInstance()->advanceGame();
lockUnlockUI();
}
}
}
void MainWindow::fillTilesCombo() {
// Fill only tiles in borough that player can afford
ui->tileCombo->clear();
Game *game = Game::getInstance();
int turn = game->getTurn();
int zone = game->getPlayers()[turn].getZone();
DeckOfTiles *deckOfTiles = game->getDeckOfTiles();
int numOfTiles = deckOfTiles->getNumOfTiles();
Tile *tiles = deckOfTiles->getTiles();
// Add buildings tiles
for (int stack = 0; stack < 3; stack++) {
for (int i = 0; i < numOfTiles; i++) {
if (tiles[i].isDestoryed()) continue;
int activeSide = tiles[i].getActiveSide();
if (activeSide == 0) {
if (tiles[i].getStackNumber() == stack) {
if (remainingDestruction >= tiles[i].getSide(activeSide).getCost()) {
ui->tileCombo->addItem(tiles[i].getSide(activeSide).getDescription().c_str(), QVariant(i));
break;
}
}
}
}
}
// Add units tiles
for (int i = 0; i < numOfTiles; i++) {
if (tiles[i].isDestoryed()) continue;
int activeSide = tiles[i].getActiveSide();
if (activeSide == 1) {
if (remainingDestruction >= tiles[i].getSide(activeSide).getCost()) {
ui->tileCombo->addItem(tiles[i].getSide(activeSide).getDescription().c_str(), QVariant(i));
}
}
}
}
void MainWindow::updateMap() {
ui->backgroundLabel->setScaledContents(true);
string path = "../KONY/res/Images/Board.png";
QPixmap pixmap = QPixmap(path.c_str());
QPainter *paint = new QPainter(&pixmap);
Game *game = Game::getInstance();
Player *players = game->getPlayers();
int numberOfPlayers = game->getNumOfPlayers();
Node **graphNodes = game->getMap()->getGraph()->getNodes();
Node **subGraphNodes = game->getMap()->getSubgraph()->getNodes();
int graphSize = game->getMap()->getGraph()->getNumOfNodes();
int subGraphSize = game->getMap()->getSubgraph()->getNumOfNodes();
int *graphCounter = new int [graphSize];
int *subGraphCounter = new int [subGraphSize];
for (int i = 0; i < graphSize; i++) {
graphCounter[i] = 0;
}
for (int i = 0; i < subGraphSize; i++) {
subGraphCounter[i] = 0;
}
for (int i = 0; i < numberOfPlayers; i++) {
// getPhotoPath
// getCoordinates
Monsters monster = players[i].getMonster();
string monsterName = getNameFromMonster(monster);
string path = "../KONY/res/Images/Monster" + monsterName + ".jpg";
int zone = players[i].getZone();
if (zone == -1) continue;
int rank = players[i].getRank();
cout << "Player: " << i << " Zone: " << zone << " Rank: " << rank << endl;
int locX = graphNodes[zone]->loc_x;
int locY = graphNodes[zone]->loc_y;
if (zone == 0) {
locX = subGraphNodes[rank]->loc_x;
locY = subGraphNodes[rank]->loc_y;
}
if (locX == 0) continue;
// If there is another player: shift
if (zone != 0) {
if (graphCounter[zone] == 1) {
locX += 50;
locY += 50;
}
} else {
if (subGraphCounter[rank] == 1) {
locX += 50;
locY += 50;
}
}
paint->drawImage(QRect(locX, locY, IMAGE_SIZE, IMAGE_SIZE), QImage(path.c_str()));
// Update Counters
if (zone != 0) {
graphCounter[zone]++;
} else {
subGraphCounter[rank]++;
}
}
ui->backgroundLabel->setPixmap(pixmap);
}
void MainWindow::on_finishedCardsButton_clicked()
{
Game::getInstance()->advanceGame();
lockUnlockUI();
}
void MainWindow::on_finishTurnButton_clicked()
{
Game::getInstance()->advanceGame();
// reset dice images
for (int i = 0; i < 8; i++) {
rolls[i] = -1;
}
// Dice Labels
setDiceImage(ui->diceLabel1, rolls[0]);
setDiceImage(ui->diceLabel2, rolls[1]);
setDiceImage(ui->diceLabel3, rolls[2]);
setDiceImage(ui->diceLabel4, rolls[3]);
setDiceImage(ui->diceLabel5, rolls[4]);
setDiceImage(ui->diceLabel6, rolls[5]);
setDiceImage(ui->diceLabel7, rolls[6]);
setDiceImage(ui->diceLabel8, rolls[7]);
fillMoveLocations();
lockUnlockUI();
}
void MainWindow::on_showCards_clicked()
{
int playerNumber = Game::getInstance()->getTurn();
for(int i = 1; i <= SIZE_OF_DECK; i++){
if(Game::getInstance()->getCards(playerNumber, i)){
log(doc.showCard(deck, i, SIZE_OF_DECK));
}
}
}
void MainWindow::on_showTilesButton_clicked()
{
Game *game = Game::getInstance();
int numOfZones = game->getMap()->getGraph()->getNumOfNodes();
DeckOfTiles *deckOfTiles = game->getDeckOfTiles();
int numOfTiles = deckOfTiles->getNumOfTiles();
Tile *tiles = deckOfTiles->getTiles();
log("-");
log("Tiles");
for (int i = 0; i < numOfTiles; i++) {
int activeSide = tiles[i].getActiveSide();
string prefix = "";
if (activeSide == 1) {
prefix = "*";
}
if (tiles[activeSide].isDestoryed()) continue;
int zoneNumber = tiles[i].getZone();
string zoneName = game->getMap()->getGraph()->getNodes()[zoneNumber]->getName();
log(prefix + "Zone " + zoneName + " " + tiles[i].getSide(activeSide).getDescription());
}
log("-");
}
void MainWindow::on_destroyBuildingButton_clicked()
{
// Get Tile
Game *game = Game::getInstance();
int tileNumber = ui->tileCombo->currentData().toInt();
Tile t = game->getDeckOfTiles()->getTiles()[tileNumber];
int activeSide = t.getActiveSide();
Side side = t.getSide(activeSide);
// Apply effect to player
remainingDestruction -= side.getCost();
int trun = game->getTurn();
Player *p = &game->getPlayers()[trun];
p->setEnergy(p->getEnergy() + side.getEnergy());
p->setHealth(p->getHealth() + side.getHealth());
p->setVictoryPoints(p->getVictoryPoints() + side.getVictory());
// Flip/Destory tile
game->getDeckOfTiles()->getTiles()[tileNumber].flip();
log ("Player " + to_string(trun+1) + " Destroyed " + side.getDescription());
//updatePlayerCard();
// Advance Game
fillTilesCombo();
if (ui->tileCombo->count() == 0) {
ui->resolveGroup->setEnabled(true);
ui->tilesGroup->setEnabled(false);
// Check if finished resolving dice
if (ui->resolveCombo->count() == 0) { // Finished resolving
Game::getInstance()->advanceGame();
lockUnlockUI();
}
}
}
void MainWindow::upate6DiceLabels() {
// Dice Labels
setDiceImage(ui->diceLabel1, rolls[0]);
setDiceImage(ui->diceLabel2, rolls[1]);
setDiceImage(ui->diceLabel3, rolls[2]);
setDiceImage(ui->diceLabel4, rolls[3]);
setDiceImage(ui->diceLabel5, rolls[4]);
setDiceImage(ui->diceLabel6, rolls[5]);
}