Skip to content

Commit

Permalink
2.0 Release Candidate.
Browse files Browse the repository at this point in the history
  • Loading branch information
Harinlen committed Jun 5, 2015
1 parent 53b5908 commit f981372
Show file tree
Hide file tree
Showing 14 changed files with 183 additions and 85 deletions.
2 changes: 0 additions & 2 deletions Robot.pro
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ win32
macx
{
ICON = icon.icns
QMAKE_CXXFLAGS -= -O2
QMAKE_CXXFLAGS += -O3
}

SOURCES += \
Expand Down
35 changes: 24 additions & 11 deletions about.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#include "about.h"

#include <QDebug>

void About::showAbout(QWidget *parent)
{
QScopedPointer<About> aboutWindow(new About(parent));
Expand All @@ -31,29 +33,40 @@ void About::showAbout(QWidget *parent)
About::About(QWidget *parent) :
QDialog(parent)
{
setFixedSize(325, 356);
setWindowTitle(tr("About Robot Emulator"));
//Set the main layout.
QBoxLayout *mainLayout=new QBoxLayout(QBoxLayout::TopToBottom,
this);
mainLayout->setContentsMargins(20,20,20,20);
mainLayout->setSpacing(15);
setLayout(mainLayout);

QLabel *icon=new QLabel(this);
icon->setPixmap(QPixmap("://res/icon.png"));
icon->setFixedSize(256, 256);
icon->setScaledContents(true);
mainLayout->addWidget(icon, 1, Qt::AlignCenter);
mainLayout->addWidget(new QLabel(tr("Robot Emulator"), this),
QLabel *label=new QLabel(this);
label->setPixmap(QPixmap("://res/icon.png"));
label->setFixedSize(128, 128);
label->setScaledContents(true);
mainLayout->addWidget(label, 1, Qt::AlignCenter);
label=new QLabel(tr("Robot Emulator"), this);
QFont labelFont=label->font();
labelFont.setBold(true);
label->setFont(labelFont);
mainLayout->addWidget(label,
0,
Qt::AlignHCenter);
mainLayout->addWidget(new QLabel(tr("New robot simulation experience")),
0,
Qt::AlignHCenter);
mainLayout->addWidget(new QLabel(QApplication::applicationVersion(), this),

mainLayout->addWidget(new QLabel(tr("Emulator version ")+
QApplication::applicationVersion(),
this),
0,
Qt::AlignHCenter);
QLabel *author=new QLabel(this);
author->setAlignment(Qt::AlignHCenter);
author->setText(tr("Author:\n"
"Haolei Ye, 1120132191, Class: 08111302\n"
"Han Wang, 1120132065, Class: 08211301\n"
"Quanquan Li, 1120132192, Class: 08211302\n"));
author->setText(tr("Haolei Ye, Han Wang, and Quanquan Li\n"
"All rights reserved."));
mainLayout->addWidget(author,
0,
Qt::AlignHCenter);
Expand Down
24 changes: 17 additions & 7 deletions enemy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,13 @@ void Enemy::setTarget(const QPointF &target)
m_target = target;
}

void Enemy::moveOneStep()
QPointF Enemy::nextStep(bool &reachTarget)
{
QLineF routine(m_pos, m_target);
if(routine.length()<0.9)
{
//The enemy reach the target point.
return;
}
setPos(routine.pointAt(1/routine.length()));
reachTarget=(routine.length()<0.9);
return routine.pointAt(1/routine.length());
}

bool Enemy::destory() const
{
return m_destory;
Expand All @@ -67,4 +64,17 @@ void Enemy::setDestory(bool destory)
m_destory = destory;
}

bool Enemy::m_missionComplete=false;

bool Enemy::missionComplete()
{
return m_missionComplete;
}

void Enemy::setMissionComplete(bool missionAccept)
{
m_missionComplete = missionAccept;
}



19 changes: 17 additions & 2 deletions enemy.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ class Enemy : public RobotBase
static void setTarget(const QPointF &target);

/*!
* \brief Ask the enemy move one step to the target point.
* \brief Get the next step of the enemy.
* \return The next step of the enemy.
*/
void moveOneStep();
QPointF nextStep(bool &reachTarget);

/*!
* \brief Whether this enemy is destoried by robot.
Expand All @@ -75,8 +76,22 @@ class Enemy : public RobotBase
*/
void setDestory(bool destory);

/*!
* \brief Get the enemy mission complete status.
* \return The enemy mission complete status.
*/
static bool missionComplete();

/*!
* \brief Set the enemy mission complete status.
* \param missionComplete To make all the enemy when to the final position,
* set it to true.
*/
static void setMissionComplete(bool missionComplete);

private:
static QPointF m_target;
static bool m_missionComplete;
bool m_destory;
};

Expand Down
8 changes: 4 additions & 4 deletions enemymanagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ EnemyManagement::EnemyManagement(QWidget *parent) :
[=]
{
m_groundPreview->setEnemyPreviewList(m_enemyManage->enemyList(),
m_enemyManage->positionList());
m_enemyManage->positionList());
});
connect(m_enemyManage, &EnemyManageWidget::requireUpdatePositionList,
[=]
{
m_groundPreview->setPositionList(m_enemyManage->positionList());
m_groundPreview->setEnemyPositionList(m_enemyManage->positionList());
});
m_stackLayout->addWidget(m_enemyManage);

