• Advertisement
Sign in to follow this  
  • entries
    61
  • comments
    131
  • views
    32140

I started working on a TXT RPG yesterday

Sign in to follow this  

130 views

I skimmed trough my directories last night and figured that I have never really completed the "real" projects I have worked on. So I decided that this had to change.

So yesterday evening I started working on a TXT RPG. And to be honest with you, I think it goes by very well.

I don't want to compile though, because it will produce so much errors I will just throw the whole project straight into the dusty directories of mine.

So, anyways. Here is the code, hope it keeps the formatting:

main.cpp

/**********************************************
/*PROJECT NAME: Unknown
/*PROJECT CODENAME: Project X
/*DEVELOPER: Oyvind Jarto Ege, PixelBox
/*Last Updated - Sun 29 Jan 2006
/*Builds - 0
/**********************************************
/*TODO - Add a World Class to store all the connected rooms | Create a CPlayer class to handle player input etc | Complete the CRoomDatabase | Complete the CMonsterDatabase | Comment the other files
/*BUGS - N/A
/***************
/*THANKS TO
/*www.cplusplus.com
/*www.gamedev.net
***********************************************/

#include
#include
//#include //Need to see if this works without this header
#include
#include //Includes the IO.cpp file wich in turn includes the IO.h file wich contains the code necessary to load a line from a text file

using namespace std;

/**********
/*GLOBALS
/*LAST UPDATED - 29 Jan 2006
***********/


bool end; //A bool to specify when the end of the program is.

/***************
/*Monster struct
/***************
/*USE - Holds data to all monster in the world
/*VERSION - 0.5
/*TODO - Unknown
/*LAST UPDATED - Sat 28 Jan 2006
****************/

struct Monster
{
string NAME; //Its name
bool EXIST; //This is true if the Monster exists
int HP; //Health
int ATT; //It's attack attribute
int DEF; //It's defense attribute
};

/***************
/*Room Struct
/***************
/*USE - Holds data to all rooms in the world
/*VERSION - 0.2
/*TODO - Unknown
/*LAST UPDATED - Sat 28 Jan 2006
****************/


struct Room
{
int ID; //This rooms ID number
string Desc; //This rooms description
string story; //This is a string holding a optional "story" behind the room.
int RelatedRoomID1; //The ID of the related room1(if any)
int RelatedRoomID2; //The ID of the related room2(if any)
Monster RoomMonster[10]; //Makes room for 11 monsters
};

/*******************
/*CRoom Database
/*******************
/*STATUS - UNDONE
/*USE - A database that contains all the rooms in the world
/*VERSION - 0.01
/*BUGS - N/A
/*TODO - Unknown
/*******************
/*LAST UPDATED - Sat 28 Jan 2006
********************/



class CRoomDatabase
{
private:
int m_iTotalRooms; //Int to hold all the rooms
Rooms m_rTheRooms [MAX_ROOMS] //And array of all the rooms
public:
CRoomDatabase(); //Default constructor
}RDatabase; //only one instance of this class: RDatabase

/******************
/*CRoomDatabase Function Definitions
/*BUGS - N/A
/*TODO - N/A
/******************
/*LAST UPDATED - 29 Jan 2006
*******************/



CRoomDatabase::CRoomDatabase() //Definition of constructor
{

this->m_iTotalRooms = 0: //When the instance of CRoomDatabase is created, set that instances m_iTotalRooms to 0.
}






/*******************
/*CMonsterDatabase
/*STATUS - UNDONE
/*******************
/*WHY - Lack of progression on other parts(Rooms)
/*VERSION - 0.0
/*******************
/*TODO - ...
/*LAST UPDATED - Sat 28 Jan 2006
********************/


class CMonsterDatabase
{
private:
int m_iTotalMonsters; //An INT to store the number of monsters in th world
public:
CMonsterDatabase(); //Default constructor
}MDatabase;

/******************
/*Definitions of CMonsterDatabase
/******************
/*BUGS - N/A
/*VERSION - 0.0
/******************
/*LAST UPDATED - 29 Jan 2006
*******************/



