Results 1 to 8 of 8

Thread: GUI: simple memory game(URGENT)

  1. #1
    Join Date
    Aug 2013
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default GUI: simple memory game(URGENT)

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: GUI: simple memory game(URGENT)

    Which part are you having problems with?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Aug 2013
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: GUI: simple memory game(URGENT)

    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
    Last edited by leeks; 24th August 2013 at 13:49.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: GUI: simple memory game(URGENT)

    Quote Originally Posted by leeks View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Aug 2013
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: GUI: simple memory game(URGENT)

    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:

    Qt Code:
    1. #indef Randoms_H
    2. #define Randoms_H
    3. #include <QWidget>
    4. #include <QLabel>
    5. #include <QPushButton>
    6. #include <QLineEdit>
    7. #include <QTimer>
    8.  
    9. using namespace std;
    10.  
    11. class Randoms:public QWidget
    12. {
    13. Q_Object
    14.  
    15. public:
    16. //constructor
    17. Randoms();
    18.  
    19. private slots:
    20. //set timer
    21. void set_Timer();
    22. //display numbers
    23. void displayMessage();
    24. void changeTimerValue();
    25.  
    26. private:
    27. //widget data members
    28. QLabel* timerLabel;
    29. QLineEdit* m_timer_entry;
    30. QPushButton* okButton;
    31. QpushButton* cancelButton;
    32.  
    33. //timer
    34. QTimer* m_timer;
    35. //sets the GUI
    36. void setUpGUI();
    37.  
    38. };
    39.  
    40. #endif
    To copy to clipboard, switch view to plain text mode 




    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)

    Qt Code:
    1. #include <stdlib.h>
    2. #include <time.h>
    3. #include <QWidget>
    4. #include <QGridLayout>
    5. #include <QLabel>
    6. #include <QPushButton>
    7. #include <QTimer>
    8. #include <QMessageBox>
    9. #include <"randoms.h">
    10.  
    11. Randoms::Randoms()
    12. {
    13. setWindowTitle("Numbers");
    14. QGridLayout* layout = new QGridLayout (this),
    15.  
    16. QLabel* timer_value = new QLabel("Timer Interval")
    17. m_timer_entry = new QLineEdit(),
    18. QPushButton* set_timer = new QPushButton("Set Timer");
    19.  
    20.  
    21. m_timer_entry->setText("10");
    22.  
    23. layout->addWidget(timer_value, 0, 0);
    24. layout->addWidget(m_timer_entry, 0, 1);
    25. layout->addWidget(set_timer, 1, 1)
    26.  
    27.  
    28. m_timer = new QTimer(this),
    29. m_timer->setInterval(10),
    30. m_timer->start();
    31. m_started = true,
    32.  
    33. QObject::connect(set_timer, SIGNAL(clicked()), this, SLOT(changeTimerValue()),
    34. QObject::connect(m_timer, SIGNAL(timeout(), this, SLOT(displayMessage()));
    35. }
    To copy to clipboard, switch view to plain text mode 



    incomplete because I am unsure if it is correct so far
    Last edited by wysota; 26th August 2013 at 14:24. Reason: missing [code] tags

  6. #6
    Join Date
    Aug 2013
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: GUI: simple memory game(URGENT)

    someone please help on this, I am stressing over it

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: GUI: simple memory game(URGENT)

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Aug 2013
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: GUI: simple memory game(URGENT)

    ok thanks a lot for the advice, I will try that now

Similar Threads

  1. bluetooth for a simple 2 player game???
    By mahsa in forum Newbie
    Replies: 0
    Last Post: 4th August 2012, 10:23
  2. a simple game, much trouble
    By kennethadammiller in forum Newbie
    Replies: 1
    Last Post: 9th July 2010, 04:07
  3. Memory usage of simple Qt app
    By DiamonDogX in forum Qt Programming
    Replies: 1
    Last Post: 23rd September 2009, 06:53
  4. [URGENT] Weird compile error [URGENT]
    By MarkoSan in forum Qt Programming
    Replies: 3
    Last Post: 24th May 2008, 23:54
  5. Qt3 Memory game
    By rjk in forum Qt Programming
    Replies: 3
    Last Post: 6th December 2007, 21:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.