Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Newbie and creating a mastermind-type game in C++ (http://www.velocityreviews.com/forums/t287400-newbie-and-creating-a-mastermind-type-game-in-c.html)

Kraig 12-07-2004 12:37 AM

Newbie and creating a mastermind-type game in C++
 
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!

Rolf Magnus 12-07-2004 01:18 AM

Re: Newbie and creating a mastermind-type game in C++
 
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.


David White 12-07-2004 01:30 AM

Re: Newbie and creating a mastermind-type game in C++
 
"Kraig" <tsi1990@gmail.com> wrote in message
news:pW6td.43220$Ch2.15138@bignews5.bellsouth.net. ..
> 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




Will Twentyman 12-07-2004 05:48 PM

Re: Newbie and creating a mastermind-type game in C++
 
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

Kraig 12-09-2004 12:04 AM

Re: Newbie and creating a mastermind-type game in C++
 
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!

David White 12-09-2004 11:36 PM

Re: Newbie and creating a mastermind-type game in C++
 
"Kraig" <tsi1990@gmail.com> wrote in message
news:tEMtd.62679$fY.56933@bignews3.bellsouth.net.. .
> 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




Will Twentyman 12-10-2004 01:40 AM

Re: Newbie and creating a mastermind-type game in C++
 
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


All times are GMT. The time now is 10:45 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.