Segmentation fault

This commit is contained in:
2023-12-26 18:10:52 +01:00
parent ac7411aa58
commit 2418aafa97
5 changed files with 101 additions and 20 deletions

48
app.cpp
View File

@@ -1,12 +1,14 @@
#include "app.h"
App::App() {
st.connectRequest("sdi.hevs.ch", 61614, "/", "sdi10", "809c02f36becb0868da98761fe3209f6");
st.sendRequest("/topic/sdi10.gem.command", "right");
st.subscribeRequest("/topic/sdi10.gem.field", 1);
App::App(Stomp* st) {
st_ = st;
st_->connectRequest("sdi.hevs.ch", 61614, "/", "sdi10", "809c02f36becb0868da98761fe3209f6");
st_->sendRequest("/topic/sdi10.gem.command", "right");
st_->subscribeRequest("/topic/sdi10.gem.field", 1);
}
void App::connectConfirmation(bool success, int version) {
void App::connectConfirmation(bool success, QString version) {
}
@@ -15,11 +17,14 @@ void App::sendConfirmation(bool success) {
}
void App::subscribeConfirmation(bool success) {
st.sendRequest("/topic/sdi10.gem.command", "up");
st_->sendRequest("/topic/sdi10.gem.command", "up");
}
void App::receiveIndication(int id, QString destination, QString body) {
//qDebug() << "Indication " << id << " : " << destination << Qt::endl << body << Qt::endl;
if(destination.contains("field")){
fillField(body);
}
}
void App::disconnectConfirmation() {
@@ -29,3 +34,32 @@ void App::disconnectConfirmation() {
void App::disconnectIndication() {
}
void App::addGem(int x, int y, int pts) {
Gem g;
g.x = x;
g.y = y;
g.pts = pts;
gems_.append(g);
}
void App::fillField(QString body) {
static int x = 0;
static int y = 0;
for(int i = 0; i<body.length(); i++) {
const QChar c = body.at(i);
if(c == 'g') addGem(x, y, 100);
if(c == 'G') addGem(x, y, 250);
if(c == 'D') addGem(x, y, 500);
if(c == 'Y') {
myVehicle_.x = x;
myVehicle_.y = y;
myVehicle_.me = true;
}
if(c == '\n') {
y++;
x = 0;
}
x++;
}
}