Sfoglia il codice sorgente

Changes in the sources, updated README

Jose Ortiz 9 anni fa
parent
commit
3a8bd53471
6 ha cambiato i file con 103 aggiunte e 404 eliminazioni
  1. 8
    26
      QuadraticFormula.cpp
  2. 2
    2
      README.md
  3. 69
    118
      frog.cpp
  4. 6
    114
      frog.h
  5. 15
    75
      mainwindow.cpp
  6. 3
    69
      mainwindow.h

+ 8
- 26
QuadraticFormula.cpp Vedi File

@@ -1,39 +1,21 @@
1
+/* Ive changed the type of the function to double,     */
2
+/* so it is consistent with the type that sqrt returns */
3
+
4
+
1 5
 #include "frog.h"
2 6
 
3
-/// \fn frog::QuadraticPlus(int a, int b, int c)
4
-/// \~English
5
-/// \brief Function that returns the result of the negative quadratic formula.
6
-/// \param a: value used to complete the quadratic formula
7
-/// \param b: value used to complete the quadratic formula
8
-/// \param c: value used to complete the quadratic formula
9
-/// \~Spanish
10
-/// \brief Funcion que devuelve el resultado de la formula cuadratica negativa.
11
-/// \param a: valor utilizado para completar la formula quadratica
12
-/// \param b: valor utilizado para completar la formula quadratica
13
-/// \param c: valor utilizado para completar la formula quadratica
14 7
 double frog::QuadraticPlus(int a, int b, int c){
15
-    double result = 0;
8
+    double result;
16 9
 
17
-    // YOUR CODE HERE / TU CODIGO AQUI
10
+    // YOUR CODE HERE
18 11
 
19
-    return result = 0;
12
+    return result;
20 13
 }
21 14
 
22
-/// \fn frog::QuadraticMinus(int a, int b, int c)
23
-/// \~English
24
-/// \brief Function that returns the result of the negative quadratic formula.
25
-/// \param a: value used to complete the quadratic formula
26
-/// \param b: value used to complete the quadratic formula
27
-/// \param c: value used to complete the quadratic formula
28
-/// \~Spanish
29
-/// \brief Funcion que devuelve el resultado de la formula cuadratica negativa.
30
-/// \param a: valor utilizado para completar la formula quadratica
31
-/// \param b: valor utilizado para completar la formula quadratica
32
-/// \param c: valor utilizado para completar la formula quadratica
33 15
 double frog::QuadraticMinus(int a, int b, int c){
34 16
     double result;
35 17
 
36
-    // YOUR CODE HERE / TU CODIGO AQUI
18
+    // YOUR CODE HERE
37 19
 
38 20
     return result;
39 21
 }

+ 2
- 2
README.md Vedi File

@@ -316,7 +316,7 @@ In this exercise you will implement the quadratic formula to complete a game in
316 316
     ---
317 317
 
318 318
 
319
-5. Use "Deliverable 1" in Moodle to submit the file  `QuadraticFormula.cpp` containing the code with the functions `QuadraticPlus` and `QuadraticMinus`. Remember to use good programming practices, to include the names of the programmers and to document your program.
319
+5. Use "Deliver 1" in Moodle to submit the file  `QuadraticFormula.cpp` containing the code with the functions `QuadraticPlus` and `QuadraticMinus`. Remember to use good programming practices, to include the names of the programmers and to document your program.
320 320
 
321 321
 6. To play, the frog should leap jump from one leaf to another. Note that the leaves have values for $x_1$ and $x_2$. These values represent the intersects of the parabola with the $x$-axis. You should input the values for the coefficients $a, b, c$ of the quadratic equation so that its graph that is a parabola that opens down and intersects the $x$-axis in the values $x_1, x_2$ shown in the leaves. You can obtain these values noting that
322 322
 
@@ -347,6 +347,6 @@ Suppose that all courses in Cheo's University are 3 credits each and have the fo
347 347
 
