-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwidget.cpp
More file actions
executable file
·215 lines (151 loc) · 4.29 KB
/
widget.cpp
File metadata and controls
executable file
·215 lines (151 loc) · 4.29 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
#include "widget.h"
#include "ui_widget.h"
#include "enums_structs.h"
#include <QPropertyAnimation>
#include <QDebug>
#include <iostream>
Widget::Widget(QWidget *parent) :
QWidget(parent),ui(new Ui::Widget)
{
ui->setupUi(this);
ui->Server->hide();
ui->Client->hide();
connect(ui->radioclient,&QRadioButton::clicked,ui->Client,&QFrame::show);
connect(ui->radioclient,&QRadioButton::clicked,ui->Server,&QFrame::hide);
connect(ui->radioserver,SIGNAL(clicked()),ui->Server,SLOT(show()));
connect(ui->radioserver,SIGNAL(clicked()),ui->Client,SLOT(hide()));
// connect(ui->StratGame,SIGNAL(clicked()),this,SLOT(OpenGame()));
connect(ui->radioserver,&QPushButton::clicked, [this](){
auto animation = new QPropertyAnimation(ui->Server, "size");
animation->setDuration(800);
animation->setStartValue(QSize(0, 322));
animation->setEndValue(QSize(550, 322));
animation->start();
});
connect(ui->radioclient,&QRadioButton::clicked, [this](){
auto animation1 = new QPropertyAnimation(ui->Client, "size");
animation1->setDuration(800);
animation1->setStartValue(QSize(0, 321));
animation1->setEndValue(QSize(550, 321));
animation1->start();
});
connect(ui->ServerConnect,&QPushButton::clicked,this, &Widget::serverinit);
connect(ui->CLientConnect,&QPushButton::clicked,this, &Widget::clientinit);
}
void Widget::buildGameField(quint8 width,
quint8 height,
quint8 rounds_n,
QColor color1,
QColor color2,
std::string nick_name1,
std::string nick_name2){
game = new Dialog(this, width, height, rounds_n, 0);
game->show();
this->hide();
emit infoGameField(color1, color2, nick_name1,nick_name2);
}
void Widget::rewrite()
{
}
void Widget::serverinit()
{
QString port = ui->ServerPortText->text();
QString width = ui->width->text();
QString height = ui->height->text();
QString round = ui->Round->text();
QString nickname = ui->ServerName->text();
int beginner = -1;
if (ui->ServerFirst->isChecked())
{
beginner = 0;
}
else if (ui->RandomFirst->isChecked())
{
beginner = 2;
}
else if (ui->ClientFirst->isChecked())
{
beginner = 1;
}
else{
ui->output->append("Please Choose who goes First!");
}
spalten = width.toInt();
zeilen =height.toInt();
round_n= round.toInt();
QString color = ui->ServerColor->currentText();
QColor color_to_send;
if (color=="magenta") {
color_to_send = Qt::magenta;
}
else if (color=="blue") {
color_to_send = Qt::blue;
}
else if (color=="green") {
color_to_send = Qt::green;
}
else if (color=="yellow") {
color_to_send = Qt::yellow;
}
else if (color=="cyan") {
color_to_send = Qt::cyan;
}
else{
color_to_send = Qt::magenta;
}
emit startConnectionServer(port.toInt(), width.toInt(), height.toInt(), round.toInt(), beginner, nickname.toStdString(), color_to_send);
}
void Widget::clientinit()
{
QString host = ui->ClientIPText->text();
QString port = ui->ClientPortText-> text();
QString nickname = ui->ClientName->text();
QString color = ui->ClientColor->currentText();
QColor color_to_send;
if (color=="magenta") {
color_to_send = Qt::magenta;
}
else if (color=="blue") {
color_to_send = Qt::blue;
}
else if (color=="green") {
color_to_send = Qt::green;
}
else if (color=="yellow") {
color_to_send = Qt::yellow;
}
else if (color=="cyan") {
color_to_send = Qt::cyan;
}
else{
color_to_send = Qt::magenta;
}
emit startConnectionClient(host.toStdString(), port.toInt(), nickname.toStdString(), color_to_send);
}
void Widget::startGame(quint8 current_round, QString player_name, quint8 score1, quint8 score2, quint8 round_n)
{
emit tostartGameDIA(current_round, player_name,score1,score2,round_n);
}
void Widget::gameOver(Result result, bool more_rounds){
emit togameOverDIA(result, more_rounds);
}
void Widget::opponentReadyToContinue()
{
emit toopponentReadyToContinueDIA();
}
void Widget::netConnected()
{
}
void Widget::netFailedToConnect(quint8 status_code)
{
}
void Widget::displayMsg(QString msg){
emit chatMsg(msg);
}
void Widget::chatconnection(QString msg){
emit sendMsg(msg);
}
Widget::~Widget()
{
delete ui;
}