Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

gamechampionx

RPG code

This topic is 5918 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m working on my RPG, and the code looks fine, but it won''t run. Here''s the code:
  
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>

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

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

Character player;
Character enemy;

char CharacterResults()
{
	char yn;
	bool done = 0;
	do
	{
		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;
		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 a valid choice.\n\n";
			cout << "Press any key to continue...";
			cout << flush;
			getch();
		}
		else
			done = 1;
	} while (done = 0);
	return yn;
}

int CharacterMenu()
{
	bool done;
	bool done2;
	char result;
	char choice;
	do
	{
		done = 1;
		Cls();
		cout << "What is your name?\n";
		cin.getline (player.name,21);
		do
		{
			done2 = 1;
			Cls();
			cout << "Please choose a race for your character:\n\n";
			cout << "1.  Human: A strong physical race, in offence and defence.\n\n";
			cout << "2.  Goblin: Another physical race, with a powerful attack, but little grasp of"
				<< "\n    magic.\n\n";
			cout << "3.  Elf: A less physical race, with its roots in magic.\n\n";
			cout << "4.  Faerie: A very agile race.\n\n";
			cout << "5.  Dragon: The most well-rounded of all races.\n\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:
				cout << "Not a valid choice.\n\n";
				cout << "Press any key to continue...";
				cout << flush;
				getch();
				done = 0;
			break;
			}
		Cls();
		cout << "Please choose a class for your character:\n\n";
		cout << "1.  Blood Mage: A sorceror class with powerful but sometimes suicidal spells.\n\n";
		cout << "2.  Thief: A nimble class that attacks with agility, and steals various things.\n\n";
		cout << "3.  Elemental Mage: A sorceror class that can control the elements.\n\n";
		cout << "4.  Ninja: A strong and agile physical class that uses martial arts spells.\n\n";
		cout << "5.  Gladiator: Another strong physical class that uses close-range weapons.\n\n";
		cout << "6.  Warlord: An agile class that uses long-range weapons.\n\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:
			cout << "Not a valid choice.\n\n";
			cout << "Press any key to continue...";
			cout << flush;
			getch();
			done2 = 0;
			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();
			done2 = 0;
		}
	} while (done2 = 0);
	return 0;
}

int Story()
{
	Cls();
	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\n";
	cout << flush;
	choice = getch();
	switch(choice)
	{
	case ''1'':
		Story();
		break;
	case ''2'':
		Cls();
		cout << "Not yet available\n\n\n";
		cout << "Press any key to reset...";
		cout << flush;
		getch();
		goto Start;
	case ''3'':
		Cls();
		cout << "Press any key to exit..." << flush;
		getch();
		return 0;
	default:
		cout << "Not a valid choice.\n\n";
		cout << "Press any key to continue...";
		cout << flush;
		getch();
		goto Start;
	}
	return 0;
}

  
Here are the errors:
  
--------------------Configuration: RPG - Win32 Debug--------------------
Compiling...
RPG.cpp
C:\Windows\Desktop\Web Site\XtremeSoftware RPG\Rpg\RPG.cpp(211) : error C2062: type ''int'' unexpected (Line of Int Story)
C:\Windows\Desktop\Web Site\XtremeSoftware RPG\Rpg\RPG.cpp(212) : error C2143: syntax error : missing '';'' before ''{'' ({ after Int Story)
C:\Windows\Desktop\Web Site\XtremeSoftware RPG\Rpg\RPG.cpp(234) : error C2601: ''main'' : local function definitions are illegal ({ after Int Main)
C:\Windows\Desktop\Web Site\XtremeSoftware RPG\Rpg\RPG.cpp(269) : fatal error C1004: unexpected end of file found
Error executing cl.exe. (End of File)

RPG.exe - 4 error(s), 0 warning(s)
  
What''s going on?

Share this post


Link to post
Share on other sites
Advertisement
You have an extra do { that doesn''t "do" anything
look closely at your code...
You''ll see it in function CharacterMenu().





DracosX:

Master of the General Protection Fault

Share this post


Link to post
Share on other sites
I''ve noticed not exactly an error; but, with your Character struct I''d ''typedef'' it.

so...

  
typedef struct character_s
{
int maxmana, maxhp, strength, defence, magic, agility;
int mana, hp;
int experience;
int damage;
int damageestimate[2];
float battleinterval;
char name[20];
char race[7];
char characterclass[15];
} character_t;

typedef struct monster_s
{
// obviously this is a cut and paste job, but you get the idea

int maxmana, maxhp, strength, defence, magic, agility;
int mana, hp;
int experience;
int damage;
int damageestimate[2];
float battleinterval;
char name[20];
char race[7];
char characterclass[15];
} monster_t;

character_t PC1, PC2; //...

monster_t NPC1, NPC2; //...




This allows you to place checks on yourself to perhaps keeps yourself from attacking other good PCs or NPCs that you other wise wouldn''t want to attack/interact with. This would just enforce typechecking. That''s all.

Share this post


Link to post
Share on other sites
on your line with:

      
CharacterResults()
...
...
...
done = 1;
} while (done = 0);



//you've assigned '0' to done. Thusly causing the while statement to end prematurely. I think you wanted 'done == 0'.


//I've used this method before. try this:


// excuse my C++. it's been a while.

bool done = false;
char test;

do
{
cout << "again?";
cin >> test;
if( test == "n" )
done = true;
}while(!done);


[edited by - Like2Byte on June 24, 2002 10:47:09 AM]

[edited by - Like2Byte on June 24, 2002 10:47:58 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by Like2Byte
I''ve noticed not exactly an error; but, with your Character struct I''d ''typedef'' it.


I disagree completely, I like using the same foundation for pc''s and npc''s. Creating a universal processing of the character is nice (fight between pc/pc, pc/npc, npc/npc - all interactions will be dealt with universally. Not to mention when you have 10 different kinds of these!).
Although I would suggest derived classes in the future, but don''t think about that now...

gamechapionx, if you know want to be able to identify different kinds of characters (like Like2Byte has stated can be good, and he''s right)... Just throw in a TYPE enum or something:
enum CHARTYPE = {PS,NPC,MONSTER,YOMAMA}; 
and so on...

I''m assuming here that your pc''s and npc''s has got the same value (due to your current layout)...

gamechampionx, ignore this post if you found it useless or to over the top. I just wanted you to know that I think your layout is fine as it is.

btw it''s funny, all these console rpg''s that you see (including how mine were) is just create an advanced character code with 10 different classes... hehe =)

Share this post


Link to post
Share on other sites
Usually when you get an unexpected end of file you are missing a closing bracket somewhere. Like DracosX pointed out it is the second do in the CharacterMenu function that has an opening bracket but no closing bracket and while expression.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
In VB the type is "Boolean"

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!