Expand Down Expand Up @@ -125,7 +125,7 @@ void EnemyManagement::addEnemy()
//Make the preview show the preview robot.
m_groundPreview->setShowPreviewEnemy(true);
//Hide the exist robot.
m_groundPreview->setDisplayEnemys(false);
m_groundPreview->setDisplayEnemies(false);
//Show the dialog.
show();
}
Expand All @@ -147,7 +147,7 @@ void EnemyManagement::manageEnemy()
//Hide the preview robot.
m_groundPreview->setShowPreviewEnemy(false);
//Show the exist robots.
m_groundPreview->setDisplayEnemys(true);
m_groundPreview->setDisplayEnemies(true);
//Show the dialog.
show();
}
Expand Down
12 changes: 7 additions & 5 deletions enemymanagewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ EnemyManageWidget::EnemyManageWidget(QWidget *parent) :
&QItemSelectionModel::currentChanged,
[=](const QModelIndex &current)
{
emit requireSelectEnemy(m_enemyList.at(current.row()));
if(current.row()<m_enemyList.size())
{
emit requireSelectEnemy(m_enemyList.at(current.row()));
}
});
connect(m_enemyInitialDataModel, &QStandardItemModel::itemChanged,
[=](QStandardItem *item)
Expand Down Expand Up @@ -108,12 +111,11 @@ EnemyManageWidget::EnemyManageWidget(QWidget *parent) :
if(m_enemyInitialDataView->selectionModel()->hasSelection() &&
m_enemyInitialDataView->currentIndex().isValid())
{
int robotIndex=m_enemyInitialDataView->currentIndex().row();
int enemyIndex=m_enemyInitialDataView->currentIndex().row();
//Remove the robot from the list.
m_enemyList.removeAt(robotIndex);
m_enemyList.removeAt(enemyIndex);
//Remove the initial data from the model.
m_enemyInitialDataModel->removeRow(robotIndex);

m_enemyInitialDataModel->removeRow(enemyIndex);
//Update all.
emit requireUpdateAllList();
}
Expand Down
46 changes: 41 additions & 5 deletions ground.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ void Ground::setBorder(const QPolygonF &border)
2+(Robot::detectRadius()<<1));
//Resize the ground.
setFixedSize(groundSize);
emit groundSizeChanged(groundSize);
//Update the widget.
update();
//Emit changed signal.
Expand Down Expand Up @@ -345,11 +346,37 @@ void Ground::onActionUpdateRobot()
//Move un-destoied unit enemy if 80% of the robots reach the border.
if(m_reachBorderCount>m_minimumMoveEnemyCount)
{
//Get the next position of the enemies.
for(Enemy *enemy : m_enemyList)
{
if(!enemy->destory())
{
enemy->moveOneStep();
bool reachTarget=false;
QPointF nextStep=enemy->nextStep(reachTarget);
if((!Enemy::missionComplete()) && reachTarget)
{
//Set mission complete flag.
Enemy::setMissionComplete(true);
//Generate the four target point.
QList<QPointF> targetPoints;
targetPoints << QPointF(0, 0)
<< QPointF(width(), 0)
<< QPointF(0, height())
<< QPointF(width(), height());
//Set the new target.
for(QPointF point : targetPoints)
{
if(!m_border.containsPoint(point,
Qt::WindingFill))
{
Enemy::setTarget(point);
}
}
//Get the new next step.
nextStep=enemy->nextStep(reachTarget);
}
//Add next step to steps list.
enemy->setPos(nextStep);
}
}
}
Expand Down Expand Up @@ -673,6 +700,7 @@ void Ground::clearGroundData()

//Resize ground.
setFixedSize(0,0);
emit groundSizeChanged(QSize(0,0));
}

