-
Notifications
You must be signed in to change notification settings - Fork 0
/
gamedialog.cpp
159 lines (146 loc) · 2.95 KB
/
gamedialog.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
#include "gamedialog.h"
#include "ui_gamedialog.h"
#include<QDebug>
/**
* Constructor
*
* @param parent
*/
GameDialog::GameDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::GameDialog)
{
ui->setupUi(this);
ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Play!"));
}
/**
* Destructor
*
*/
GameDialog::~GameDialog()
{
delete ui;
}
/**
* Get the ai difficulty
*
* @return int
*/
int GameDialog::getDifficulty() {
return settings.difficulty;
}
/**
* Get the configured board size
*
* @return int
*/
int GameDialog::getBoardSize() {
return settings.boardSize;
}
/**
* Get the token which indicates who start the game
*
* @return CELL_STATE
*/
CELL_STATE GameDialog::getToken() {
if(this->ui->player1CheckBox->checkState()) {
return BLACK;
}
else {
return WHITE;
}
}
/**
* Get the name of player 1
*
* @return QString
*/
QString GameDialog::getPlayerName1() {
return playerName1;
}
/**
* Get the name of player 2
*
* @return QString
*/
QString GameDialog::getPlayerName2() {
return playerName2;
}
/**
* Enables the input for a second player if the game mode is player vs player
*
*/
void GameDialog::enablePlayer2Input() {
this->ui->playerName2Edit->setEnabled(true);
}
/**
* Save event
*
*/
void GameDialog::on_buttonBox_accepted()
{
playerName1 = this->ui->playerName1Edit->text();
playerName2 = this->ui->playerName2Edit->text();
}
/**
* Board size changed event (slider)
*
* @param value
*/
void GameDialog::on_boardSizeSlider_valueChanged(int value)
{
this->ui->boardSizeValueLabel->setText(QString::number(this->ui->boardSizeSlider->value()));
settings.boardSize = this->ui->boardSizeSlider->value();
}
/**
* AI difficulty box changed event
*
* @param index
*/
void GameDialog::on_difficultyBox_currentIndexChanged(int index)
{
switch(index) {
case 0:
settings.difficulty = 1;
break;
case 1:
settings.difficulty = 5;
break;
case 2:
settings.difficulty = 8;
break;
case 3:
settings.difficulty = 12;
break;
default:
break;
}
}
/**
* Player 1 checkbox clicked
*
* @param checked
*/
void GameDialog::on_player1CheckBox_clicked(bool checked)
{
if(!checked && !this->ui->player1CheckBox->checkState()) {
this->ui->player2CheckBox->setChecked(true);
}
else {
this->ui->player2CheckBox->setChecked(false);
}
}
/**
* Player 2 checkbox clicked
*
* @param checked
*/
void GameDialog::on_player2CheckBox_clicked(bool checked)
{
if(!checked && !this->ui->player2CheckBox->checkState()) {
this->ui->player1CheckBox->setChecked(true);
}
else {
this->ui->player1CheckBox->setChecked(false);
}
}