123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- ///
- /// Modifications:
- /// - 2015-01-13 [RAN] - Changed the quadraticFormulaCheck function to
- /// prevent giving away the expression
- /// - 2015-06-09 [LAA] - Modified the graphics windwow so that you aren't
- /// able to scroll
-
- #include "mainwindow.h"
- #include "ui_mainwindow.h"
- #include <QMessageBox>
-
- /// \fn MainWindow::MainWindow(QWidget *parent)
- /// \~English
- /// \brief Default constructor.
- /// \~Spanish
- /// \brief Constructor por defecto.
- ///
- MainWindow::MainWindow(QWidget *parent) :
- QMainWindow(parent),
- ui(new Ui::MainWindow)
- {
- quadraticFormulaCheck();
-
- // set up mainWindow
- ui->setupUi(this);
- scene= new QGraphicsScene(this);
- scene->setSceneRect(QRectF(QPointF(0,0), QPointF(0,0)));
- ui->MainView->setScene(scene);
- ui->MainView->setAlignment((Qt::AlignLeft | Qt::AlignTop));
- ui->MainView->resize(580,345);
- ui->MainView->move(0,0);
- ui->MainView->setEnabled(false);
-
- // set lables and buttons
- ui->alabel->move(10,360);
- ui->alineEdit->move(25,358);
- ui->blabel->move(85,360);
- ui->blineEdit->move(100,358);
- ui->clabel->move(160,360);
- ui->clineEdit->move(175,358);
- ui->RunPushButton->move(10,385);
- ui->retryButton->move(180,385);
- ui->RunPushButton->setEnabled(false);
-
- frogger = new frog;
- globalTimer = new QTimer;
- scene->addWidget(frogger);
-
-
- }
-
- /// \fn MainWindow::~MainWindow()
- /// \~English
- /// \brief Default destructor
- /// \~Spanish
- /// \brief Destructor por defecto
- ///
- MainWindow::~MainWindow()
- {
- delete ui;
- delete scene;
- }
-
- /// \fn void MainWindow::quadraticFormulaCheck()
- /// \~English
- /// \brief Function that uses an array of values to determine
- /// if the equation written by the student is correct.
- /// \~Spanish
- /// \brief Funcion que utiliza un arreglo de valores para
- /// determinar si la ecuacion que escribio el estudiante
- /// esta correcta.
- ///
- void MainWindow::quadraticFormulaCheck()
- {
- float resultFromFunction;
- bool pass = true;
- float values[] = {357 , -1000 , 698 , 1.4804781099 , 748 , -392 , 51 , 0.28391805554 ,
- 689 , -689 , 172 , 0.519048482944 , 90 , 521 , 751 , -2.71178575308 , 5 , 107 ,
- 465 , -6.0642692054 , 1609 , -983 , 150 , 0.314734649792 , 273 , 496 , 224 ,
- -0.839700867988 , 2 , 91 , 920 , -15.1630045473 , 48 , 300 , 463 , -2.77889067238 ,
- 852 , 907 , 241 , -0.510947439149};
-
- float valuesForMinus[] = {129 , -486 , 456 , 1.76744186047 , 384 , 980 , 625 , -1.30208333333 ,
- 270 , -904 , 755 , 1.59515823795 , 67 , -450 , 752 , 3.12650485528 , 98 , 506 , 651 ,
- -2.72985550047 , 38 , -373 , 901 , 4.29396930804 , 273 , -282 , 72 , 0.461538461538 ,
- 225 , -889 , 874 , 1.84 , 8 , 136 , 522 , -11.1457513111 , 5 , 77 , 214 , -11.760788100};
-
- float a, b, c, expected;
-
- //Verifying if the equation written by the student is correct
- for (int i = 0; i < 40 && pass; i+=4){
- a = values[i];
- b = values[i+1];
- c = values[i+2];
- expected = values[i+3];
-
- // firstX = (((-b) + sqrt((pow(b,2)) - 4*a*c))/(2*a));
- resultFromFunction = frogger->QuadraticPlus(a,b,c);
-
- if( fabs(resultFromFunction - expected) > 0.00001) {
- pass = false;
- }
- }
- if(!pass){
- QMessageBox::information(this, "Error", "La funcion cuadratica esta mal escrita!");
- exit(1);
- }
-
- //Verifying if the equation written by the student is correct
- for (int i = 0; i < 40 && pass; i+=4){
- a = valuesForMinus[i];
- b = valuesForMinus[i+1];
- c = valuesForMinus[i+2];
- expected = valuesForMinus[i+3];
-
- // firstX = (((-b) + sqrt((pow(b,2)) - 4*a*c))/(2*a));
- resultFromFunction = frogger->QuadraticMinus(a,b,c);
-
- if( fabs(resultFromFunction - expected) > 0.00001) {
- pass = false;
- }
- }
- if(!pass){
- QMessageBox::information(this, "Error", "La funcion cuadratica esta mal escrita!");
- exit(1);
- }
- }
-
- /// \fn void on_RunPushButton_clicked()
- /// \~English
- /// \brief Function that is invoked when the jump button is pressed,
- /// frog jumps to calculated location.
- /// \~Spanish
- /// \brief Funcion que se invoca cuando el boton de "jump" es presionado,
- /// el sapo brinca a la localizacion calculada.
- ///
- void MainWindow::on_RunPushButton_clicked()
- {
- int a = 0;
- int b = 0;
- int c = 0;
- int det = 0;
- a = (ui->alineEdit->text().toInt());
- b = (ui->blineEdit->text().toInt());
- c = (ui->clineEdit->text().toInt());
-
- det = (pow(b,2) - (4*a*c));
-
- if(a > 0){
- QMessageBox::information(this, "Error", "La parabola abre hacia arriba y por lo tanto el sapo no brincara");
- ui->alineEdit->clear();
- ui->blineEdit->clear();
- ui->clineEdit->clear();
- }
- else if(a == 0){
- QMessageBox::information(this, "Error", "No hay parabola y por lo tanto el sapo no brincara");
- ui->alineEdit->clear();
- ui->blineEdit->clear();
- ui->clineEdit->clear();
- }
- else{
- if(det < 0){
- QMessageBox::information(this, "Error", "No tiene intercepto y por lo tanto el sapo no brincara");
- ui->alineEdit->clear();
- ui->blineEdit->clear();
- ui->clineEdit->clear();
- }
- else if(det == 0){
- QMessageBox::information(this, "Error", "El vertice esta en el intercepto y por lo tanto el sapo no brincara");
- ui->alineEdit->clear();
- ui->blineEdit->clear();
- ui->clineEdit->clear();
- }
- else{
- frogger->run(a, b, c);
- ui->RunPushButton->setEnabled(false);
- ui->alineEdit->clear();
- ui->blineEdit->clear();
- ui->clineEdit->clear();
- }
- }
-
-
- }
-
- /// \fn void on_retryButton_clicked()
- /// \~English
- /// \brief Function that is invoked when the reset button is pressed,
- /// returns the window to its original state.
- /// \~Spanish
- /// \brief Funcion que se invoca cuando el boton de "reset" es presionado,
- /// devuelve la ventana a su estado original.
- ///
- void MainWindow::on_retryButton_clicked()
- {
- frogger->reset();
- }
-
- /// \fn MainWindow::on_alineEdit_textChanged(QString &arg1)
- /// \~English
- /// \brief Function that is invoked when the text is changed in the
- /// alineEdit, enables jump buttton if the other line edits aren't empty.
- /// \~Spanish
- /// \brief Funcion que se invoca cuando el texto dentro de alineEdit
- /// cambia, permite que el button de "jump" sea presionado si los otros
- /// "line edits" no estan vacios.
- ///
- void MainWindow::on_alineEdit_textChanged()
- {
- if(ui->alineEdit->text() != "" && ui->blineEdit->text() != "" && ui->clineEdit->text() != "" ){
- ui->RunPushButton->setEnabled(true);
- }
- else{
- ui->RunPushButton->setEnabled(false);
- }
- }
-
- /// \fn MainWindow::on_blineEdit_textChanged(QString &arg1)
- /// \~English
- /// \brief Function that is invoked when the text is changed in the
- /// alineEdit, enables jump buttton if the other line edits aren't empty.
- /// \~Spanish
- /// \brief Funcion que se invoca cuando el texto dentro de alineEdit
- /// cambia, permite que el button de "jump" sea presionado si los otros
- /// "line edits" no estan vacios.
- ///
- void MainWindow::on_blineEdit_textChanged()
- {
- if(ui->alineEdit->text() != "" && ui->blineEdit->text() != "" && ui->clineEdit->text() != "" ){
- ui->RunPushButton->setEnabled(true);
- }
- else{
- ui->RunPushButton->setEnabled(false);
- }
- }
-
- /// \fn MainWindow::on_clineEdit_textChanged(QString &arg1)
- /// \~English
- /// \brief Function that is invoked when the text is changed in the
- /// alineEdit, enables jump buttton if the other line edits aren't empty.
- /// \~Spanish
- /// \brief Funcion que se invoca cuando el texto dentro de alineEdit
- /// cambia, permite que el button de "jump" sea presionado si los otros
- /// "line edits" no estan vacios.
- ///
- void MainWindow::on_clineEdit_textChanged()
- {
- if(ui->alineEdit->text() != "" && ui->blineEdit->text() != "" && ui->clineEdit->text() != "" ){
- ui->RunPushButton->setEnabled(true);
- }
- else{
- ui->RunPushButton->setEnabled(false);
- }
- }
|