-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
166 lines (141 loc) · 4.33 KB
/
mainwindow.cpp
File metadata and controls
166 lines (141 loc) · 4.33 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
#include "mainwindow.h"
#include "guiplayervertical.h"
#include "guiplayerhorizontal.h"
#include "player.h"
#include <QApplication>
#include <QMenuBar>
#include <QMenu>
#include <QAction>
#include <iostream>
#include <string>
using namespace std;
MainWindow::MainWindow() : QMainWindow()
{
setGeometry( 50, 50, 758, 615 );
//Display the board in the central widget
centralWidget = new CentralWidget();
setCentralWidget( centralWidget );
QMenuBar *menubar = menuBar();
QMenu *file = new QMenu("File", this);
menubar->addMenu(file);
QAction *newgameAction = new QAction("New Game", this);
file->addAction(newgameAction);
connect(newgameAction, SIGNAL(triggered()), this, SLOT(startGame()));
QAction *exitAction = new QAction("Exit", this);
file->addAction(exitAction);
connect(exitAction, SIGNAL(triggered()), QApplication::instance(), SLOT(quit()));
//Create the roll button for the board.
rollButton = new QPushButton( centralWidget );
rollButton->setText("ROLL");
rollButton->setGeometry(98, 405, 90, 40);
connect(rollButton, SIGNAL(pressed()), this, SLOT(rollDie()));
buyrentButton = new QPushButton( centralWidget );
buyrentButton->setText("BUY / UPGRADE");
buyrentButton->setGeometry(198, 405, 90, 40);
connect(buyrentButton, SIGNAL(pressed()), this, SLOT(buyOrRent()));
endButton = new QPushButton( centralWidget );
endButton->setText("END TURN");
endButton->setGeometry(298, 405, 90, 40);
connect(endButton, SIGNAL(pressed()), this, SLOT(endTurn()));
resignButton = new QPushButton( centralWidget );
resignButton->setText("RESIGN");
resignButton->setGeometry(398, 405, 90, 40);
connect(resignButton, SIGNAL(pressed()), this, SLOT(resign()));
this->show();
for(int i = 0; i < 4; i++)
guiPlayers[i] = NULL;
rollButton->setEnabled(false);
buyrentButton->setEnabled(false);
endButton->setEnabled(false);
resignButton->setEnabled(false);
}
void MainWindow::startGame()
{
if (b != NULL)
delete b;
b = new Board();
//Create the 4 players
int numPlayers = b->getNumPlayers();
for(int i = 0; i < 4; i++)
if(guiPlayers[i] != NULL)
{
removeDockWidget(guiPlayers[i]);
guiPlayers[i] = NULL;
}
//Player 1 is at the bottom. 2 at the left. 3 on top. 4 on the right
//Create the GUIPlayers
for(int i = 0; i < numPlayers; i++)
{
Player *p = b->getPlayer(i);
if(i % 2 == 0)
guiPlayers[i] = new GUIPlayerHorizontal(p);
else
guiPlayers[i] = new GUIPlayerVertical(p);
}
addDockWidget( Qt::BottomDockWidgetArea, guiPlayers[0] );
addDockWidget( Qt::LeftDockWidgetArea, guiPlayers[1] );
if(numPlayers > 2)
addDockWidget( Qt::TopDockWidgetArea, guiPlayers[2] );
if(numPlayers > 3)
addDockWidget( Qt::RightDockWidgetArea, guiPlayers[3] );
rollButton->setEnabled(true);
buyrentButton->setEnabled(false);
endButton->setEnabled(false);
resignButton->setEnabled(true);
drawLocation();
}
void MainWindow::drawLocation()
{
centralWidget->drawPieces(b->getAllPlayers(), b->getNumPlayers());
for(int i = 0; i < b->getNumPlayers(); i++)
guiPlayers[i]->setMoney(b->getPlayer(i)->getMoney());
}
void MainWindow::rollDie()
{
b->roll();
drawLocation();
b->doAutomaticActions();
drawLocation();
rollButton->setEnabled(false);
if(b->hasAction())
buyrentButton->setEnabled(true);
else
buyrentButton->setEnabled(false);
endButton->setEnabled(true);
resignButton->setEnabled(true);
}
void MainWindow::endTurn()
{
bool isNotFinished = b->nextPerson();
if(isNotFinished)
{
rollButton->setEnabled(true);
resignButton->setEnabled(true);
}
else
{
rollButton->setEnabled(false);
resignButton->setEnabled(false);
}
buyrentButton->setEnabled(false);
endButton->setEnabled(false);
drawLocation();
}
void MainWindow::resign()
{
b->shouldResign();
rollButton->setEnabled(false);
buyrentButton->setEnabled(false);
endButton->setEnabled(true);
resignButton->setEnabled(false);
drawLocation();
}
void MainWindow::buyOrRent()
{
b->selectBuyOrUpgrade();
rollButton->setEnabled(false);
buyrentButton->setEnabled(false);
endButton->setEnabled(true);
resignButton->setEnabled(true);
drawLocation();
}