CMonsterDatabase::CMonsterDatabase() //UNDONE
{
//LOOP TROUGH ALL THE ROOMS AND GET THE TOTAL NUMBER OF MONSTERS THERE
for(int i= 0; i {
for(int x = 0; x<10; x++)
{
if(RDatabase.m_rTheRooms[i.RoomMonster[x.EXIST] ] == true) //If one of the 10 room monsters "x" in that room "i" exists.
{
this->m_iTotalMonsters++; //Increment this value by one each time
}
}
}


}

/*******************
/* End Of Monster Database Code
********************/



class CRoom
{
public:
void AddRoom(string, int, int, int); //String is an adress to a txt file containing a description of the new room, ints are used to know wich room is connected to the new room, the last int represents the ID of the room
void AddRoom(string, int, int); // -||- This is used for adding just one realted room to the new room instead of two
void AddMonster(CRoom, Monster); //adds a monster to a room
void GetRoomInfo(int); //int is the rooms ID
}RoomManager;

void CRoom::AddRoom(string a, int x, int y, int ID)
{
string Filein; // This holds the Line coming from IO.LoadTextFile(a, 1);
string Filein = IO.LoadTextFile(a, 1); //Load a text file specified by a, and read 1 line of that text file
RDatabase.m_rTheRooms[m_iTotalRooms] = ID; //Set the number of total rooms to ID.
RDatabase.m_rTheRooms[ID.Desc] = Filein; //The description gotten from Filein is now stored in the room "ID" Description value.
RDatabase.m_rTheRooms[ID.RelatedRoomID1] = x; //This is an INT to the first rooms ID this new room is connected to
RDatabase.m_rTheRooms[ID.RelatedRoomID2] = y; //This is an INT to the second rooms ID this new one is connected to
m_iTotalRooms++; //Icrement the m_iTotalRooms value so the next AddRoom won't override this one
}

void GetRoomInfo(int ID);
{
int RelID1; //This is to hold the First connected rooms ID.
int RelID2: //This is to hold the second connected rooms ID.
cout << RDatabase.m_rTheRooms[ID.Desc]; //This line prints the specified room IDs Description.
cout <<"This room leads to: "; //Prints the text "This room leads to: " Without newline
RelID1 = RDatabase.m_rTheRooms[ID.RelatedRoomID1]; //Gets the Room ID of the first connected room and stores it in RelID1
cout << RDatabase.m_rTheRooms[RelID1.Desc]; //Prints the description of the connected room1
cout << "and "; //Prints "and"
RelID2 = RDatabase.m_rTheRooms[ID.RelatedRoomID2]; //Stores the second connected room into RelID2
cout << RDatabase.m_rTheRooms[RelID2.Desc]<//Prints the second connected rooms description on the screen
}

/*******************
/*PLAYER CLASS
/*******************
/*USE - Class containing all the attributes of a player
/*VERSION - 0.0
/*BUGS - N/A
/*******************
/*TODO - N/A
/*LAST UPDATED - 29 Jan 2006
********************/


class CPlayer
{
private:
string m_sName; //A string representing the name of the player
int m_iCurrentRoomID; //An INT representing the ID to the room the player currently is in
public:
void Input(); //This checks and handles player input
void MoveToRoom(int); //This moves the player to the room of ID int. If that room is connected to the current room
}Player;

//DEFINITIONS

void CPlayer::Input() //UNDONE
{
}

void MoveToRoom(int a)
{
if(RDatabase.m_rTheRooms[a.RelatedRoomID1]||RDatabase.m_rTheRooms[a.RelatedRoomID2] != this->m_iCurrentRoomID) //If the room to move to specified by A is not connected to the room the player is currently in
{
cout << "Where's that?"< }
else
{
this->m_iCurrentRoomID = RDatabase.m_rTheRooms[a]; //Set the room ID the player currently is in to the new room spcified by int "a"
RoomManager.GetRoomInfo(a); //Get the info of the new room
}
}


/****************************************
/*MAIN LOOP
/****************************************
/*BUGS - N/A
/*TODO - N/A
/*LAST UPDATED - 29 Jan 2006
*****************************************/


// PROGRAM START

//Set global bool END to false
end = false;

int main()
{
//MAIN LOOP
while(!end) //end is a global bool variable.
{
//CODE GOES HERE
}
}

// PROGRAM END





defines.h

#include
#include
#include
#include

/******************
/*TODO - Make this IO class compitable.
/*BUGS - N/A
/*TODO - ALOT, this is totaly unfinished
/*VERSION 1.0
/******************
/*LAST UPDATED - 29 Jan 2006
*******************/



using namespace std;

#define MAX_LINES 1 //The max lines in a file

class CDefines
{
private:
public:
string Filelines[MAX_LINES]; //An array of strings to hold all the readed lines, the number is sepcified by the #define above
}Defines;





IO.h

#include
#include
#include
#include

#include //Includes define.cpp

using namespace std;


class CInputOutput //Input/output class
{
public:
string LoadTextFile(string, int); //string is the file path while INT is the number of lines to read from file
void LoadDefineFile(int); //The int sepcifies how many lines to read, the path is "define.txt" and is non-changeable
}IO;

string CInputOutput::LoadTextFile(string a, int x)
{
string Line; //The string this function returns, and buffer for loading of lines from text files
istream file(a, ios::in);
if(file.is_open())
{
for(int i = 0; i {
getline(file, Line);
}
file.close();
}
else
{
cout << "Could not open file"< }
return Line;
}

void CInputOutput::LoadDefineFile(int a)
{
ifstream infile("defines.txt", ios::in);
if(infile.is_open())
{
for(int i = 0; i {
getline(infile,Defines.Filelines); //Put it in the class instance DEFINES buffer, Filelines(array).

}
infile.close();
}
else
{
cout << "Unable to open file" < }
}





Sorry, if this is just a redicolous way of getting someone to read through and point out mistakes [grin]


Cheers,

Sign in to follow this  


5 Comments


Recommended Comments

Why the hell are you including .cpp files? They're supposed to be linked alongside the main project. You might as well just make them headers if you're going to include them like that.

Share this comment


Link to comment
The cpp files #includes header files. Like

defines.cpp includes defines.h

So I thought: "Why don't just include the .cpp files?"

Whats so bad about it? [smile]

Share this comment


Link to comment
Source files usually contain implementation details. If you include a source file, you're including the implementation and potentially getting multiple copies of your data.

Keep at it. Text games can be lots of fun. [smile]

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement