Advertisement

C++ Workshop - Project 1

Started by August 16, 2006 05:41 PM
193 comments, last by me_minus 15 years, 3 months ago
churchskiz (or anyone): please explain what this line means:
choice[0]=toupper(choice[0]);

deyja: What your saying is that getch isnt c++? and, is that reason enough to never use it? and, is there a c++ alternative?
and btw,
[opinion]
user usually expects to
- see what he typed
- get a chance to breath and hit ENTER before action happens upon his input
[/opinion]
Quote:
Original post by kingIZZZY
churchskiz (or anyone): please explain what this line means:
choice[0]=toupper(choice[0]);

deyja: What your saying is that getch isnt c++? and, is that reason enough to never use it? and, is there a c++ alternative?
and btw,
[opinion]
user usually expects to
- see what he typed
- get a chance to breath and hit ENTER before action happens upon his input
[/opinion]


choice is a string, which is really just an array of characters (with some extra functionality built in).

So the line:
choice[0]=toupper(choice[0]);

takes the first character in the string, makes it upper case, and then sets it to the first character in the string. This keeps you from having to test each input against a lower case condition and an upper case condition.

string a="a";
string b="A";
string c=toupper(a[0]);
a!=b;
a!=c;
b==c;

I'm not sure what languages support getch, but it is a valid form of receiving input. I chose not to use it for the reason you mentioned, I wanted the user to be able to see his input before having it used, but in situations where you just want to pause for key input it is an easy method to see if they hit a key.
Advertisement
I almost have all my coding done for the project, but I keep running in to the same problems when I want to put it all together. The problem is that I include headers files in files that are in the same hierarchy and therefore I get compilation errors that some classes are defined more than once.

Take the following example:

Menu.hclass Menu{};MainMenu.h#include "Menu.h"class MainMenu : public Menu{};CharacterMenu.h#include "Menu.h"class CharacterMenu : public Menu{};


With my 13 week C++ experience I think this looks ok. But when I try to use my classes together in an other class:

Main.cpp#include "MainMenu.h"#include "CharacterMenu.h"


I get compilation errors saying that Menu has been defined more than once. Now I understand why the compiler is complaining, the definition of class Menu is copied in twice because the header is included in both menus. What I don't understand is how I should handle this.

I'm puzzled why this problem does not occur for iostream or string. I can include these on any level and the compiler will never complain about those, or so it seems.

I'm looking for some design guideline which will prevent me from making the error above. Is there such guideline? And I'm wondering what is different about the std header files.
Quote:
Original post by RinusMaximus
I almost have all my coding done for the project, but I keep running in to the same problems when I want to put it all together. The problem is that I include headers files in files that are in the same hierarchy and therefore I get compilation errors that some classes are defined more than once.

Take the following example:

Menu.hclass Menu{};MainMenu.h#include "Menu.h"class MainMenu : public Menu{};CharacterMenu.h#include "Menu.h"class CharacterMenu : public Menu{};


With my 13 week C++ experience I think this looks ok. But when I try to use my classes together in an other class:

Main.cpp#include "MainMenu.h"#include "CharacterMenu.h"


I get compilation errors saying that Menu has been defined more than once. Now I understand why the compiler is complaining, the definition of class Menu is copied in twice because the header is included in both menus. What I don't understand is how I should handle this.

I'm puzzled why this problem does not occur for iostream or string. I can include these on any level and the compiler will never complain about those, or so it seems.

I'm looking for some design guideline which will prevent me from making the error above. Is there such guideline? And I'm wondering what is different about the std header files.


What you want are include guards (this is a google search on this subject - it will point you to many valuable informations).

Regards,
Quote:
deyja: What your saying is that getch isnt c++? and, is that reason enough to never use it? and, is there a c++ alternative?
and btw,
[opinion]
user usually expects to
- see what he typed
- get a chance to breath and hit ENTER before action happens upon his input
[/opinion]


getch is part of the C standard library, and is thus also part of the C++ standard library.

And your opinion is highly subjective. Nor does using getch preclude the user from seeing what he typed.
I started coding for the project a few days ago and i am nearly done with all the parts and just need to put them together.
The only thing i havent done is the equipment. Now i entered the workshop somewhat late and i have just reached pointers. I believe i can do the equipment bit with what i learned so far, but i was wondering if it would be better to reach arrays before i code them(as it was mentioned somewhere that we might need arrays).

basicaly what i wanted to ask was whether chapters 9 - 13 introduce concepts that will make this part easier or not.
Advertisement
Hi, I've been looking at the workshop on days when I don't have much to do, and this project was something I really could have used a while back >.< Anyway, I'm making a text game and it's along the lines of something like this, so I was wondering if I get the battling system done and my saving/loading to work, can I post it here so you guys can tell me what you think of it?

Anyway, I hope you guys are able to pull this off!! It will really help you get the idea of how to do things in programming. Many of the things I thought would be simple have given me problems I didn't even think of, but it's good to learn that way. (To me anyway)

Keep up the work guys! :)
Quote:
Original post by gparali
I started coding for the project a few days ago and i am nearly done with all the parts and just need to put them together.
The only thing i havent done is the equipment. Now i entered the workshop somewhat late and i have just reached pointers. I believe i can do the equipment bit with what i learned so far, but i was wondering if it would be better to reach arrays before i code them(as it was mentioned somewhere that we might need arrays).

basicaly what i wanted to ask was whether chapters 9 - 13 introduce concepts that will make this part easier or not.


I would imagine you'd want to use arrays or vectors for the equipment. I can't really think of an easy to use, well designed solution that doesn't involve an array or vector of some sort. What's your idea without an array? If it will work and you can do it, then go for it. If it creates complex code that is hard to maintain, do a quick array tutorial on the internet first and see if you can't come up with a better idea.
Well i havent realy thought about how exactly i will do it, but i am pretty sure it will be an inellegant brute force way. As for the tutorial, i am not in any hurry. I can wait until i read the arrays chapter. I might even try it without arrays just to see if i can do it.

Anyway thanks for the quik reply ChurchSkiz.

By the way i saw your blog and i was wondering why you are following the workshop. You evidently know how to program and have some games under your belt.Unless the games were writen in a different language.
Quote:
Original post by gparali
Well i havent realy thought about how exactly i will do it, but i am pretty sure it will be an inellegant brute force way. As for the tutorial, i am not in any hurry. I can wait until i read the arrays chapter. I might even try it without arrays just to see if i can do it.

Anyway thanks for the quik reply ChurchSkiz.

By the way i saw your blog and i was wondering why you are following the workshop. You evidently know how to program and have some games under your belt.Unless the games were writen in a different language.


My coding practices are pretty bad. This was my first attempt at an Object Oriented approach. You'll see when I post my code that it still isn't pretty, but I made a lot of progress in design. I wanted to do the workshop because I liked how the guidelines were set up so that we could concentrate more on design principles rather than gameplay. I also needed some practice with File I/O and input handling. As with all completed projects, I learned a hell of a lot and will use a lot of what I learned when I create my next game. I actually got to use the stuff I learned when implementing my weapons class at work, taking input from an Excel file and reformatting it into a format specific space delimited text file. It allowed me to completely eliminate an old legacy system that our company used, and may even get me a raise.

Anyway, as promised here is my source code and project files if anyone needs some help with ideas. Don't look at it as an example of good structure, naming conventions, and design principles, only as innertia to get your own programming juices flowing.

Console Combat Source

Get cracking on those projects so we can see some more demos on the board!

This topic is closed to new replies.

Advertisement