Before I get Much Further Into Development...
Posted: Mon Apr 13, 2009 10:07 pm
Is this the right way to use classes and stuff? I mean books only show you little snippets of using classes so Im asking here. Yes it will be a text based game, and not like the usual fight game, its more like a sim. Im taking it slowly cause I tried to jump right into SDL and other Graphic Libraries and I thought to my self, why not make it easier to make it in text version then translate into GUI after I get the core down...
main.cpp
NewGame.cpp
NewGame.h
Not much done, but that only took like 20 minutes to code...
How do I use the Variables declared in my NewGame class from another one?
main.cpp
Code: Select all
#include <iostream>
#include <fstream>
#include "NewGame.cpp"
int main()
{
NewGame NG;
NG.GetName();
NG.GetBT();
NG.DisplayName();
NG.DisplayBT();
NG.DisplayBF();
system("PAUSE");
}
Code: Select all
#include <iostream>
#include "NewGame.h"
void NewGame::GetName()
{
std::cout << "Whats Your Name?\n";
std::cin >> Name;
}
void NewGame::GetBT()
{
std::cout << "What Body Type Are You?\n1 = Ectomorph\t2 = Mesomorph\t3 = Endomorph\n";
std::cin >> BodyType;
if (BodyType > 3 || BodyType < 1 )
{
std::cout << "WRONG NUMBER DUMBASS!\n";
GetBT();
}
if (BodyType == 1)
{
BodyFat = 10;
}
if (BodyType == 2)
{
BodyFat = 15;
}
if (BodyType == 3)
{
BodyFat = 20;
}
}
void NewGame::DisplayBT()
{
if (BodyType == 1)
{
std::cout << "Ectomorph";
}
if (BodyType == 2)
{
std::cout << "Mesomorph";
}
if (BodyType == 3)
{
std::cout << "Endomorph";
}
}
void NewGame::DisplayBF()
{
std::cout << BodyFat;
}
void NewGame::DisplayName()
{
std::cout << Name;
}
Code: Select all
#include <iostream>
class NewGame
{
public:
float BodyFat;
int BodyType;
char Name[10];
void GetName();
void GetBT();
void DisplayBT();
void DisplayBF();
void DisplayName();
};
Not much done, but that only took like 20 minutes to code...
How do I use the Variables declared in my NewGame class from another one?