Archived

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

Dko

Too all of you! (especialy those who helped me)

Recommended Posts

Well its been hard work but ive finnaly got a (very) simple text rpg battle. So ive decided to share Its probibly full of bad codeing mistakes ,is majorly flickery and what not but this was a learning experiance only. But ive attempted to fix it somewhat. So go ahead, compile and enjoy my crapy rpg battle. Ill be expanding it slowly so its not so crapy and all the while ill steal more ff3/6 formulae to use in it(Its not like im gona sell it or anything) :D
#include <iostream>
#include <stdlib.h>

using namespace std;


class Creature
{
public:
void setHp(int Hp);
void changeHp(int Hp);
void setAtk(int Atk);
void setDef(int Def);
void setSpd(float Spd);
void setATB(float ATB);
int CalculateATB();
int showHp();
int showMaxHp();
int showAtk();
int showDef();
float showSpd();
int showATB();

private:
	int itsHp;
	int MaxHp;
	int itsAtk;
	int itsDef;
	float itsSpd;
	float itsATB;
};

// Creature class functions

void Creature::setHp(int Hp)
{
	itsHp = Hp;
	MaxHp = itsHp;
}

void Creature::changeHp(int Hp)
{
	itsHp = Hp;
}

void Creature::setAtk(int Atk)
{
	itsAtk = Atk;
}

void Creature::setDef(int Def)
{
	itsDef = Def;
}

void Creature::setSpd(float Spd)
{
	itsSpd = Spd;
}

void Creature::setATB(float ATB)
{
	itsATB = ATB;
}

int Creature::CalculateATB()  
{
	
	this->setATB(this->itsATB + (96 * (this->showSpd() + 20)) / 16);  // My riped off ff3/6 formule :P

	
	if (this->itsATB >= 65535)
		return 1;
	return 0;
}
	

int Creature::showHp()
{
	return itsHp ;
}

int Creature::showMaxHp()
{
	return MaxHp;
}

int Creature::showAtk()
{
	return itsAtk;
}

int Creature::showDef()
{
	return itsDef;
}

float Creature::showSpd()
{
	return itsSpd;
}

int Creature::showATB()
{
	float NumOfBars = 10;
	float interval = 65535 / NumOfBars;
	float bars = itsATB / interval;

	cout << "(";
	
	for(int i = 0; i < bars; i++)
		cout << "|";
		
	for(float j = bars; j <= NumOfBars; j++)
		cout << "-";
	
	cout << ")";
	
	return 0;

	}

// Functions

void clrscr( ) { system("cls"); }  // Clears the screen


bool Battle(Creature Char, Creature Monster)  // Battle function, takes the character and the monster to fight

{
	
	int Option = 0;
	int defMode = 0;
	int IsATBFull1 = 0;
	int IsATBFull2 = 0;
	while(true)
	{
		
				
		cout << "NAME: Mainchar" << endl;
		cout << "HP: " << Char.showHp() << "/" << Char.showMaxHp() << endl;
		IsATBFull1 = Char.CalculateATB();
		Char.showATB();
		IsATBFull2 = Monster.CalculateATB();
		
		cout << "__________________________________________________________" << endl;
		cout << "VS!!!!!!!!!!" << endl;
		cout << "__________________________________________________________" << endl;
		cout << "NAME: Monster" << endl;
		cout << "HP: " << Monster.showHp() << "/" << Monster.showMaxHp() << endl;
		cout << "----------------------------------------------------------" << endl;
		cout << endl;
		
		if (IsATBFull1 == 1)
		{
			cout << "Please pick a command"<< endl;
			cout << "1 = Attack(default)" << endl;
			cout << "2 = Defend" << endl;
			cout << "3 = Run" << endl;
						
			cin >> Option;

			switch (Option)
			{
			case 1:
				{
					int damage = Char.showAtk() - Monster.showDef();
					if (damage <= 0)
					{
						damage = 1;
					}
					cout << "Main character attacks!!" << endl;
					cout << "For..." << damage << endl;
					system("PAUSE");
					Monster.changeHp(Monster.showHp() - damage);
					if (Monster.showHp() <= 0)
					{
						Monster.changeHp(0);
						cout << "Monster has died!" << endl;
						cout << "YOU WIN!!!!" << endl;

						IsATBFull1 = 0;
						
						return 0;
					}
					Char.setATB(0);
					break;
				}
			
			case 2:
				{
					IsATBFull1 = 0;
					defMode = 1;
					Char.setATB(0);
					break;
				}

			case 3:
				{
					IsATBFull1 = 0;
					cout << "You run... You coward!";
					return 0;
					break;
				}
				
			default:
				{
					int damage = Char.showATB() - Monster.showDef();
					if (damage <= 0)
						damage = 1;
					cout << "Main character attacks!!" << endl;
					cout << "For..." << damage << endl;
					system("PAUSE");
					Monster.changeHp(Monster.showHp() - damage);
					if (Monster.showHp() <= 0)
					{
						Monster.changeHp(0);
						cout << "Monster has died!" << endl;
						cout << "YOU WIN!!!!" << endl;
						IsATBFull1 = 0;
						

						return 0;
					}
					break;
					Char.setATB(0);
				}
				
			}
					

		}

		if (IsATBFull2 == 1)
		{
			int damage = 0;
			if(defMode == 1)
			{
				damage = Monster.showAtk() - Char.showDef();
				damage = damage / 2;
				
			}
			else
			{
				damage = Monster.showAtk() - Char.showDef();
			}
			if (damage <= 0)
				damage = 1;

			cout << "The Monster did "<< damage << " to you!" << endl;
			system("PAUSE");

			defMode = 0;

			Char.changeHp(Char.showHp() - damage);

			if (Char.showHp() <= 0)
			{
				Char.changeHp(0);
				cout << "You have died!";
				 return 0;
			}

			Monster.setATB(0);
		}

		clrscr();
                                                                                                                           
		
	}

	return true;

}

int main()
{
	// Setting up the contestants

	Creature Mainchar;
	Mainchar.setHp(55);
	Mainchar.setAtk(90);
	Mainchar.setDef(73);
	Mainchar.setSpd(90);
	Mainchar.setATB(0);

	Creature Monster;
	Monster.setHp(40);
	Monster.setAtk(80);
	Monster.setDef(65);
	Monster.setSpd(63);
	Monster.setATB(0);

	// Start battle

	Battle(Mainchar, Monster);

	return 0;
}
EDIT: almost forgot to add in the code. [edited by - Dko on January 24, 2004 2:41:53 AM]

Share this post


Link to post
Share on other sites