348 348
     2. Remember that, in C++, when both operands in the division are integers, the result will also be an integer; the remainder will be discarded. Use "type casting": `static_cast\<type\>(expression)' to solve this problem.
349 349
 
350
-3. Verify your program by computing the GPA of a student that has two A's and 2 B's; what is the grade of this student, A or B (A goes from 3.5 to 4 points)? When your program is correct, save the `main.cpp` file and submit it using "Deliverable 2" in Moodle. Remember to follow the instructions regarding the names and types of the variables,  to include the names of the programmers, to document your program and to use good programming practices.
350
+3. Verify your program by computing the GPA of a student that has two A's and 2 B's; what is the grade of this student, A or B (A goes from 3.5 to 4 points)? When your program is correct, save the `main.cpp` file and submit it using "Deliver 2" in Moodle. Remember to follow the instructions regarding the names and types of the variables,  to include the names of the programmers, to document your program and to use good programming practices.
351 351
 
352 352
 

+ 69
- 118
frog.cpp Vedi File

@@ -1,7 +1,3 @@
1
-///
2
-/// Modifications:
3
-///     - 2015-06-05 [Ian Davila] - Changed Frogger's location
4
-///
5 1
 #include "frog.h"
6 2
 #include <QDebug>
7 3
 #include <cstdlib>
@@ -11,87 +7,59 @@
11 7
 #include "mainwindow.h"
12 8
 #include "ui_mainwindow.h"
13 9
 
14
-/// \fn frog::frog(QWidget *parent)
15
-/// \~English
16
-/// \brief Default constructor.
17
-/// * Ysapo: Y coordinate of the frog, set at 190 so it sits on top of the leaf
18
-/// * Xsapo: X coordinate of the frog, a random number from 0 to -30
19
-/// * xnenu, xnenu2, xnenu3: X coordinates of the leafs
20
-/// * textBool: Boolean for the labels on the leafs
21
-/// * temp, temp2: X coordinate of the background
22
-/// \~Spanish
23
-/// \ brief Constructor por defecto.
24
-/// * Ysapo: Coordenada Y del sapo, inicializado a 190 para que aparesca encima del nenufar
25
-/// * Xsapo: Coordenada X del sapo, un numero aleatorio de 0 a -30
26
-/// * xnenu, xnenu2, xnenu3: coordenadas x de las hojas
27
-/// * textBool: Booleana para las etiquetas de los nenufares
28
-/// * temp, temp2: Coordenada X del fondo
29
-///
30 10
 frog::frog(QWidget *parent) :
31 11
     QWidget(parent)
32 12
 {
33 13
     myTimer= new QTimer(this);
34
-    flag = xFlag = backFlag = moved = textBool = false;
14
+    flag = xFlag = false;
35 15
     Ysapo = 190;
36 16
     A = B = C = 0;
37 17
     temp = 580;
38 18
     temp2 = 0;
39
-    xnenu = -(rand()%30);
40
-    initialX = Xsapo = xnenu;
19
+    backFlag = false;
20
+    moved = false;
21
+    textBool = false;
22
+    buttonCounter = 0;
23
+    xnenu = -(rand() %30);
24
+    Xsapo = xnenu;
25
+    initialX = Xsapo;
41 26
     xnenu2 = (rand() % 100) + 100;
42 27
     xnenu3 = xnenu2 + (rand() % 100) + 200;
43 28
 }
44 29
 
45
-/// \fn void frog::updatenenu()
46
-/// \~English
47
-/// \brief Function that updates the position of the frog and the leafs
48
-///  when the frog reaches the end of the screen when it's sliding back.
49
-/// \~Spanish
50
-/// \brief Funcion que actualiza la posicion del sapo y los nenufares
51
-///  cuando el sapo llega al final de la pantalla cuando se desliza hacia atras.
52
-///
53 30
 void frog::updatenenu(){
54 31
     xnenu = -(rand() % 30);
55
-    initialX = Xsapo = xnenu;
32
+    Xsapo = xnenu;
33
+    initialX = Xsapo;
56 34
     xnenu2 = (rand() % 100) + 100;
57 35
     xnenu3 = xnenu2 + (rand() % 100) + 200;
58 36
 }
59 37
 
60
-/// \fn void frog::reset()
61
-/// \~English
62
-/// \brief Function that is invoked when the retry button is clicked, resets
63
-///  the frog and the leafs to a random starting position.
64
-/// \~Spanish
65
-/// \brief Funcion que es invocada cuando el boton de "retry" es presionado,
66
-///  restablece el sapo y los nenufares a una posicion de partida aleatoria.
67
-///
68 38
 void frog::reset(){
69
-    flag = xFlag = backFlag = moved = textBool = false;
39
+    flag = xFlag = false;
70 40
     Ysapo = 190;
71 41
     A = B = C = 0;
72 42
     temp = 580;
73 43
     temp2 = 0;
44
+    backFlag = false;
45
+    moved = false;
46
+    buttonCounter = 0;
47
+    textBool = false;
74 48
     repaint();
49
+
75 50
     myTimer->stop();
76 51
     delete myTimer;
77 52
     myTimer = new QTimer;
78 53
     connect(myTimer, SIGNAL(timeout()), this, SLOT(mySlot()));
79 54
     xnenu = -(rand() %30);
80
-    initialX = Xsapo = xnenu;
55
+    Xsapo = xnenu;
56
+    initialX = Xsapo;
81 57
     xnenu2 = (rand() % 100) + 100;
82 58
     xnenu3 = xnenu2 + (rand() % 100) + 200;
83 59
 
84 60
 }
85 61
 
86
-/// \fn void frog::paintEvent(QPaintEvent *event)
87
-/// \~English
88
-/// \brief Function that is invoked each time the widget or
89
-///  its parent receives a repaint signal.
90
-/// \~Spanish
91
-/// \brief Funcion que es invocada automaticamente cada vez que el widget
92
-///  o su padre recive una senal de repintar.
93
-///
94
-void frog::paintEvent(QPaintEvent *){
62
+void frog::paintEvent(QPaintEvent *event){
95 63
     QPainter p(this);
96 64
     QString frogger = ":/images/Frogger1.png";
97 65
     QString frogger2 = ":/images/Frogger2.png";
@@ -99,12 +67,20 @@ void frog::paintEvent(QPaintEvent *){
99 67
     QString leaf = ":/images/Nenufar1.png";
100 68
     QString back = ":/images/background.jpg";
101 69
 
102
-    //Conditions that allow a margin of error (not landing in the exact x calculated)
70
+//    Condiciones que permitian un rango de error (no caer en la x exacta de los nenufares)
71
+
103 72
     if(backFlag == true || (Xsapo <= (xnenu3 + 55) && Xsapo >= (xnenu3 - 55) && Ysapo == 190)
104 73
             || (Xsapo > xnenu && Ysapo == 190 && Xsapo < (xnenu2-55))
105 74
             || (Xsapo > xnenu2 && Ysapo == 190 && Xsapo < (xnenu3-55))
106 75
             || (Xsapo > xnenu3 && Ysapo == 190)){
107 76
 
77
+//    if(backFlag == true || (Ysapo == 190 && (Xsapo != xnenu && Xsapo != xnenu2))){
78
+        if (inter1Label == NULL){
79
+            delete inter1Label;
80
+        }
81
+        if (inter2Label == NULL){
82
+            delete inter2Label;
83
+        }
108 84
         backFlag = true;
109 85
         myTimer->stop();
110 86
         delete myTimer;
@@ -112,20 +88,19 @@ void frog::paintEvent(QPaintEvent *){
112 88
         QThread::msleep(5);
113 89
         connect(myTimer, SIGNAL(timeout()), this, SLOT(mySlot()));
114 90
 
115
-        // Draw background
91
+
92
+
116 93
         p.drawPixmap(temp2,-5,600,400,QPixmap(back));
117 94
         p.drawPixmap(temp,-5,600,400,QPixmap(back));
118 95
 
119
-        // Draw leaves
120
-        p.drawPixmap(xnenu,230,125,60,QPixmap(leaf));
121
-        p.drawPixmap(xnenu2,230,125,60,QPixmap(leaf));
122
-        p.drawPixmap(xnenu3,230,125,60,QPixmap(leaf));
96
+        p.drawPixmap(xnenu,250,125,60,QPixmap(leaf));
97
+        p.drawPixmap(xnenu2,250,125,60,QPixmap(leaf));
98
+        p.drawText(xnenu2+45,290,"x1 = " + QString::number(xnenu2));
99
+        p.drawPixmap(xnenu3,250,125,60,QPixmap(leaf));
100
+        p.drawText(xnenu3+45,290,"x2 = " + QString::number(xnenu3));
101
+
123 102
 
124
-        // Draw text labels
125
-        p.drawText(xnenu2+45,310,"x1 = " + QString::number(xnenu2));
126
-        p.drawText(xnenu3+45,310,"x2 = " + QString::number(xnenu3));
127 103
 
128
-        // Moves everything on the screen back on the x-axis
129 104
         Xsapo=Xsapo-1;
130 105
         xnenu=xnenu-1;
131 106
         xnenu2=xnenu2-1;
@@ -133,9 +108,11 @@ void frog::paintEvent(QPaintEvent *){
133 108
         temp= temp - 1;
134 109
         temp2 = temp2 -1;
135 110
 
111
+
136 112
         repaint();
137 113
 
138
-        // When the frog reaches the end of the screen reset everything to a start position
114
+
115
+
139 116
         if(temp == 0 || xnenu3 == -10 || Xsapo == 0){
140 117
             backFlag = false;
141 118
             temp = 580;
@@ -145,77 +122,63 @@ void frog::paintEvent(QPaintEvent *){
145 122
             updatenenu();
146 123
         }
147 124
 
148
-    }else{
125
+    }
126
+    else{
149 127
           QFont font = p.font();
150 128
           font.setBold(true);
151 129
           p.setFont(font);
152 130
 
153
-          // Draw background
154 131
           p.drawPixmap(temp2,-5,600,400,QPixmap(back));
155 132
           p.drawPixmap(temp,-5,600,400,QPixmap(back));
133
+          p.drawPixmap(xnenu,250,125,60,QPixmap(leaf));
134
+          p.drawPixmap(xnenu2,250,125,60,QPixmap(leaf));
135
+          p.drawPixmap(xnenu3,250,125,60,QPixmap(leaf));
156 136
 
157
-          // Draw leaves
158
-          p.drawPixmap(xnenu,230,125,60,QPixmap(leaf));
159
-          p.drawPixmap(xnenu2,230,125,60,QPixmap(leaf));
160
-          p.drawPixmap(xnenu3,230,125,60,QPixmap(leaf));
137
+//          Cambiada la condicion para que sea exacta la caida en el nenufar
138
+//          if(Xsapo < (xnenu2 + 55) && Ysapo == 190 && Xsapo > (xnenu2-55)){
139
+//               textBool = true;
140
+//          }
161 141
 
162
-          //Cambiada la condicion para que sea exacta la caida en el nenufar // Funciona con esta condición
163
-          if(Xsapo < (xnenu2 + 55) && Ysapo == 190 && Xsapo > (xnenu2-55)){
164
-               textBool = true;
165
-          }
166
-
167
-          // When the frog lands on the second leaf, change labels to next leaf
168 142
           if(Ysapo == 190 && Xsapo == xnenu2){
169 143
             textBool = true;
170 144
           }
171 145
 
172 146
           if(textBool){
173
-              // Redraw the text labels
174
-              p.drawText(xnenu2+35,310,"x1 = " + QString::number(xnenu2)); // de 290 a 310
175
-              p.drawText(xnenu3+35,310,"x2 = " + QString::number(xnenu3));
176
-              p.drawPixmap(xnenu,230,125,60,QPixmap(leaf)); // 250 a 230
177
-          }else{
178
-              p.drawText(xnenu2+35,310,"x2 = " + QString::number(xnenu2)); // de 290 a 310
147
+              p.drawText(xnenu2+35,290,"x1 = " + QString::number(xnenu2));
148
+              p.drawText(xnenu3+35,290,"x2 = " + QString::number(xnenu3));
149
+              p.drawPixmap(xnenu,250,125,60,QPixmap(leaf));
150
+          }
151
+          else{
152
+              p.drawText(xnenu2+35,290,"x2 = " + QString::number(xnenu2));
179 153
           }
154
+
180 155
     }
181 156
 
182
-    //Cambiada la condicion para que sea exacta la caida en el nenufar
183
-    if((Xsapo > (xnenu + 55) && Ysapo == 190 && Xsapo < (xnenu2-55))
157
+//    Cambiada la condicion para que sea exacta la caida en el nenufar
158
+    if(Xsapo > (xnenu + 55) && Ysapo == 190 && Xsapo < (xnenu2-55)
184 159
         || (Xsapo > (xnenu2 + 55) && Ysapo == 190 && Xsapo < (xnenu3-55))
185 160
         || (Xsapo > (xnenu3 + 55) && Ysapo == 190)){
186 161
 
162
+//    if(Ysapo == 190 && (Xsapo != xnenu && Xsapo != xnenu2 && Xsapo != xnenu3)){
187 163
         p.drawPixmap(Xsapo, Ysapo + 30, 100, 80, QPixmap(frogger3));
188
-
189
-    }else if(Ysapo < 190){
190
-       p.drawPixmap(Xsapo,Ysapo,100,100,QPixmap(frogger2));
191
-
164
+    }
165
+    else if(Ysapo < 190){
166
+        p.drawPixmap(Xsapo,Ysapo,100,100,QPixmap(frogger2));
192 167
     }else if(Ysapo == 190){
193 168
         qDebug() << "xsapo: " << Xsapo << "xnenu2: " << xnenu2;
194
-        p.drawPixmap(Xsapo + 15,Ysapo - 20 ,100,100,QPixmap(frogger)); //+15 a la Xsapo, -20 a Ysapo
169
+        p.drawPixmap(Xsapo,Ysapo,100,100,QPixmap(frogger));
195 170
         if(!textBool){
196
-            p.drawText(xnenu+45,310,"x1 = " + QString::number(xnenu+10));
171
+            p.drawText(xnenu+45,290,"x1 = " + QString::number(xnenu+10));
197 172
         }
198 173
     }
174
+
199 175
 }
200 176
 
201
-/// \fun frog::~frog()
202
-/// \~English
203
-/// \brief Default destructor.
204
-/// \~Spanish
205
-/// \brief Destructor por defecto.
206
-///
207 177
 frog::~frog(){
208 178
     delete myTimer;
209 179
 }
210 180
 
211
-/// \fun void frog::mySlot()
212
-/// \~English
213
-/// \brief Function connected to a timer, used to simulate the
214
-///  frog's jump.
215
-/// \~Spanish
216
-/// \brief Funcion conectada a un reloj, utilizada para simular
217
-///  el brinco del sapo
218
-///
181
+
219 182
 void frog::mySlot(){
220 183
     float interX1 = 0;
221 184
     float interX2 = 0;
@@ -224,6 +187,8 @@ void frog::mySlot(){
224 187
     float xtemp = 0;
225 188
     float xEnd = 0;
226 189
 
190
+
191
+
227 192
     interX1 = QuadraticMinus(A,B,C);
228 193
     interX2 = QuadraticPlus(A,B,C);
229 194
 
@@ -234,6 +199,7 @@ void frog::mySlot(){
234 199
     }
235 200
     if(moved){
236 201
         moved = false;
202
+        buttonCounter = 1;
237 203
         initialX = Xsapo;
238 204
     }
239 205
 
@@ -269,27 +235,12 @@ void frog::mySlot(){
269 235
 
270 236
 }
271 237
 
272
-/// \fn void frog::run(int aa, int bb, int cc)
273
-/// \~English
274
-/// \brief Function that is invoked when the jump button is
275
-///  pressed, makes the frog jump to the coordinates calculated
276
-///  with the a, b, c values provided by the user.
277
-/// \param aa value provided by user to complete the quadratic equation ax^2 + bx + c
278
-/// \param bb value provided by user to complete the quadratic equation ax^2 + bx + c
279
-/// \param cc value provided by user to complete the quadratic equation ax^2 + bx + c
280
-/// \~Spanish
281
-/// \brief Funcion que es invocada cuando el boton de brincar es
282
-///  presionado, hace que el sapo salte a las coordenadas calculadas
283
-///  con los valores de a, b, c proporcionados por el usuario.
284
-/// \param aa valor proporcionado por el usuario utilizado para completar la ecuacion cuadratica ax^2 + bx + c
285
-/// \param bb valor proporcionado por el usuario utilizado para completar la ecuacion cuadratica ax^2 + bx + c
286
-/// \param cc valor proporcionado por el usuario utilizado para completar la ecuacion cuadratica ax^2 + bx + c
287
-///
288 238
 void frog::run(int aa, int bb, int cc){
289 239
 
290 240
     A = aa;
291 241
     B = bb;
292 242
     C = cc;
243
+    buttonCounter++;
293 244
 
294 245
     connect(myTimer, SIGNAL(timeout()), this, SLOT(mySlot()));
295 246
     myTimer->start(25);

+ 6
- 114
frog.h Vedi File

@@ -8,140 +8,32 @@
8 8
 #include <QTimer>
9 9
 #include <QLabel>
10 10
 
11
-
12
-/// Class that represent the frog and leaves.
13
-///
14
-/// Frog is a subclass of QWidget.
15
-
16 11
 class frog : public QWidget
17 12
 {
18 13
     Q_OBJECT
19 14
 public:
20
-
21
-    /// \fn frog::frog(QWidget *parent)
22
-    /// \~English
23
-    /// \brief Default constructor.
24
-    /// * Ysapo: Y coordinate of the frog, set at 190 so it sits on top of the leaf
25
-    /// * Xsapo: X coordinate of the frog, a random number from 0 to -30
26
-    /// * xnenu, xnenu2, xnenu3: X coordinates of the leafs
27
-    /// * textBool: Boolean for the labels on the leafs
28
-    /// * temp, temp2: X coordinate of the background
29
-    /// \~Spanish
30
-    /// \ brief Constructor por defecto.
31
-    /// * Ysapo: Coordenada Y del sapo, inicializado a 190 para que aparesca encima del nenufar
32
-    /// * Xsapo: Coordenada X del sapo, un numero aleatorio de 0 a -30
33
-    /// * xnenu, xnenu2, xnenu3: coordenadas x de las hojas
34
-    /// * textBool: Booleana para las etiquetas de los nenufares
35
-    /// * temp, temp2: Coordenada X del fondo
36
-    ///
37 15
     explicit frog(QWidget *parent = 0);
16
+    float Ysapo, Xsapo, initialX;
17
+    bool flag, xFlag, backFlag, moved, textBool;
18
+    int A, B, C, buttonCounter,temp,temp2,xnenu,xnenu2,xnenu3;
38 19
 
39
-    /// \fn frog::QuadraticPlus(int a, int b, int c)
40
-    /// \~English
41
-    /// \brief Function that returns the result of the positive quadratic formula.
42
-    /// \param a: value used to complete the quadratic formula ((-b) + sqrt((pow(b,2)) - 4*a*c))/(2*a)
43
-    /// \param b: value used to complete the quadratic formula ((-b) + sqrt((pow(b,2)) - 4*a*c))/(2*a)
44
-    /// \param c: value used to complete the quadratic formula ((-b) + sqrt((pow(b,2)) - 4*a*c))/(2*a)
45
-    /// \~Spanish
46
-    /// \brief Funcion que devuelve el resultado de la formula cuadratica positiva.
47
-    /// \param a: valor utilizado para completar la formula quadratica ((-b) + sqrt((pow(b,2)) - 4*a*c))/(2*a)
48
-    /// \param b: valor utilizado para completar la formula quadratica ((-b) + sqrt((pow(b,2)) - 4*a*c))/(2*a)
49
-    /// \param c: valor utilizado para completar la formula quadratica ((-b) + sqrt((pow(b,2)) - 4*a*c))/(2*a)
50
-    ///
51 20
     double QuadraticPlus(int a, int b, int c);
52
-
53
-    /// \fn frog::QuadraticMinus(int a, int b, int c)
54
-    /// \~English
55
-    /// \brief Function that returns the result of the negative quadratic formula.
56
-    /// \param a: value used to complete the quadratic formula ((-b) + sqrt((pow(b,2)) - 4*a*c))/(2*a)
57
-    /// \param b: value used to complete the quadratic formula ((-b) + sqrt((pow(b,2)) - 4*a*c))/(2*a)
58
-    /// \param c: value used to complete the quadratic formula ((-b) + sqrt((pow(b,2)) - 4*a*c))/(2*a)
59
-    /// \~Spanish
60
-    /// \brief Funcion que devuelve el resultado de la formula cuadratica negativa.
61
-    /// \param a: valor utilizado para completar la formula quadratica ((-b) - sqrt((pow(b,2)) - 4*a*c))/(2*a)
62
-    /// \param b: valor utilizado para completar la formula quadratica ((-b) - sqrt((pow(b,2)) - 4*a*c))/(2*a)
63
-    /// \param c: valor utilizado para completar la formula quadratica ((-b) - sqrt((pow(b,2)) - 4*a*c))/(2*a)
64
-    ///
65 21
     double QuadraticMinus(int a, int b, int c);
66
-
67
-    /// \fun frog::~frog()
68
-    /// \~English
69
-    /// \brief Default destructor.
70
-    /// \~Spanish
71
-    /// \brief Destructor por defecto.
72
-    ///
73 22
     ~frog();
74 23
 
75
-
76
-    float Ysapo; /**< Y coordinate of the frog*/
77
-    float Xsapo; /**< X coordinate of the frog*/
78
-    float initialX; /**< Initial position of the frog*/
79
-    bool flag, xFlag, backFlag, moved, textBool;
80
-    int A, B, C, buttonCounter,temp,temp2,xnenu,xnenu2,xnenu3;
81
-
24
+private:
25
+    QLabel *inter1Label;
26
+    QLabel *inter2Label;
82 27
 
83 28
 signals:
84 29
 
85 30
 public slots:
86
-    /// \fun void frog::mySlot()
87
-    /// \~English
88
-    /// \brief Function connected to a timer, used to simulate the
89
-    ///  frog's jump.
90
-    /// \~Spanish
91
-    /// \brief Funcion conectada a un reloj, utilizada para simular
92
-    ///  el brinco del sapo
93
-    ///
94 31
     void mySlot();
95
-
96
-    /// \fn void frog::run(int , int , int )
97
-    /// \~English
98
-    /// \brief Function that is invoked when the jump button is
99
-    ///  pressed, makes the frog jump to the coordinates calculated
100
-    ///  with the a, b, c values provided by the user.
101
-    /// \param aa value provided by user to complete the quadratic equation ax^2 + bx + c
102
-    /// \param bb value provided by user to complete the quadratic equation ax^2 + bx + c
103
-    /// \param cc value provided by user to complete the quadratic equation ax^2 + bx + c
104
-    /// \~Spanish
105
-    /// \brief Funcion que es invocada cuando el boton de brincar es
106
-    ///  presionado, hace que el sapo salte a las coordenadas calculadas
107
-    ///  con los valores de a, b, c proporcionados por el usuario.
108
-    /// \param aa valor proporcionado por el usuario utilizado para completar la ecuacion
109
-    ///  cuadratica ax^2 + bx + c
110
-    /// \param bb valor proporcionado por el usuario utilizado para completar la ecuacion
111
-    ///  cuadratica ax^2 + bx + c
112
-    /// \param cc valor proporcionado por el usuario utilizado para completar la ecuacion
113
-    /// cuadratica ax^2 + bx + c
114 32
     void run(int, int, int);
115
-
116
-    /// \fn void frog::reset()
117
-    /// \~English
118
-    /// \brief Function that is invoked when the retry button is clicked, resets
119
-    ///  the frog and the leafs to a random starting position.
120
-    /// \~Spanish
121
-    /// \brief Funcion que es invocada cuando el boton de "retry" es presionado,
122
-    ///  restablece el sapo y los nenufares a una posicion de partida aleatoria.
123
-    ///
124 33
     void reset();
125
-
126
-    /// \fn void frog::updatenenu()
127
-    /// \~English
128
-    /// \brief Function that updates the position of the frog and the leafs
129
-    ///  when the frog reaches the end of the screen when it's sliding back.
130
-    /// \~Spanish
131
-    /// \brief Funcion que actualiza la posicion del sapo y los nenufares
132
-    ///  cuando el sapo llega al final de la pantalla cuando se desliza hacia atras.
133
-    ///
134 34
     void updatenenu();
135 35
 
136 36
 protected:
137
-    /// \fn void frog::paintEvent(QPaintEvent *event)
138
-    /// \~English
139
-    /// \brief Function that is invoked each time the widget or
140
-    ///  its parent receives a repaint signal.
141
-    /// \~Spanish
142
-    /// \brief Funcion que es invocada automaticamente cada vez que el widget
143
-    ///  o su padre recive una senal de repintar.
144
-    ///
145 37
     void paintEvent(QPaintEvent *event);
146 38
     QTimer *myTimer;
147 39
 

+ 15
- 75
mainwindow.cpp Vedi File

@@ -2,26 +2,18 @@
2 2
 /// Modifications:
3 3
 ///     - 2015-01-13 [RAN] - Changed the quadraticFormulaCheck function to
4 4
 ///                 prevent giving away the expression
5
-///     - 2015-06-09 [LAA] - Modified the graphics windwow so that you aren't
6
-///                 able to scroll
7 5
 
8 6
 #include "mainwindow.h"
9 7
 #include "ui_mainwindow.h"
10 8
 #include <QMessageBox>
11 9
 
12
-/// \fn MainWindow::MainWindow(QWidget *parent)
13
-/// \~English
14
-/// \brief Default constructor.
15
-/// \~Spanish
16
-/// \brief Constructor por defecto.
17
-///
18 10
 MainWindow::MainWindow(QWidget *parent) :
19 11
     QMainWindow(parent),
20 12
     ui(new Ui::MainWindow)
21 13
 {
22 14
     quadraticFormulaCheck();
23 15
 
24
-    // set up mainWindow
16
+
25 17
     ui->setupUi(this);
26 18
     scene= new QGraphicsScene(this);
27 19
     scene->setSceneRect(QRectF(QPointF(0,0), QPointF(0,0)));
@@ -29,9 +21,7 @@ MainWindow::MainWindow(QWidget *parent) :
29 21
     ui->MainView->setAlignment((Qt::AlignLeft | Qt::AlignTop));
30 22
     ui->MainView->resize(580,345);
31 23
     ui->MainView->move(0,0);
32
-    ui->MainView->setEnabled(false);
33 24
 
34
-    // set lables and buttons
35 25
     ui->alabel->move(10,360);
36 26
     ui->alineEdit->move(25,358);
37 27
     ui->blabel->move(85,360);
@@ -40,38 +30,29 @@ MainWindow::MainWindow(QWidget *parent) :
40 30
     ui->clineEdit->move(175,358);
41 31
     ui->RunPushButton->move(10,385);
42 32
     ui->retryButton->move(180,385);
43
-    ui->RunPushButton->setEnabled(false);
33
+
34
+
44 35
 
45 36
     frogger = new frog;
37
+    //ui->x1Label->setText(fr);
38
+   // ui->x1Label->move(frogger->xnenu2, 300);
46 39
     globalTimer = new QTimer;
47 40
     scene->addWidget(frogger);
48 41
 
42
+    ui->RunPushButton->setEnabled(false);
49 43
 
50 44
 }
51 45
 
52
-/// \fn MainWindow::~MainWindow()
53
-/// \~English
54
-/// \brief Default destructor
55
-/// \~Spanish
56
-/// \brief Destructor por defecto
57
-///
46
+
58 47
 MainWindow::~MainWindow()
59 48
 {
60 49
     delete ui;
61 50
     delete scene;
62 51
 }
63 52
 
64
-/// \fn void MainWindow::quadraticFormulaCheck()
65
-/// \~English
66
-/// \brief Function that uses an array of values to determine
67
-///  if the equation written by the student is correct.
68
-/// \~Spanish
69
-/// \brief Funcion que utiliza un arreglo de valores para
70
-///  determinar si la ecuacion que escribio el estudiante
71
-///  esta correcta.
72
-///
73 53
 void MainWindow::quadraticFormulaCheck()
74 54
 {
55
+    // float firstX;
75 56
     float resultFromFunction;
76 57
     bool pass = true;
77 58
     float values[] = {357 , -1000 , 698 , 1.4804781099 , 748 , -392 , 51 , 0.28391805554 ,
@@ -97,7 +78,7 @@ void MainWindow::quadraticFormulaCheck()
97 78
         // firstX = (((-b) + sqrt((pow(b,2)) - 4*a*c))/(2*a));
98 79
         resultFromFunction = frogger->QuadraticPlus(a,b,c);
99 80
 
100
-        if( fabs(resultFromFunction - expected) > 0.00001) {
81
+        if( abs(resultFromFunction - expected) > 0.00001) {
101 82
             pass = false;
102 83
         }
103 84
     }
@@ -116,7 +97,7 @@ void MainWindow::quadraticFormulaCheck()
116 97
         // firstX = (((-b) + sqrt((pow(b,2)) - 4*a*c))/(2*a));
117 98
         resultFromFunction = frogger->QuadraticMinus(a,b,c);
118 99
 
119
-        if( fabs(resultFromFunction - expected) > 0.00001) {
100
+        if( abs(resultFromFunction - expected) > 0.00001) {
120 101
             pass = false;
121 102
         }
122 103
     }
@@ -126,14 +107,6 @@ void MainWindow::quadraticFormulaCheck()
126 107
     }
127 108
 }
128 109
 
129
-/// \fn void on_RunPushButton_clicked()
130
-/// \~English
131
-/// \brief Function that is invoked when the jump button is pressed,
132
-///  frog jumps to calculated location.
133
-/// \~Spanish
134
-/// \brief Funcion que se invoca cuando el boton de "jump" es presionado,
135
-///  el sapo brinca a la localizacion calculada.
136
-///
137 110
 void MainWindow::on_RunPushButton_clicked()
138 111
 {
139 112
     int a = 0;
@@ -183,29 +156,12 @@ void MainWindow::on_RunPushButton_clicked()
183 156
 
184 157
 }
185 158
 
186
-/// \fn void on_retryButton_clicked()
187
-/// \~English
188
-/// \brief Function that is invoked when the reset button is pressed,
189
-///  returns the window to its original state.
190
-/// \~Spanish
191
-/// \brief Funcion que se invoca cuando el boton de "reset" es presionado,
192
-///  devuelve la ventana a su estado original.
193
-///
194 159
 void MainWindow::on_retryButton_clicked()
195 160
 {
196 161
     frogger->reset();
197 162
 }
198 163
 
199
-/// \fn MainWindow::on_alineEdit_textChanged(QString &arg1)
200
-/// \~English
201
-/// \brief Function that is invoked when the text is changed in the
202
-///  alineEdit, enables jump buttton if the other line edits aren't empty.
203
-/// \~Spanish
204
-/// \brief Funcion que se invoca cuando el texto dentro de alineEdit
205
-///  cambia, permite que el button de "jump" sea presionado si los otros
206
-///  "line edits" no estan vacios.
207
-///
208
-void MainWindow::on_alineEdit_textChanged()
164
+void MainWindow::on_alineEdit_textChanged(const QString &arg1)
209 165
 {
210 166
     if(ui->alineEdit->text() != "" && ui->blineEdit->text() != "" && ui->clineEdit->text() != "" ){
211 167
         ui->RunPushButton->setEnabled(true);
@@ -215,16 +171,7 @@ void MainWindow::on_alineEdit_textChanged()
215 171
     }
216 172
 }
217 173
 
218
-/// \fn MainWindow::on_blineEdit_textChanged(QString &arg1)
219
-/// \~English
220
-/// \brief Function that is invoked when the text is changed in the
221
-///  alineEdit, enables jump buttton if the other line edits aren't empty.
222
-/// \~Spanish
223
-/// \brief Funcion que se invoca cuando el texto dentro de alineEdit
224
-///  cambia, permite que el button de "jump" sea presionado si los otros
225
-///  "line edits" no estan vacios.
226
-///
227
-void MainWindow::on_blineEdit_textChanged()
174
+void MainWindow::on_blineEdit_textChanged(const QString &arg1)
228 175
 {
229 176
     if(ui->alineEdit->text() != "" && ui->blineEdit->text() != "" && ui->clineEdit->text() != "" ){
230 177
         ui->RunPushButton->setEnabled(true);
@@ -234,16 +181,9 @@ void MainWindow::on_blineEdit_textChanged()
234 181
     }
235 182
 }
236 183
 
237
-/// \fn MainWindow::on_clineEdit_textChanged(QString &arg1)
238
-/// \~English
239
-/// \brief Function that is invoked when the text is changed in the
240
-///  alineEdit, enables jump buttton if the other line edits aren't empty.
241
-/// \~Spanish
242
-/// \brief Funcion que se invoca cuando el texto dentro de alineEdit
243
-///  cambia, permite que el button de "jump" sea presionado si los otros
244
-///  "line edits" no estan vacios.
245
-///
246
-void MainWindow::on_clineEdit_textChanged()
184
+
185
+
186
+void MainWindow::on_clineEdit_textChanged(const QString &arg1)
247 187
 {
248 188
     if(ui->alineEdit->text() != "" && ui->blineEdit->text() != "" && ui->clineEdit->text() != "" ){
249 189
         ui->RunPushButton->setEnabled(true);

+ 3
- 69
mainwindow.h Vedi File

@@ -15,86 +15,20 @@ class MainWindow : public QMainWindow
15 15
     Q_OBJECT
16 16
 
17 17
 public:
18
-    /// \fn MainWindow::MainWindow(QWidget *parent)
19
-    /// \~English
20
-    /// \brief Default constructor.
21
-    /// \~Spanish
22
-    /// \brief Constructor por defecto.
23
-    ///
24 18
     explicit MainWindow(QWidget *parent = 0);
25
-
26
-    /// \fn MainWindow::~MainWindow()
27
-    /// \~English
28
-    /// \brief Default destructor
29
-    /// \~Spanish
30
-    /// \brief Destructor por defecto
31
-    ///
32 19
     ~MainWindow();
33
-
34
-    /// \fn void MainWindow::quadraticFormulaCheck()
35
-    /// \~English
36
-    /// \brief Function that uses an array of values to determine
37
-    ///  if the equation written by the student is correct.
38
-    /// \~Spanish
39
-    /// \brief Funcion que utiliza un arreglo de valores para
40
-    ///  determinar si la ecuacion que escribio el estudiante
41
-    ///  esta correcta.
42
-    ///
43 20
     void quadraticFormulaCheck();
44 21
 
45 22
 private slots:
46
-    /// \fn void on_RunPushButton_clicked()
47
-    /// \~English
48
-    /// \brief Function that is invoked when the jump button is pressed,
49
-    ///  frog jumps to calculated location.
50
-    /// \~Spanish
51
-    /// \brief Funcion que se invoca cuando el boton de "jump" es presionado,
52
-    ///  el sapo brinca a la localizacion calculada.
53
-    ///
54 23
     void on_RunPushButton_clicked();
55 24
 
56
-    /// \fn void on_retryButton_clicked()
57
-    /// \~English
58
-    /// \brief Function that is invoked when the reset button is pressed,
59
-    ///  returns the window to its original state.
60
-    /// \~Spanish
61
-    /// \brief Funcion que se invoca cuando el boton de "reset" es presionado,
62
-    ///  devuelve la ventana a su estado original.
63
-    ///
64 25
     void on_retryButton_clicked();
65 26
 
66
-    /// \fn MainWindow::on_alineEdit_textChanged(QString &arg1)
67
-    /// \~English
68
-    /// \brief Function that is invoked when the text is changed in the
69
-    ///  alineEdit, enables jump buttton if the other line edits aren't empty.
70
-    /// \~Spanish
71
-    /// \brief Funcion que se invoca cuando el texto dentro de alineEdit
72
-    ///  cambia, permite que el button de "jump" sea presionado si los otros
73
-    ///  "line edits" no estan vacios.
74
-    ///
75
-    void on_alineEdit_textChanged();
27
+    void on_alineEdit_textChanged(const QString &arg1);
76 28
 
77
-    /// \fn MainWindow::on_blineEdit_textChanged(QString &arg1)
78
-    /// \~English
79
-    /// \brief Function that is invoked when the text is changed in the
80
-    ///  alineEdit, enables jump buttton if the other line edits aren't empty.
81
-    /// \~Spanish
82
-    /// \brief Funcion que se invoca cuando el texto dentro de alineEdit
83
-    ///  cambia, permite que el button de "jump" sea presionado si los otros
84
-    ///  "line edits" no estan vacios.
85
-    ///
86
-    void on_blineEdit_textChanged();
29
+    void on_blineEdit_textChanged(const QString &arg1);
87 30
 
88
-    /// \fn MainWindow::on_clineEdit_textChanged(QString &arg1)
89
-    /// \~English
90
-    /// \brief Function that is invoked when the text is changed in the
91
-    ///  alineEdit, enables jump buttton if the other line edits aren't empty.
92
-    /// \~Spanish
93
-    /// \brief Funcion que se invoca cuando el texto dentro de alineEdit
94
-    ///  cambia, permite que el button de "jump" sea presionado si los otros
95
-    ///  "line edits" no estan vacios.
96
-    ///
97
-    void on_clineEdit_textChanged();
31
+    void on_clineEdit_textChanged(const QString &arg1);
98 32
 
99 33
 private:
100 34
     Ui::MainWindow *ui;