Skip to content
Snippets Groups Projects
Commit ffc9486b authored by s90532's avatar s90532
Browse files

simulation

parent dd492aab
No related branches found
No related tags found
No related merge requests found
Showing
with 282 additions and 69 deletions
hii/ICON/Screenshot 2024-06-12 142211.png

187 B

hii/ICON/fire-7559_256.gif

274 KiB

hii/ICON/gears-5875.gif

23.6 KiB

hii/ICON/ramencup1.png

5.38 KiB

hii/ICON/re1.png

20.7 KiB

hii/ICON/trimmed_image.png

336 B

......@@ -5,5 +5,10 @@
<file>re.png</file>
<file>Screenshot 2024-06-12 142211.png</file>
<file>re1 - Kopie.png</file>
<file>ICON/re1.png</file>
<file>ICON/fire-7559_256.gif</file>
<file>ICON/gears-5875.gif</file>
<file>ICON/ramencup1.png</file>
<file>ICON/trimmed_image.png</file>
</qresource>
</RCC>
......@@ -9,21 +9,68 @@ Dialog1::Dialog1(QWidget *parent)
, ui(new Ui::Dialog1)
{
ui->setupUi(this);
QPixmap bgPixmap(":/re1 - Kopie.png"); // Pfad zum Hintergrundbild
QPixmap bgPixmap(":/ICON/re1.png"); // Pfad zum Hintergrundbild
QLabel *background = new QLabel(this);
background->setPixmap(bgPixmap);
background->setGeometry(0, 0, bgPixmap.width(), bgPixmap.height());
// Fahrstuhl Label setzen
QPixmap balken(":/Screenshot 2024-06-12 142211.png");
// QPixmap balken(":/ramencup1.png");
QPixmap cup(":/ICON/trimmed_image.png");
fahrstuhlLabel = new QLabel(this);
cuplabel = new QLabel(this);
zahnradLabel = new QLabel(this);
gifLabel1 = new QLabel(this);
gifLabel = new QLabel(this);
//movie = new QMovie(this);
//fahrstuhlLabel->setText("Fahrstuhl");
fahrstuhlLabel->setPixmap(balken);
fahrstuhlLabel->setGeometry(236, 355, 130, 120); // Startposition
fahrstuhlLabel->raise();
fahrstuhlLabel->raise(); // Fahrstuhl Label vor dem Hintergrund anzeigen
cuplabel->setPixmap(cup);
cuplabel->setGeometry(20, 10, 130, 120);
cuplabel->raise();
zahnradLabel->setGeometry(450, 10, 130, 120);
zahnradLabel->raise();
zahnradLabel->hide();
gifLabel->setGeometry(450, 10, 130, 120);
gifLabel->raise();
gifLabel->hide();
gifLabel1->setGeometry(345, -15, 130, 120);
gifLabel1->raise();
gifLabel1->hide();
// Simulation initialisieren
simulation = new Simulation(fahrstuhlLabel, this);
//simulation->start();
movie = new QMovie(":/ICON/gears-5875.gif");
// Überprüfen, ob das QMovie-Objekt korrekt geladen wurde
if (!movie->isValid()) {
qDebug() << "Das QMovie-Objekt konnte nicht geladen werden. Überprüfen Sie den Pfad zur GIF-Datei.";
return;
}
// Weisen Sie das QMovie-Objekt dem QLabel zu und starten Sie die Animation
gifLabel->setMovie(movie);
movie1 = new QMovie(":/ICON/fire-7559_256.gif");
int newWidth = 60; // Neue Breite
int newHeight = 60; // Neue Höhe
movie1->setScaledSize(QSize(newWidth, newHeight));
// Überprüfen, ob das QMovie-Objekt korrekt geladen wurde
if (!movie1->isValid()) {
qDebug() << "Das QMovie-Objekt konnte nicht geladen werden. Überprüfen Sie den Pfad zur GIF-Datei.";
return;
}
// Weisen Sie das QMovie-Objekt dem QLabel zu und starten Sie die Animation
gifLabel1->setMovie(movie1);
simulation = new Simulation(fahrstuhlLabel,cuplabel,zahnradLabel,gifLabel1,gifLabel,movie,movie1, this);
}
......
......@@ -26,6 +26,12 @@ private:
QPushButton *closeButton;
QLabel *fahrstuhlLabel;
Simulation *simulation;
QLabel *cuplabel;
QLabel *zahnradLabel;
QLabel *gifLabel1;
QLabel *gifLabel;
QMovie *movie;
QMovie *movie1;
......
......@@ -120,6 +120,8 @@ RESOURCES += \
ressource.qrc
DISTFILES += \
ICON/Screenshot 2024-06-12 142211.png \
ICON/Screenshot 2024-06-12 142211.png \
default.cfg \
../../../../../Pictures/Screenshots/Screenshot 2024-05-12 214014.png \
......
......@@ -7,24 +7,34 @@
#include <QRandomGenerator>
#include <QDebug>
Simulation::Simulation(QLabel *fahrstuhlLabel, QObject *parent)
: QObject(parent), fahrstuhlLabel(fahrstuhlLabel), aktuelleTemperatur(20.0), zustand(NACH_OBEN), aktuellesGewicht(0.0),logik(steuerung())
Simulation::Simulation(QLabel *fahrstuhlLabel, QLabel *cuplabel, QLabel *zahnradLabel,QLabel *gifLabel1 ,QLabel *gifLabel, QMovie *movie, QMovie *movie1, QObject *parent)
: QObject(parent), cuplabel(cuplabel), fahrstuhlLabel(fahrstuhlLabel), zahnradLabel(zahnradLabel),gifLabel1(gifLabel1),gifLabel(gifLabel), movie(movie),movie1(movie1), aktuellesGewicht(0), aktuelleTemperatur(20.0), zustand(NACH_OBEN), bildToggle(false),logik(steuerung())
{
// Timer für Updates
timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, &Simulation::aktualisieren);
bildwechselTimer = new QTimer(this);
connect(bildwechselTimer, &QTimer::timeout, this, &Simulation::wechselBild);
zielX = fahrstuhlLabel->x();
zielY = fahrstuhlLabel->y();
zielCupX = cuplabel->x();
zielCupY = cuplabel->y();
zahnrad1 = QPixmap(":/rad1.png");
zahnrad2 = QPixmap(":/rad2png.png");
}
Simulation::~Simulation()
{
delete timer;
delete bildwechselTimer;
}
void Simulation::start()
{
timer->start(1000); // Aktualisierung alle 1 Sekunde
timer->start(100); // Aktualisierung alle 1 Sekunde
}
void Simulation::aktualisieren()
......@@ -37,36 +47,80 @@ void Simulation::aktualisieren()
// Fahrstuhl nach oben bewegen
logik.setzeZielEtage(4);
logik.hoch();
zielY -= 295;
//fahrstuhlLabel->move(fahrstuhlLabel->x(), fahrstuhlLabel->y() - 295);
if (lichtSensorAktiv(4))
{
zustand = WARTE_GEWICHT;
qDebug() << "Fahrstuhl hat 4. Etage erreicht.";
}
qDebug() << "Bewege nach oben";
zielX = fahrstuhlLabel->x();
zielY = fahrstuhlLabel->y() - 320;
schrittX = 0;
schrittY = -10;
nextState = WARTE_GEWICHT;
zustand = BEWEGEN;
break;
case WARTE_GEWICHT:
qDebug() << "WARTE_GEWICHT";
logik.bewegeFahrstuhl();
if (gewichtSchwelleÜberschritten())
logik.bewegeFahrstuhl();
{
zustand = ZU_WASSER;
qDebug() << "Gewichtsschwelle überschritten.";
//qDebug() << "Aktuelles Gewicht: " << aktuellesGewicht;
zielCupX = cuplabel->x() + 245;
zielCupY = cuplabel->y();
schrittCupX = 10;
schrittCupY = 0;
zustand = BEWEGEN;
nextState = ZU_WASSER;
}
break;
case ZU_WASSER:
fahrstuhlLabel->move(fahrstuhlLabel->x() + 90, fahrstuhlLabel->y() - 10); // Zu Position 1
zustand = WASSER_ERHITZEN;
qDebug() << "Fahrstuhl bewegt sich zur Wasserstation.";
qDebug() << "Gewichtsschwelle überschritten!";
qDebug() << "Bewege zu Wasser";
zielX = fahrstuhlLabel->x();
zielY = fahrstuhlLabel->y() + 20;
schrittX =0;
schrittY = 1;
zielCupX = cuplabel->x();
zielCupY = cuplabel->y() + 20;
schrittCupX =0;
schrittCupY = 1;
nextState = ZU_WASSER2;
zustand = BEWEGEN;
break;
case ZU_WASSER2:
qDebug() << "Bewege zu Wasser";
zielX = fahrstuhlLabel->x() +90;
zielY = fahrstuhlLabel->y();
schrittX =10;
schrittY = 0;
zielCupX = cuplabel->x()+90;
zielCupY = cuplabel->y() ;
schrittCupX =10;
schrittCupY = 0;
nextState = WASSER_ERHITZEN;
zustand = BEWEGEN;
break;
case WASSER_ERHITZEN:
gifLabel1->show(); // Zeige das Label, das das GIF enthält
movie1->start();
gifLabel->show(); // Zeige das Label, das das GIF enthält
movie->start();
//bildwechselTimer->start(100);
if (temperaturErreicht())
{
zustand = WASSER_AUSGEBEN;
qDebug() << "Wassertemperatur erreicht.";
movie->stop();
gifLabel->hide();
movie1->stop();
gifLabel1->hide(); // Zeige das Label, das das GIF enthält
//zahnradLabel->hide();
}
break;
......@@ -80,90 +134,163 @@ void Simulation::aktualisieren()
case NACH_LINKS:
logik.links();
fahrstuhlLabel->move(fahrstuhlLabel->x() + 90, fahrstuhlLabel->y()); // Zu Position 2
zustand = ZURUECK_START;
qDebug() << "Fahrstuhl bewegt sich nach links.";
qDebug() << "Bewege nach links";
zielX = fahrstuhlLabel->x() - 90;
zielY = fahrstuhlLabel->y();
schrittX = -10;
schrittY = 0;
zielCupX = cuplabel->x() - 90;
zielCupY = cuplabel->y();
schrittCupX = -10;
schrittCupY = 0;
nextState = ZURUECK_START;
zustand = BEWEGEN;
break;
case ZURUECK_START:
logik.runter();
fahrstuhlLabel->move(fahrstuhlLabel->x(), fahrstuhlLabel->y() + 305);
zustand = NACH_RECHTS;
qDebug() << "Fahrstuhl bewegt sich zurück zur Startposition.";
qDebug() << "Bewege zurück zum Start";
zielX = fahrstuhlLabel->x();
zielY = fahrstuhlLabel->y() + 300;
schrittX = 0;
schrittY = 10;
zielCupX = cuplabel->x();
zielCupY = cuplabel->y() + 300;
schrittCupX = 0;
schrittCupY = 10;
nextState = NACH_RECHTS;
zustand = BEWEGEN;
break;
case NACH_RECHTS:
logik.rechts();
fahrstuhlLabel->move(fahrstuhlLabel->x() + 90, fahrstuhlLabel->y()); // Zu Position 3
zustand = NACH_Oben;
qDebug() << "Fahrstuhl bewegt sich nach rechts.";
qDebug() << "Bewege nach rechts";
zielX = fahrstuhlLabel->x() + 90;
zielY = fahrstuhlLabel->y();
schrittX = 10;
schrittY = 0;
zielCupX = cuplabel->x() + 90;
zielCupY = cuplabel->y();
schrittCupX = 10;
schrittCupY = 0;
nextState = NACH_Oben;
zustand = BEWEGEN;
break;
case NACH_Oben:
logik.hoch();
fahrstuhlLabel->move(fahrstuhlLabel->x(), fahrstuhlLabel->y() - 80);
zustand = ZU_ENDE;
qDebug() << "Fahrstuhl bewegt sich nach oben.";
zielX = fahrstuhlLabel->x();
zielY = fahrstuhlLabel->y() - 90;
schrittX = 0;
schrittY = -10;
zielCupX = cuplabel->x();
zielCupY = cuplabel->y() - 90;
schrittCupX = 0;
schrittCupY = -10;
nextState = ZU_ENDE;
zustand = BEWEGEN;
break;
case ZU_ENDE:
fahrstuhlLabel->move(fahrstuhlLabel->x(), fahrstuhlLabel->y());
qDebug() << "Simulation beendet.";
qDebug() << "Simulation beendet";
timer->stop();
break;
case BEWEGEN:
int currentX = fahrstuhlLabel->x();
int currentY = fahrstuhlLabel->y();
int currentCupX = cuplabel->x();
int currentCupY = cuplabel->y();
bool fahrstuhlBewegt = false;
bool cupBewegt = false;
if ((schrittX != 0 && currentX != zielX) || (schrittY != 0 && currentY != zielY))
{
if (schrittX != 0)
currentX += schrittX;
if (schrittY != 0)
currentY += schrittY;
fahrstuhlLabel->move(currentX, currentY);
fahrstuhlBewegt = true;
if ((schrittX != 0 && ((schrittX > 0 && currentX >= zielX) || (schrittX < 0 && currentX <= zielX))) ||
(schrittY != 0 && ((schrittY > 0 && currentY >= zielY) || (schrittY < 0 && currentY <= zielY))))
{
fahrstuhlLabel->move(zielX, zielY);
schrittX = 0;
schrittY = 0;
}
}
// Lichtsensor Implementierung
if ((schrittCupX != 0 && currentCupX != zielCupX) || (schrittCupY != 0 && currentCupY != zielCupY))
{
if (schrittCupX != 0)
currentCupX += schrittCupX;
if (schrittCupY != 0)
currentCupY += schrittCupY;
cuplabel->move(currentCupX, currentCupY);
cupBewegt = true;
if ((schrittCupX != 0 && ((schrittCupX > 0 && currentCupX >= zielCupX) || (schrittCupX < 0 && currentCupX <= zielCupX))) ||
(schrittCupY != 0 && ((schrittCupY > 0 && currentCupY >= zielCupY) || (schrittCupY < 0 && currentCupY <= zielCupY))))
{
cuplabel->move(zielCupX, zielCupY);
schrittCupX = 0;
schrittCupY = 0;
}
}
if (!fahrstuhlBewegt && !cupBewegt)
{
zustand = nextState;
}
break;
}
}
bool Simulation::lichtSensorAktiv(int etage)
{
// Simulierte Lichtsensor-Logik
int lichtIntensitaet = QRandomGenerator::global()->bounded(10); // Simuliert Lichtintensität zwischen 0 und 10
qDebug() << "Lichtintensität: " << lichtIntensitaet;
int lichtIntensitaet = QRandomGenerator::global()->bounded(10);
return lichtIntensitaet > 0;
}
// Gewichtssensor Implementierung
bool Simulation::gewichtSchwelleÜberschritten()
{
if (aktuellesGewicht < Gewichtsschwelle)
{
aktuellesGewicht += 40.0;
qDebug() << "Aktuelles Gewicht: " << aktuellesGewicht;
aktuellesGewicht += 20.0;
}
return aktuellesGewicht >= Gewichtsschwelle;
}
// Temperatursensor Implementierung
bool Simulation::temperaturErreicht()
{
if (aktuelleTemperatur < zielTemperatur)
{
aktuelleTemperatur += 10.0;
qDebug() << "Aktuelle Temperatur: " << aktuelleTemperatur;
aktuelleTemperatur += 2.5;
}
return aktuelleTemperatur >= zielTemperatur;
}
void Simulation::bewegeInSchritten(int zielX, int zielY)
void Simulation::wechselBild()
{
int schrittGroesse = 5; // Größe der Schritte
int aktuelleX = fahrstuhlLabel->x();
int aktuelleY = fahrstuhlLabel->y();
if (aktuelleX != zielX) {
if (aktuelleX < zielX) {
fahrstuhlLabel->move(aktuelleX + schrittGroesse, aktuelleY);
} else {
fahrstuhlLabel->move(aktuelleX - schrittGroesse, aktuelleY);
}
if (bildToggle)
{
zahnradLabel->setPixmap(zahnrad1);
}
if (aktuelleY != zielY) {
if (aktuelleY < zielY) {
fahrstuhlLabel->move(aktuelleX, aktuelleY + schrittGroesse);
} else {
fahrstuhlLabel->move(aktuelleX, aktuelleY - schrittGroesse);
}
else
{
zahnradLabel->setPixmap(zahnrad2);
}
zahnradLabel->update();
bildToggle = !bildToggle;
}
......@@ -6,39 +6,65 @@
#include <QLabel>
#include <QTimer>
#include "fahrstuhl.h"
#include <QMovie>
class Simulation : public QObject
{
Q_OBJECT
public:
Simulation(QLabel *fahrstuhlLabel, QObject *parent = nullptr);
Simulation(QLabel *fahrstuhlLabel, QLabel *cuplabel, QLabel *zahnradLabel,QLabel *gifLabel1 ,QLabel *gifLabel, QMovie *movie,QMovie *movie1, QObject *parent = nullptr);
~Simulation();
void start();
private slots:
void aktualisieren();
void wechselBild();
private:
QLabel *cuplabel;
QLabel *fahrstuhlLabel;
QLabel *zahnradLabel;
QLabel *gifLabel1;
QLabel *gifLabel;
QMovie *movie;
QMovie *movie1;
QTimer *timer;
QTimer *bildwechselTimer;
bool bildToggle;
double aktuelleTemperatur;
double aktuellesGewicht;
const double Gewichtsschwelle =200.0;
const double zielTemperatur =100.0;
enum Zustand { NACH_OBEN, WARTE_GEWICHT, ZU_WASSER, WASSER_ERHITZEN, WASSER_AUSGEBEN,NACH_LINKS, ZURUECK_START,NACH_RECHTS,NACH_Oben, ZU_ENDE } zustand;
enum Zustand { NACH_OBEN, WARTE_GEWICHT, ZU_WASSER,ZU_WASSER2, WASSER_ERHITZEN, WASSER_AUSGEBEN,NACH_LINKS, ZURUECK_START,NACH_RECHTS,NACH_Oben, ZU_ENDE, BEWEGEN} zustand;
int zielX;
/* int zielX;
int zielY;
void bewegeInSchritten(int zielX, int zielY);
*/
// Sensorfunktionen
bool lichtSensorAktiv(int etage);
bool gewichtSchwelleÜberschritten();
bool temperaturErreicht();
Fahrstuhl logik;
int zielX;
int zielY;
int startX;
int startY;
int schrittX;
int schrittY;
int zielCupX, zielCupY;
int schrittCupX, schrittCupY;
Zustand nextState;
Zustand nextState1;
void bewegeInSchritten(int zielX, int zielY);
QPixmap zahnrad1;
QPixmap zahnrad2;
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment