RPG code

Started by
47 comments, last by gamechampionx 21 years, 7 months ago
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?
Check out Drunken Brawl at http://www.angelfire.com/games6/drunken_brawl!
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
DracosX:Master of the General Protection Fault
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.
- Advice, eh? Well, besides working on your swing...you know, besides that...I'd have to think.
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]
- Advice, eh? Well, besides working on your swing...you know, besides that...I'd have to think.
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 =)
---GUI Programming Division Manager at Wildfire Gamesworking on the 0 A.D. project
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.
I never knew bool existed. Is it supported by MS VB6?

Also, why am I getting that end of file garbage? I can''t figure it out.
Check out Drunken Brawl at http://www.angelfire.com/games6/drunken_brawl!
In VB the type is "Boolean"
People, 2 questions:

1: Where do I have an extra "{" or "}"?

2: Is bool supported by MS VC++ 6?

Please help!
Check out Drunken Brawl at http://www.angelfire.com/games6/drunken_brawl!
In your CharacterMenu() function the first

do
{

doesn''t have anything to line up with

bool is supported by msvc.

This topic is closed to new replies.

Advertisement