bool Ground::readGroundData(const QString &filePath)
Expand Down Expand Up @@ -991,10 +1019,15 @@ bool Ground::addEnemy(Enemy *enemy)
//Add the enemy to initial position.
m_enemyInitialPosition.append(enemy->pos());
//Resize the ground.
int enemyRightMost=enemy->pos().x()+(Enemy::detectRadius()<<1),
enemyBottomMost=enemy->pos().y()+(Enemy::detectRadius()<<1);
setFixedSize(qMax(width(), enemyRightMost),
qMax(height(), enemyBottomMost));
QSize preferSize=
QSize(qMax(width(), (int)(enemy->pos().x()+(Enemy::detectRadius()<<1))),
qMax(height(), (int)(enemy->pos().y()+(Enemy::detectRadius()<<1))));
//If the size is not the same as current size, emit size changed signal.
if(preferSize!=size())
{
setFixedSize(preferSize);
emit groundSizeChanged(preferSize);
}
return true;
}

Expand Down Expand Up @@ -1166,6 +1199,9 @@ void Ground::reset()
//Reset the position.
enemy->setPos(m_enemyInitialPosition.at(i));
}
//Reset the enemy target point and flag.
Enemy::setMissionComplete(false);
Enemy::setTarget(m_barracks.boundingRect().center());
//Update the ground.
update();
}
Expand Down
6 changes: 6 additions & 0 deletions groundbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ class GroundBase : public QWidget
*/
void barracksChanged();

/*!
* \brief When the size of ground changed, this signal will be emitted.
* \param groundSize The size of the ground.
*/
void groundSizeChanged(QSize groundSize);

public slots:
/*!
* \brief Change the time line speed of the ground. The parameter speed
Expand Down
59 changes: 27 additions & 32 deletions groundpreviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,28 +129,9 @@ bool GroundPreviewer::showPreviewEnemy() const
return m_showPreviewEnemy;
}

void GroundPreviewer::setShowPreviewEnemy(bool showPreviewEnemy)
{
m_showPreviewEnemy = showPreviewEnemy;
}

bool GroundPreviewer::showPreviewPoint() const
{
return m_showPreviewPoint;
}

void GroundPreviewer::setPreviewBorder(const QPolygonF &groundBorder)
void GroundPreviewer::onActionGroundSizeChanged(const QSize &groundSize)
{
QPolygonF previewGroundBorder;
//Update the ground height and width.
QRect borderBoundingRect=groundBorder.toPolygon().boundingRect();
QSize groundSize=QSize(borderBoundingRect.right(),
borderBoundingRect.bottom());
//Bounding revise.
groundSize+=QSize(2+(RobotBase::detectRadius()<<1),
2+(RobotBase::detectRadius()<<1));
qreal groundHeight=groundSize.height(),
groundWidth=groundSize.width();
qreal groundHeight=groundSize.height(), groundWidth=groundSize.width();
//Update the offset.
if(groundHeight<groundWidth)
{
Expand All @@ -164,21 +145,35 @@ void GroundPreviewer::setPreviewBorder(const QPolygonF &groundBorder)
{
m_groundParameter=1.0;
}
return;
}
else
//Calculate the offset.
m_xOffset=(groundHeight-groundWidth)/2;
m_yOffset=0;
//Set the parameter.
m_groundParameter=groundHeight;
//Avoid the divided by 0 bug.
if(m_groundParameter==0)
{
//Calculate the offset.
m_xOffset=(groundHeight-groundWidth)/2;
m_yOffset=0;
//Set the parameter.
m_groundParameter=groundHeight;
//Avoid the divided by 0 bug.
if(m_groundParameter==0)
{
m_groundParameter=1.0;
}
m_groundParameter=1.0;
}
}

void GroundPreviewer::setShowPreviewEnemy(bool showPreviewEnemy)
{
m_showPreviewEnemy = showPreviewEnemy;
}

bool GroundPreviewer::showPreviewPoint() const
{
return m_showPreviewPoint;
}

void GroundPreviewer::setPreviewBorder(const QPolygonF &groundBorder)
{
//Update the ground height and width.
//Gernerate the preview border, will zoom the original ground.
QPolygonF previewGroundBorder;
for(QPointF borderPoint : groundBorder)
{
previewGroundBorder.append(pointFromGround(borderPoint));
Expand Down
6 changes: 6 additions & 0 deletions groundpreviewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ class GroundPreviewer : public QWidget
signals:

public slots:
/*!
* \brief Update the parameter of the previewer according to the new size.
* \param groundSize The new size of the ground.
*/
void onActionGroundSizeChanged(const QSize &groundSize);

/*!
* \brief Make the preview widget to display the preview enemy or not.
* \param showPreviewEnemy The preview enabled value.
Expand Down
Loading

0 comments on commit f981372

Please sign in to comment.