Would classes be good for this?

I want to implement an item system into a text-based game, are classes suitable for this?
That's not much to go on, but in general, yes.
I hope by "text-based" you mean "using a graphics library like SFML to draw text to the screen myself" and not "I'm using the console because I can't figure out how to use the graphics libraries and I didn't realize I could ask for help on this great forum"
Classes for this are completely suitable.
Lets say I made a game where you would memorize flash cards, then input them back into the computer.
I could make a class hat takes the users input, then checks to make sure its correct. If it is correct, it sets a variable (int CorrectYesNo) to 1 for yes or 0 for no.
Hope that helped :D
//Bman
@Sir Mr Bman: that is actually a mis-use of classes. You should not use classes for that ;)
Sure, let's use a graphic library to print text.
You can't print text with a graphics library.
I was lurking and I just had to post, I laughed out loud at L B's reply.
$ dict print
From The Jargon File (version 4.4.7, 29 Dec 2003) [jargon]:

To output, even if to a screen. If a hacker says that a program 'printed
a message', he means this; if he refers to printing a file, he probably
means it in the conventional sense of writing to a hardcopy device
(compounds like 'print job' and 'printout', on the other hand, always
refer to the latter). This very common term is likely a holdover from the
days when printing terminals were the norm, perpetuated by programming
language constructs like {C}'s printf(3). See senses 1 and 2 of {tty}.
Classes are more than useful for that:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
#include <cstring>

using namespace std;

class Item 
{
private:
	int weight;
	string name;
public:
	Item(int, string);
	void useItem();
};

Item::Item(int w, string n)
{
	weight=w;
	name=n;
}

void Item::useItem()
{
	cout << name << " was used\n";
	cout << weight << " mass unit was removed from inventory\n";
}

int main()
{
	Item sword(33, "Saber");
	Item armor(123, "Glowing Armor of Usefulness");

	sword.useItem();
	armor.useItem();

	return 0;
}


Maybe using some class to handle possible inventory would help too :)
You may want to have different types of swords/armors/potions/etc. in which case, you can inherit from the Item class.
You may want to have different types of swords/armors/potions/etc. in which case, you can inherit from the Item class.


I know; just made short example
Last edited on
Thanks guys, and L B, I'm still getting just standard c++ down, I didn't think it would be a good idea to jump into something like SDL or Allegro yet. Chances are I'm not even going to finish this, I'm doing it entirely for learning.
Topic archived. No new replies allowed.