Advertisement

Text RPG

Started by April 27, 2002 08:26 PM
36 comments, last by gamechampionx 22 years, 5 months ago
OK, I started creating a text RPG, and it''s OK, but I''m having problems. First, I don''t know how to specify a specific place to output text or getch, esp. when outputting the story. Also, when it displays race, it sometimes displays race and class on the same line, then class again where it''s supposed to go. Anyhoo, here''s the code:
  
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>

int Cls()
{
	system("cls");
	return 0;
}

struct Character
{
	int maxmana, maxhp, strength, defence, magic, agility;
	int mana, hp;
	int damage;
	int damageestimate[2];
	float battleinterval;
	char name[20];
	char race[6];
	char characterclass[14];
};	

Character player;
Character enemy;

char CharacterResults()
{
	char yn;
	Cls();
	cout << "Name: " << player.name;
	cout << "\nRace: " << player.race;
	cout << "\nClass: " << player.characterclass;
	cout << "\n\nStrength: " << player.strength;
	cout << "\nDefence: " << player.defence;
	cout << "\nMagic: " << player.magic;
	cout << "\nAgility: " << player.agility;
	cout << "\n\nMaximum Mana: " << player.maxmana;
	cout << "\nMaximum HP: " << player.maxhp;
	cout << "\n\nBattle Interval: " << player.battleinterval;
Start:
	cout << "\n\nWould you like to keep these stats and continue?(y/n)";
	cout << flush;
	yn = getch();
	if (yn != ''y'' && yn != ''Y'' && yn != ''n'' && yn != ''N'')
	{
	cout << "\n\nNot an appropriate answer!\n\n";
	goto Start;
	}
	return yn;
}

int CharacterMenu()
{
	char result;
	char choice;
	Start:
	Cls();
	cout << "What is your name?\n";
	cin.getline (player.name,21);
	Cls();
	cout << "Please choose a race for your character:\n\n";
	cout << "1.  Human\n";
	cout << "2.  Goblin\n";
	cout << "3.  Elf\n";
	cout << "4.  Faerie\n";
	cout << "5.  Dragon\n";
	cout << flush;
	choice = getch();
	switch(choice)
	{
	case ''1'':
		strcpy(player.race,"Human");
		player.strength = 30;
		player.defence = 30;
		player.magic = 10;
		player.agility = 15;
		break;
	case ''2'':
		strcpy(player.race,"Goblin");
		player.strength = 40;
		player.defence = 30;
		player.magic = 5;
		player.agility = 10;
		break;
	case ''3'':
		strcpy(player.race,"Elf");
		player.strength = 15;
		player.defence = 10;
		player.magic = 45;
		player.agility = 15;
		break;
	case ''4'':
		strcpy(player.race,"Faerie");
		player.strength = 5;
		player.defence = 20;
		player.magic = 25;
		player.agility = 35;
		break;
	case ''5'':
		strcpy(player.race,"Dragon");
		player.strength = 20;
		player.defence = 25;
		player.magic = 20;
		player.agility = 20;
		break;
	default:
		goto Start;
		break;
	}
	Start2:
	Cls();
	cout << "Please choose a class for your character:\n\n";
	cout << "1.  Blood Mage\n";
	cout << "2.  Thief\n";
	cout << "3.  Elemental Mage\n";
	cout << "4.  Ninja\n";
	cout << "5.  Gladiator\n";
	cout << "6.  Warlord\n";
	cout << flush;
	choice = getch();
	switch(choice)
	{
	case ''1'':
		strcpy(player.characterclass,"Blood Mage");
		player.strength += 20;
		player.defence += 20;
		player.magic += 20;
		player.agility += 20;
		break;
	case ''2'':
		strcpy(player.characterclass,"Thief");
		player.strength += 15;
		player.defence += 15;
		player.magic += 20;
		player.agility += 30;
		break;
	case ''3'':
		strcpy(player.characterclass,"Elemental Mage");
		player.strength += 10;
		player.defence += 15;
		player.magic += 35;
		player.agility += 20;
		break;
	case ''4'':
		strcpy(player.characterclass,"Ninja");
		player.strength += 30;
		player.defence += 10;
		player.magic += 15;
		player.agility += 25;
		break;
	case ''5'':
		strcpy(player.characterclass,"Gladiator");
		player.strength += 30;
		player.defence += 30;
		player.magic += 10;
		player.agility += 10;
		break;
	case ''6'':
		strcpy(player.characterclass,"Warlord");
		player.strength += 20;
		player.defence += 20;
		player.magic += 10;
		player.agility += 30;
		break;
	default:
		goto Start2;
		break;
	}
	player.maxmana = 2 * player.magic;
	player.mana = player.maxmana;
	player.maxhp = 2 * player.defence;
	player.hp = player.maxhp;
	player.battleinterval = 1000.0f / (float)player.agility;
	result = CharacterResults();
	if (result == ''n'' || result == ''N'')
	{
		Cls();
		cout << "You may now choose again, press any key...";
		cout << flush;
		getch();
		goto Start;
	}
	return 0;
}

