finish mandatory part of the lab
This commit is contained in:
		| @@ -3,7 +3,8 @@ project(ProtocolDeveloppement) | ||||
|  | ||||
| set(CMAKE_CXX_STANDARD 14) | ||||
|  | ||||
| set(CMAKE_PREFIX_PATH "/Qt/6.5.0/android_arm64_v8a/lib/cmake") | ||||
| #set(CMAKE_PREFIX_PATH "/Qt/6.5.0/android_arm64_v8a/lib/cmake") | ||||
| set(CMAKE_PREFIX_PATH "D:/programme/Qt/6.5.0/mingw_64/lib/cmake") | ||||
|  | ||||
|  | ||||
| find_package(Qt6Widgets REQUIRED) | ||||
| @@ -13,6 +14,8 @@ find_package(Qt6Gui REQUIRED) | ||||
| add_executable(${PROJECT_NAME} | ||||
|         main.cpp | ||||
|         stompframe.cpp | ||||
|         stomp.cpp | ||||
|         app.cpp | ||||
| ) | ||||
|  | ||||
| link_directories( ${PCL_LIBRARY_DIRS} ) | ||||
|   | ||||
							
								
								
									
										38
									
								
								app.cpp
									
									
									
									
									
								
							
							
						
						
									
										38
									
								
								app.cpp
									
									
									
									
									
								
							| @@ -25,6 +25,7 @@ void App::receiveIndication(int id, QString destination, QString body) { | ||||
|     if(destination.contains("field")){ | ||||
|         fillField(body); | ||||
|     } | ||||
|     computeMove(); | ||||
| } | ||||
|  | ||||
| void App::disconnectConfirmation() { | ||||
| @@ -40,26 +41,51 @@ void App::addGem(int x, int y, int pts) { | ||||
|     g.x = x; | ||||
|     g.y = y; | ||||
|     g.pts = pts; | ||||
|     g.relativePts = computeRelativePts(g); | ||||
|     gems_.append(g); | ||||
| } | ||||
|  | ||||
| void App::printGem() { | ||||
|     for (Gem g: gems_) { | ||||
|         qDebug() << g.x << ":" << g.y << " - " << g.pts << Qt::endl; | ||||
|     } | ||||
| } | ||||
|  | ||||
| void App::fillField(QString body) { | ||||
|     static int x = 0; | ||||
|     static int y = 0; | ||||
|     int x = 0; | ||||
|     int y = 0; | ||||
|     gems_.clear(); | ||||
|     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 == 'g') addGem(x, y, 100); | ||||
|         if(c == 'G') addGem(x, y, 250); | ||||
|         if(c == 'D') addGem(x, y, 500); | ||||
|         if(c == '\n') { | ||||
|             y++; | ||||
|             x = 0; | ||||
|         } else { | ||||
|             x++; | ||||
|         } | ||||
|         x++; | ||||
|     } | ||||
| } | ||||
|  | ||||
| QVector2D App::computeRelativePts(Gem g) { | ||||
|     QVector2D v = QVector2D(myVehicle_.x, myVehicle_.y) - QVector2D(g.x, g.y); | ||||
| } | ||||
|  | ||||
| void App::computeMove() { | ||||
|     Gem myGem; | ||||
|     for(Gem g : gems_) { | ||||
|         if(g.pts > myGem.pts) myGem = g; | ||||
|     } | ||||
|     if(myGem.x>myVehicle_.x) st_->sendRequest("/topic/sdi10.gem.command", "right"); | ||||
|     else if(myGem.x<myVehicle_.x) st_->sendRequest("/topic/sdi10.gem.command", "left"); | ||||
|     else if(myGem.y>myVehicle_.y) st_->sendRequest("/topic/sdi10.gem.command", "down"); | ||||
|     else if(myGem.y<myVehicle_.y) st_->sendRequest("/topic/sdi10.gem.command", "up"); | ||||
| } | ||||
|  | ||||
|   | ||||
							
								
								
									
										5
									
								
								app.h
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								app.h
									
									
									
									
									
								
							| @@ -4,6 +4,7 @@ | ||||
| #include <QObject> | ||||
| #include "interface/iStompObserver.h" | ||||
| #include "stomp.h" | ||||
| #include <QVector2D> | ||||
|  | ||||
| class App : public QObject, public interface::iStompObserver { | ||||
| public: | ||||
| @@ -26,6 +27,7 @@ private: | ||||
|         int x; | ||||
|         int y; | ||||
|         int pts; | ||||
|         QVector2D relativePts; | ||||
|     } Gem; | ||||
|  | ||||
|     typedef struct { | ||||
| @@ -37,7 +39,10 @@ private: | ||||
|     QVector<Gem> gems_; | ||||
|     Vehicle myVehicle_; | ||||
|     void addGem(int x, int y, int pts); | ||||
|     void printGem(); | ||||
|     void fillField(QString body); | ||||
|     QVector2D computeRelativePts(Gem g); | ||||
|     void computeMove(); | ||||
|  | ||||
| }; | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user