Newbie and creating a mastermind-type game in C++

Discussion in 'C++' started by Kraig, Dec 7, 2004.

  1. Kraig

    Kraig Guest

    Hi! As a total newcomer to C++ and programming, I'm trying to create a
    variant of the mastermind game using two classes. Why two classes?
    Because it will help me understand how classes and constructors work.
    I've seen examples of the program, but none use a two class structure.

    **What I'm looking for is design thoughts (what data/attributes and
    methods?) for the classes.

    Basically, what happens is when the game starts, at creation of an
    instance, the computer chooses a random string of digits. The user can
    specify the length of the string and the range of digits to be used in a
    class constructor. If, for example, the user wants to have seven
    different digits, only the digits 1, 2, 3, ...7 will be used. In this
    case, the string 45561 would be a string of length five. The player's
    job is to find out which string the computer chose using a series of
    guesses.

    As always, ideas/comments appreciated!
     
    Kraig, Dec 7, 2004
    #1
    1. Advertising

  2. Kraig

    Rolf Magnus Guest

    Kraig wrote:

    > **What I'm looking for is design thoughts (what data/attributes and
    > methods?) for the classes.


    Then you are better off in a newsgroup about object oriented software
    design, like e.g. comp.object. comp.lang.c++ is more about the C++ language
    itself than about software design.
     
    Rolf Magnus, Dec 7, 2004
    #2
    1. Advertising

  3. Kraig

    David White Guest

    "Kraig" <> wrote in message
    news:pW6td.43220$...
    > Hi! As a total newcomer to C++ and programming, I'm trying to create a
    > variant of the mastermind game using two classes. Why two classes?
    > Because it will help me understand how classes and constructors work.
    > I've seen examples of the program, but none use a two class structure.
    >
    > **What I'm looking for is design thoughts (what data/attributes and
    > methods?) for the classes.
    >
    > Basically, what happens is when the game starts, at creation of an
    > instance, the computer chooses a random string of digits. The user can
    > specify the length of the string and the range of digits to be used in a
    > class constructor. If, for example, the user wants to have seven
    > different digits, only the digits 1, 2, 3, ...7 will be used. In this
    > case, the string 45561 would be a string of length five. The player's
    > job is to find out which string the computer chose using a series of
    > guesses.
    >
    > As always, ideas/comments appreciated!


    So, you aren't designing a program that guesses the human's digit string?
    That would be much more fun.

    For the problem you've described, I don't see a need for two classes. A
    single class can generate the digit string and then answer for a given guess
    how many digits are correct and in the right position and correct but in the
    wrong position. I think one class is the best design. However, if you want
    to use two classes, you could have one class to represent a single digit (it
    could answer true or false whether another given digit matches it), and have
    a collection of objects of the digit class in the digit-string class.

    DW
     
    David White, Dec 7, 2004
    #3
  4. Kraig wrote:

    > Hi! As a total newcomer to C++ and programming, I'm trying to create a
    > variant of the mastermind game using two classes. Why two classes?
    > Because it will help me understand how classes and constructors work.
    > I've seen examples of the program, but none use a two class structure.
    >
    > **What I'm looking for is design thoughts (what data/attributes and
    > methods?) for the classes.


    Usually, it seems like if you don't see how to have two classes, then
    forcing it makes a larger, tougher program. Yahtzee seems easier, where
    you can have a score-card class and a roll class.

    --
    Will Twentyman
    email: wtwentyman at copper dot net
     
    Will Twentyman, Dec 7, 2004
    #4
  5. Kraig

    Kraig Guest

    Will Twentyman wrote:
    > Kraig wrote:
    >
    >> Hi! As a total newcomer to C++ and programming, I'm trying to create
    >> a variant of the mastermind game using two classes. Why two classes?
    >> Because it will help me understand how classes and constructors work.
    >> I've seen examples of the program, but none use a two class structure.
    >>
    >> **What I'm looking for is design thoughts (what data/attributes and
    >> methods?) for the classes.

    >
    >
    > Usually, it seems like if you don't see how to have two classes, then
    > forcing it makes a larger, tougher program. Yahtzee seems easier, where
    > you can have a score-card class and a roll class.
    >

    So far, I've come up with the following as a basic structure for my program:

    int iGuess;
    MasterMindString mmsMine(5,7); // create the hidden number
    //Use 5 digits each from 0 thru 7 for the hidden number, not sure how to
    generate

    MasterMindGame mmgGame(25);
    //Allows a maximum of 25 guesses before ending the game, but how do I
    implement?

    do // iterate, make a guess, check it, stop if right
    {
    cout << "Enter your " << mmsMine.NumDigits() << " guess : ";
    cin >> iGuess;
    mmsMine.Check( iGuess );

    } until (mmgGame.RightGuess());

    Obviously, it is far from complete and I'm still learning. I hope the
    above code makes sense, as I feel I'm getting the hang of it but need
    more understanding of how to make it work. Thanks for any help you can
    provide!
     
    Kraig, Dec 9, 2004
    #5
  6. Kraig

    David White Guest

    "Kraig" <> wrote in message
    news:tEMtd.62679$...
    > Will Twentyman wrote:
    > > Kraig wrote:
    > >
    > >> Hi! As a total newcomer to C++ and programming, I'm trying to create
    > >> a variant of the mastermind game using two classes. Why two classes?
    > >> Because it will help me understand how classes and constructors work.
    > >> I've seen examples of the program, but none use a two class structure.
    > >>
    > >> **What I'm looking for is design thoughts (what data/attributes and
    > >> methods?) for the classes.

    > >
    > >
    > > Usually, it seems like if you don't see how to have two classes, then
    > > forcing it makes a larger, tougher program. Yahtzee seems easier, where
    > > you can have a score-card class and a roll class.
    > >

    > So far, I've come up with the following as a basic structure for my

    program:
    >
    > int iGuess;
    > MasterMindString mmsMine(5,7); // create the hidden number
    > //Use 5 digits each from 0 thru 7 for the hidden number, not sure how to
    > generate


    Look up the 'rand' function and see what you can do with it.

    > MasterMindGame mmgGame(25);
    > //Allows a maximum of 25 guesses before ending the game, but how do I
    > implement?


    Have a counter member in MasterMindGame that counts the guesses, check the
    value after each guess and stop the game when it reaches 25. If you don't
    know how to do this, then I suggest a good book on C++ to assist you.

    DW
     
    David White, Dec 9, 2004
    #6
  7. Kraig wrote:

    > Will Twentyman wrote:
    >
    >> Kraig wrote:
    >>
    >>> Hi! As a total newcomer to C++ and programming, I'm trying to create
    >>> a variant of the mastermind game using two classes. Why two classes?
    >>> Because it will help me understand how classes and constructors work.
    >>> I've seen examples of the program, but none use a two class structure.
    >>>
    >>> **What I'm looking for is design thoughts (what data/attributes and
    >>> methods?) for the classes.

    >>
    >>
    >>
    >> Usually, it seems like if you don't see how to have two classes, then
    >> forcing it makes a larger, tougher program. Yahtzee seems easier,
    >> where you can have a score-card class and a roll class.
    >>

    > So far, I've come up with the following as a basic structure for my
    > program:
    >
    > int iGuess;
    > MasterMindString mmsMine(5,7); // create the hidden number
    > //Use 5 digits each from 0 thru 7 for the hidden number, not sure how to
    > generate


    I would give the MasterMindString two methods for comparing to get the
    number of right digit right locations and right digit wrong locations.

    > MasterMindGame mmgGame(25);
    > //Allows a maximum of 25 guesses before ending the game, but how do I
    > implement?


    I'd have iGuess as a data member of MasterMindGame

    >
    > do // iterate, make a guess, check it, stop if right
    > {
    > cout << "Enter your " << mmsMine.NumDigits() << " guess : ";
    > cin >> iGuess;
    > mmsMine.Check( iGuess );
    >
    > } until (mmgGame.RightGuess());
    >
    > Obviously, it is far from complete and I'm still learning. I hope the
    > above code makes sense, as I feel I'm getting the hang of it but need
    > more understanding of how to make it work. Thanks for any help you can
    > provide!



    --
    Will Twentyman
    email: wtwentyman at copper dot net
     
    Will Twentyman, Dec 10, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. BlackHawke
    Replies:
    12
    Views:
    1,580
    Andrew Thompson
    Jan 26, 2004
  2. judith
    Replies:
    0
    Views:
    1,664
    judith
    Nov 1, 2006
  3. Mastermind

    , Jun 13, 2008, in forum: C++
    Replies:
    2
    Views:
    582
  4. ImmortalFire

    c++ mastermind game console app

    ImmortalFire, Jun 22, 2008, in forum: C++
    Replies:
    0
    Views:
    666
    ImmortalFire
    Jun 22, 2008
  5. Steve Jones

    Ruby Mastermind Game

    Steve Jones, Oct 30, 2008, in forum: Ruby
    Replies:
    4
    Views:
    106
    Todd Benson
    Nov 1, 2008
Loading...

Share This Page