int Story()
{
	cout << "Story:\n\n";
	cout << "Press any key to continue...\n" << flush;
	getch();
	Cls();
	cout << "The land of Relourin is in grave danger, young warior!...\n\n";
	cout << "Press any key to continue...\n" << flush;
	getch();
	Cls();
	cout << "A new evil has arisen!\n\n";
	cout << "Press any key to continue...\n" << flush;
	getch();
	Cls();
	cout << "Mournir, the King of the Dead, has arisen from his grave..\n\n";
	cout << "Press any key to continue...\n" << flush;
	getch();
	Cls();
	cout << "only to seek the destruction of the living!\n\n";
	cout << "Press any key to continue...\n" << flush;
	getch();
	Cls();
	cout << "Now go, brave young soul...\n\n";
	cout << "Press any key to continue...\n" << flush;
	getch();
	Cls();
	cout << "and rid this land of evil before it''s too late!\n\n";
	cout << "Press any key to continue...\n" << flush;
	getch();
	CharacterMenu();
	Cls();
	cout << "Press any key to exit..." << flush;
	getch();
	return 0;
}

int main()
{
	char choice;
	Start:
	Cls();
	cout << "RPG\n\n" << "What would you like to do?\n\n";
	cout << "1.  New Game\n" << "2.  Resume Game\n" << "3.  Exit\n\n";
	cout << flush;
	choice = getch();
	Cls();
	switch(choice)
	{
	case ''1'':
		Story();
		break;
	case ''2'':
		cout << "Not yet available\n\n\n";
		cout << "Press any key to reset...";
		cout << flush;
		getch();
		goto Start;
	case ''3'':
		cout << "Press any key to exit..." << flush;
		getch();
		return 0;
	default:
		goto Start;
	}
	return 0;
}

  
Check out Drunken Brawl at http://www.angelfire.com/games6/drunken_brawl!
when copying your strings, you may want them to end with the /0 character - this is the null character (if i used the right slash..). All strings should end with this.

That should make your class and race go on the right lines.

hope that helps!
All done with Cash:www.venini.co.uk/arthursdeparture/
Advertisement
Thanks. How do I locate a position, though?
Check out Drunken Brawl at http://www.angelfire.com/games6/drunken_brawl!
Just wondering, will you make the story less cliched? Because the point of a text-based RPG is to have a good story, especially if anything else in the game isn''t going to be very complex..
I hate signatures.
Hey there. I hope you''re getting along ok with your text game. I''m working on one myself actually. I sent you an email a lil'' while ago dealing with that. Write me back if you have any comments, questions etc.

best o'' luck
Ern
groovy,ern
To set the cursor position, you can use something like this:
COORD coord = {xPos, yPos};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
Advertisement
Thanks for the set_console_cursor_position help, it''s exactly what I''m looking for. Anyway, I''m going to change the story, I''m just happy to get the story menu working.

Anyway Baine, I don''t think I gout your e-mail, give me you address, or write to gamechampionx@hotmail.com.
Check out Drunken Brawl at http://www.angelfire.com/games6/drunken_brawl!
hmm strange about the email. ahh well. my address is Baine_X@hotmail.com if ya wanna get in touch

