PDA

View Full Version : GUI: simple memory game(URGENT)



leeks
24th August 2013, 13:46
Can someone please help me answer this past exam question which uses C++ with Qt creator4 to help me prepare and feel confident before I write my exam.

Question:

write a GUI application that provides a simple memory game, where the application generates and displays 10 random but unique numbers between 1 and 50 for 10 seconds. the user has to memorise and enter these numbers on the GUI, which the application verifies before displaying a score to the user.
The application should satisfy the following:
-A start button is provided on the GUI in order for the application to display the random numbers.
-use a QTimer to manage the time for which the numbers should be displayed.
-Provide a widget where the user can enter the numbers that were randomly generated and displayed. An error message is displayed if the user enters values that are non numeric . Alternatively you may program the input widget to ensure that it does not accept non numeric values.
-You may provide another button for the user to indicate when he\she has completed entering the numbers.
-the randomly generated numbers are only displayed for 10 seconds. once this time lapses, the numbers are no longer visible to the user.
-the widget in which the user can enter the numbers should be read only when the numbers are displayed, i.e the user is not allowed to type numbers while being displayed on the GUI.
-Provide a score to the user.


Someone please help me urgently since I am writing my exam on the 7th of September and I came across this question in a past exam and don't know how to do it. Thanks alot

wysota
24th August 2013, 14:16
Which part are you having problems with?

leeks
24th August 2013, 14:49
I have no idea where to begin or what to do at all with this question even though I have done other programs and got them to work perfectly. I think I am more stressed because I am writing soon and don't know how to even start this specific question

Added after 12 minutes:

I assume based on previous written code that my header file should contain functions such as:

void displayNumber()
void setTimer()

I know I should have an argument constructor such as:
RandomNumber();

I know I should have:
QTimer *timer;
void setupGUI;

I know I am suppose to have buttons implemented:
QLabel* TimerLabel;
QPushButton* okButton;
QPushButton* cancelButton;

but I don't know how to correctly set this up in a header file and then do them in the implementation and main file

wysota
24th August 2013, 15:44
I have no idea where to begin
So... you're taking a test on Qt and you have no idea where to begin? This doesn't sound like "I'd like to prepare better for my exam" but rather "Oh god! I have an exam in two weeks and I don't even know what this whole 'Qt' is!".

We can help you with a school project by giving hints but the site rules forbid us from solving your projects for you.

leeks
24th August 2013, 18:37
I will appreciate all the help I can get please. it is not my school project :-) I studied and did all my assignments and I was doing past exam papers since I took this course for my own added knowledge apart from my degree, but upon doing the past exam papers I came across this GUI question which frightened me since I did not do an application such as this before. I have been working with console apps on uml diagrams and QMessage boxes and the text editor mainly since our scope for this course didn't do GUI's such as the above mentioned app. upon seeing this question in a past exam I just feel it would be best to cover all bases and for me to know as much as I can.

Added after 1 6 minutes:

if I am not mistaken, I would assume that my header file would be something like:


#indef Randoms_H
#define Randoms_H
#include <QWidget>
#include <QLabel>
#include <QPushButton>
#include <QLineEdit>
#include <QTimer>

using namespace std;

class Randoms:public QWidget
{
Q_Object

public:
//constructor
Randoms();

private slots:
//set timer
void set_Timer();
//display numbers
void displayMessage();
void changeTimerValue();

private:
//widget data members
QLabel* timerLabel;
QLineEdit* m_timer_entry;
QPushButton* okButton;
QpushButton* cancelButton;

//timer
QTimer* m_timer;
//sets the GUI
void setUpGUI();

};

#endif




I know to generate the numbers between 1 and 50 I have to use the expression:

rand () % 50) +1;




with regards to the implementation(.cpp)


#include <stdlib.h>
#include <time.h>
#include <QWidget>
#include <QGridLayout>
#include <QLabel>
#include <QPushButton>
#include <QTimer>
#include <QMessageBox>
#include <"randoms.h">

Randoms::Randoms()
{
setWindowTitle("Numbers");
QGridLayout* layout = new QGridLayout (this),

QLabel* timer_value = new QLabel("Timer Interval")
m_timer_entry = new QLineEdit(),
QPushButton* set_timer = new QPushButton("Set Timer");


m_timer_entry->setText("10");

layout->addWidget(timer_value, 0, 0);
layout->addWidget(m_timer_entry, 0, 1);
layout->addWidget(set_timer, 1, 1)


m_timer = new QTimer(this),
m_timer->setInterval(10),
m_timer->start();
m_started = true,

QObject::connect(set_timer, SIGNAL(clicked()), this, SLOT(changeTimerValue()),
QObject::connect(m_timer, SIGNAL(timeout(), this, SLOT(displayMessage()));
}



incomplete because I am unsure if it is correct so far

leeks
26th August 2013, 15:13
someone please help on this, I am stressing over it

wysota
26th August 2013, 15:27
You should first ask yourself how you wish to show those numbers. The simplest way is to use QLabel instances for that. Then think how you want to allow the user to enter those numbers. The simplest way is to use QLineEdit or QSpinBox. Get that on screen first instead of struggling with the timer.

leeks
26th August 2013, 16:07
ok thanks a lot for the advice, I will try that now