Archived

This topic is now archived and is closed to further replies.

pdstatha

Towers of Hanoi

Recommended Posts

Hey peeps, I''ve been programming for a good while now so I decided it was about time I programmed my first simple game. So what did I choose, an old classic Towers of Hanoi. I''ve been through the description of the problem several times and have formulised this initial list of classes, with their functions and attributes. Any feedback would be greatly appreciated, also what do you think I should use the DirectX API or the Windows API?? Towers of Hanoi class identification Candidate classes v1.0 · User · Pegs · Rings · Rules · Move · Interface · Difficulty · Game · Goal · Message Refined list v1.0 · Peg · Ring · Rules · Move · Interface · Difficulty CRC List v1.0 Class name: peg Responsibilities: Collaborators: · To hold the rings of Ring varying sizes Rules · To recognize whether Move a move is valid or not Class name: ring Responsibilities: Collaborators: · Creates rings of Peg varying sizes Move Class name: rules Responsibilites: Collaborators: · Holds details of the Peg rules of the game Move Class name: move Responsibilities: Collaborators: · Responsible for Ring moving rings from Peg one peg to the next Class name: difficulty Responsibilities: Collaborators: · Holds the settings for each difficulty setting. Part way through the identifying the attributes and functions for each class I realised that I could shorten the class list once again the class list now stands as. Refined list v1.1 · Peg · Ring · Difficulty Identifying the parameters and functions for the classes Class name: Peg Attributes: · itsName : String Functions: · getName() · setName() · addRing() · removeRing() · checkMove() Class name: Ring Attributes: · itsSize : int Functions: · getSize() · setSize() · moveRing() Class name: Difficulty Attributes: · ringNumber : int · itsName : String Functions: · getDifficulty() · setDifficulty() · getName() · setName()

Share this post


Link to post
Share on other sites
You are way over-ooping the whole problem. Something like a ring, which only has stores size would be better as a struct.And a class for move? Have the pegs as stacks and just call
peg1.pushRing = peg2.popRing. If you were using java I guess this might all be ok since everyting has to be a class, but if you are using c++ then you might want to calm down a little. As a rule, if a class is nothing more than setX and getX functions, make it a struct.

I commend you though for thinking your game out first, definitly a sign that you can finish it.

And as for asking which API, this is a kind of troll question but I will give you the benefit of the doubt. Note that this is entirly just my opinion and Im not saying that its right or wrong. Using directx allientes a whole audiance for your game. Anyone who uses a mac or runs linux or any OS other than windows cant use your game. Look into SDL (www.libsdl.org) and go to cone3d.gamedev.net for some good tutorials for it. It does just about everything you would want from directx but is platform independent.

One last thing that cought my curiosity. What difficulty settings do you have in mind besides just more rings (maybe set a time limit?)

Share this post


Link to post
Share on other sites
Well spotted, I do Indeed come from a java background and have recently converted to C++. What exactly is the difference between a struct and class in C++ anyway, they seem very similar. As for the difficulty i''m not sure about the time limit as after 5 rings it starts to get hard and after 9 a very arduous task indeed.

Share this post


Link to post
Share on other sites
A class is a way of abstracting the actual data. It has private members (data) and public members (functions to use that data). It''s default is private meaning if you don''t specify a private area, all data is private. A struct is just data and its members are public by default.

Share this post


Link to post
Share on other sites
Since its a 90% windows world, use DirectX. Its far faster than windows API functions, and "guaruntees" hardware compatibility. You may read that OpenGL is faster than D3D. This is not true since the release of DX8.

Proceeding on a brutal rampage is the obvious choice.

Share this post


Link to post
Share on other sites
quote:
Original post by randomDecay
A class is a way of abstracting the actual data. It has private members (data) and public members (functions to use that data). It''s default is private meaning if you don''t specify a private area, all data is private. A struct is just data and its members are public by default.

Not exactly true.

In C++ structs and classes are the exact same thing with one exception: The default access-modifier for classes is ''private'', and the default for structs is ''public''. Both of them can contain member-functions.

Share this post


Link to post
Share on other sites
Since its a 90% windows world, use DirectX. Its far faster than windows API functions, and "guaruntees" hardware compatibility. You may read that OpenGL is faster than D3D. This is not true since the release of DX8.


I really want to reply to that, but I dont want to get this thread closed since that isnt fair to pdstatha.

Edited by - antistuff on February 7, 2002 7:21:07 PM

Share this post


Link to post
Share on other sites