Ern
groovy,ern
Did some more work with \0 and the story. Here''s the code:


  #include <iostream.h>#include <conio.h>#include <stdlib.h>#include <string.h>int Cls(){	system("cls");	return 0;}struct Character{	int maxmana, maxhp, strength, defence, magic, agility;	int mana, hp;	int damage;	int damageestimate[2];	float battleinterval;	char name[20];	char race[6];	char characterclass[14];};	Character player;Character enemy;char CharacterResults(){	char yn;	Cls();	cout << "Name: " << player.name;	cout << "\nRace: " << player.race;	cout << "\nClass: " << player.characterclass;	cout << "\n\nStrength: " << player.strength;	cout << "\nDefence: " << player.defence;	cout << "\nMagic: " << player.magic;	cout << "\nAgility: " << player.agility;	cout << "\n\nMaximum Mana: " << player.maxmana;	cout << "\nMaximum HP: " << player.maxhp;	cout << "\n\nBattle Interval: " << player.battleinterval;Start:	cout << "\n\nWould you like to keep these stats and continue?(y/n)";	cout << flush;	yn = getch();	if (yn != ''y'' && yn != ''Y'' && yn != ''n'' && yn != ''N'')	{	cout << "\n\nNot an appropriate answer!\n\n";	goto Start;	}	return yn;}int CharacterMenu(){	char result;	char choice;	Start:	Cls();	cout << "What is your name?\n";	cin.getline (player.name,21);	Cls();	cout << "Please choose a race for your character:\n\n";	cout << "1.  Human\n";	cout << "2.  Goblin\n";	cout << "3.  Elf\n";	cout << "4.  Faerie\n";	cout << "5.  Dragon\n";	cout << flush;	choice = getch();	switch(choice)	{	case ''1'':		strcpy(player.race,"Human\0");		player.strength = 30;		player.defence = 30;		player.magic = 10;		player.agility = 15;		break;	case ''2'':		strcpy(player.race,"Goblin\0");		player.strength = 40;		player.defence = 30;		player.magic = 5;		player.agility = 10;		break;	case ''3'':		strcpy(player.race,"Elf\0");		player.strength = 15;		player.defence = 10;		player.magic = 45;		player.agility = 15;		break;	case ''4'':		strcpy(player.race,"Faerie\0");		player.strength = 5;		player.defence = 20;		player.magic = 25;		player.agility = 35;		break;	case ''5'':		strcpy(player.race,"Dragon\0");		player.strength = 20;		player.defence = 25;		player.magic = 20;		player.agility = 20;		break;	default:		goto Start;		break;	}	Start2:	Cls();	cout << "Please choose a class for your character:\n\n";	cout << "1.  Blood Mage\n";	cout << "2.  Thief\n";	cout << "3.  Elemental Mage\n";	cout << "4.  Ninja\n";	cout << "5.  Gladiator\n";	cout << "6.  Warlord\n";	cout << flush;	choice = getch();	switch(choice)	{	case ''1'':		strcpy(player.characterclass,"Blood Mage\0");		player.strength += 20;		player.defence += 20;		player.magic += 20;		player.agility += 20;		break;	case ''2'':		strcpy(player.characterclass,"Thief\0");		player.strength += 15;		player.defence += 15;		player.magic += 20;		player.agility += 30;		break;	case ''3'':		strcpy(player.characterclass,"Elemental Mage\0");		player.strength += 10;		player.defence += 15;		player.magic += 35;		player.agility += 20;		break;	case ''4'':		strcpy(player.characterclass,"Ninja\0");		player.strength += 30;		player.defence += 10;		player.magic += 15;		player.agility += 25;		break;	case ''5'':		strcpy(player.characterclass,"Gladiator\0");		player.strength += 30;		player.defence += 30;		player.magic += 10;		player.agility += 10;		break;	case ''6'':		strcpy(player.characterclass,"Warlord\0");		player.strength += 20;		player.defence += 20;		player.magic += 10;		player.agility += 30;		break;	default:		goto Start2;		break;	}	player.maxmana = 2 * player.magic;	player.mana = player.maxmana;	player.maxhp = 2 * player.defence;	player.hp = player.maxhp;	player.battleinterval = 1000.0f / (float)player.agility;	result = CharacterResults();	if (result == ''n'' || result == ''N'')	{		Cls();		cout << "You may now choose again, press any key...";		cout << flush;		getch();		goto Start;	}	return 0;}int Story(){	cout << "Story:\n\n"		<< "Welcome to the land of Relourin, young warrior.  You have been selected by the\n"		<< "King himself for this mission.\n\n"		<< "This land is in grave danger.  Something has emerged into the depths of the\n"		<< "Great Volcano.  Many strange things have been happening.  Strange unfriendly\n"		<< "creatures have been roaming the countryside, looking for a fight.  The local\n"		<< "villages have been sabotaged.  There are far too many of them for us to ward\n"		<< "off without you.  You are our only hope.\n\n"		<< "Leave with haste, and rid this land of evil before it''s too late.\n\n"		<< "Press any key to continue...";	cout << flush;	getch();	CharacterMenu();	Cls();	cout << "Press any key to exit..." << flush;	getch();	return 0;}int main(){	char choice;	Start:	Cls();	cout << "RPG\n\n" << "What would you like to do?\n\n";	cout << "1.  New Game\n" << "2.  Resume Game\n" << "3.  Exit\n";	cout << flush;	choice = getch();	Cls();	switch(choice)	{	case ''1'':		Story();		break;	case ''2'':		cout << "Not yet available\n\n\n";		cout << "Press any key to reset...";		cout << flush;		getch();		goto Start;	case ''3'':		cout << "Press any key to exit..." << flush;		getch();		return 0;	default:		goto Start;	}	return 0;}  


However, it still shows the race and class together where race should be, and class again where it should be. Why?
Check out Drunken Brawl at http://www.angelfire.com/games6/drunken_brawl!
goto?!?!?!?!?!?!?!?!?!?

This topic is closed to new replies.

Advertisement