Click here to Skip to main content
15,887,135 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: draw a rectangle in dialog based visual C++ 6.0 Pin
Eka Candra23-Sep-09 22:49
Eka Candra23-Sep-09 22:49 
AnswerRe: draw a rectangle in dialog based visual C++ 6.0 Pin
CPallini23-Sep-09 21:24
mveCPallini23-Sep-09 21:24 
GeneralRe: draw a rectangle in dialog based visual C++ 6.0 Pin
Eka Candra23-Sep-09 22:38
Eka Candra23-Sep-09 22:38 
GeneralRe: draw a rectangle in dialog based visual C++ 6.0 Pin
KarstenK23-Sep-09 22:51
mveKarstenK23-Sep-09 22:51 
GeneralRe: draw a rectangle in dialog based visual C++ 6.0 Pin
CPallini23-Sep-09 22:54
mveCPallini23-Sep-09 22:54 
AnswerRe: draw a rectangle in dialog based visual C++ 6.0 Pin
Eka Candra23-Sep-09 23:04
Eka Candra23-Sep-09 23:04 
GeneralRe: draw a rectangle in dialog based visual C++ 6.0 Pin
Richard MacCutchan24-Sep-09 1:13
mveRichard MacCutchan24-Sep-09 1:13 
QuestionMY simple txt Based Rpg Pin
akosidandan23-Sep-09 20:15
akosidandan23-Sep-09 20:15 
Hello all
I would like to ask how to make a simple graphics for this txt based rpg I create . I was planning to make some via dark gdk . So my question would be if anyone would like to tell some basic sprite in dark gdk

below here is my game

#include<iostream>
#include<string>
#include<ctime>
#include<cstdlib>

using namespace std;

// player class ///////////////////////
class player {
	
	int getDamage( );
	string getName( );
	string getJob( );

public:

	//player info
	string p_name;
	string p_job;

	//player items;
	int potion;
	int manaPotion;
	int powerPotion;
	
	//player status
	int p_lvl;
	int p_damage;
	int p_magicDamage;
	int p_powerDamage;
	int p_life;
	int p_mana;
	int p_power;
	int p_xp;
	int p_gold;
	int p_maxXp;
	int p_maxLife;
	int p_maxMana;
	int p_maxPower;

	//constructor of the class
	player ( );


};

//player contructor definition
player :: player( ){
	p_maxLife = 30;
	p_lvl = 1;
	p_maxXp = 2;
	p_xp = 0;
	p_gold = 10;
	p_name = getName ( );
	p_job = getJob ( );
	p_life = p_maxLife;
	p_damage = getDamage ( );

	if ( p_job == "Warrior" ){
		p_maxMana = 5;
		p_maxPower = 10;
		p_magicDamage = 5;
		p_powerDamage = 10;
		p_mana = p_maxMana;
		p_power = p_maxPower;
	}else if ( p_job == "Assasin" ){
		p_maxMana = 7;
		p_maxPower = 7;
		p_magicDamage = 7;
		p_powerDamage = 7;
		p_mana = p_maxMana;
		p_power = p_maxPower;
	}else{
		p_maxMana = 10;
		p_maxPower = 5;
		p_magicDamage = 10;
		p_powerDamage = 5;
		p_mana = p_maxMana;
		p_power = p_maxPower;
	}
}

//get the player name
string player::getName( ) {
	system ( "cls" );
	cout<<"\tJourney Txt Fighting Game\n\n"
		<<"What is your name : ";
	string name;
	cin>>name;
	system ( "pause" );
	return name;
}
//get the player choosen job
string player::getJob( ) {
	int choice;
	do{
		system ( "cls" );
		cout<<"\tJourney Txt Fighting Game\n\n"
			<<"What job do you want :\n"
			<<"[ 1 ] - Warrior\n"
			<<"[ 2 ] - Assasin\n"
			<<"[ 3 ] - Soolsa\n"
			<<"Choice : ";
		cin>>choice;
	} while ( choice < 1 || choice > 3 );
	
	system ( "pause" );

	if ( choice == 1 ){
		return "Warrior";
	}else if ( choice == 2 ){
		return "Assasin";
	}else{
		return "Soolsa";
	}
}

//get the playerDamage
int player::getDamage( ) {
	srand ( time ( 0 ) );
	int damage = rand ( ) % 5 + 1; //get a rando number from 1 - 5
	return damage;
}

// enemy class //////////////////////////////////////
class enemy {
	
	int getDamage ( );
public :
	//constuctor of the class
	enemy ( );
	//enemy status
	int e_damage;
	int e_life;
	int e_maxLife;
};

//enemy class constructor definition
enemy ::enemy( ){
	e_maxLife = 20;
	e_life = e_maxLife;
	e_damage = getDamage ( );
}

//get the enemy Damage
int enemy::getDamage( ) {
	int damage;
	if ( e_life <= 5 ) {
		 damage = 10;
	}else {
	srand ( time ( 0 ) );
	     damage = rand ( ) % 5 + 1;// get a random number from 1 - 5
	}
	return damage;
}



//create a public object for the enemy and the player
player hero;
enemy villain;


//functions /////////////////////////////////
void menu ( );
string title ( );
void fight ( );
char switchTurn ( char turn );
int playerMove ( int &heroLife , int &heroDamage , int &enemyLife );
void run ( int &heroLife , int &enemyMaxLife );
int useItems ( int &heroLife , int &potion , int &manaPotion, int &powerPotion , int &mana , int &power );
int attack ( int &heroLife , int &mana , int &power , int &enemyLife );
int enemyMove ( int &heroLife , int enemyDamage );
void displayStatus (int &xp , int &gold , int &maxXp );
void displayHp( );
void shop ( int &gold , int &potion , int &manaPotion , int &powerPotion);
void check ( int &xp , int &maxXp , int &life , int &maxLife , int &mana , int &maxMana , int &power , int &maxPower );

//main funtion of the program///////////////////////////////////
int main ( ) {

	//main program flow menu
	menu ( );
	
	cin.ignore ( cin.rdbuf ( ) ->in_avail ( ) + 1 );
	return 0;
}

//return  the title of the game
inline string title ( ){
	return "\tJourney Txt Fighting Game\n\n";
}

//menu
void menu ( ){
	int choice;
	do {
		system ( "cls" );
		cout<<title ( )
			<<"What do you want to do ? \n"
			<<"[ 1 ] - fight an enemy\n"
			<<"[ 2 ] - goto a shop\n"
			<<"[ 3 ] - display character status\n"
			<<"[ 4 ] - exit the game\n"
			<<"Choice : ";
		cin>>choice;
	} while ( choice < 1 || choice > 4 );

	switch ( choice ){

		case 1 :
				cout<<"Your are about to fight now an enemy \n";
				system ( "pause" );
				fight ( );
				break;
		case 2 :
				cout<<"You are about to go in to a shop now\n";
				system ( "pause" );
				shop ( hero.p_gold , hero.potion , hero.manaPotion , hero.powerPotion  );
				break;
		case 3 :
				cout<<"Character info now loading.....\n";
				system ( "pause" );
				displayStatus ( hero.p_xp , hero.p_gold , hero.p_maxXp );
				break;
		case 4: 
				cout<<"Thanks for playing .......\n";
				break;
	}
}

//fight funtion
void fight ( ){
	char playerTurn = 'x';
	char enemyTurn = 'o';
	char turn = playerTurn;
	int life;
	int faint = 0;
	do {
		if ( turn == playerTurn ){
			life = playerMove ( hero.p_life , hero.p_damage , villain.e_life  );
			//change the turn 
			turn = switchTurn ( turn );
		}else {
			life = enemyMove ( hero.p_life , villain.e_damage  );
			//change the turn 
			turn = switchTurn ( turn );
		}
	
	}while ( life > faint  );
	
	system ( "cls" );
	cout<<title ( );
	
		if ( hero.p_life <= 0 ){
			cout<<"GAME OVER YOU HAVE BEEN DEFEATED.....\n"
				<<"To play again please restart the game....\n";
			system ( "pause" );
		}else{

			cout<<"CONGRATULATION YOU DEFEAT THE ENEMY......\n"
				<<"you have loot 1 gold .\n";
			check ( hero.p_xp , hero.p_maxXp , hero.p_life , hero.p_maxLife , hero.p_mana , hero.p_maxMana , hero.p_power , hero.p_maxPower );
			villain.e_life = villain.e_maxLife ;
			hero.p_gold = hero.p_gold + 1;
			system ( "pause" );
			//go back to menu again
			menu ( );
		}
	

}

//switch  the turn
char switchTurn ( char turn ) {
	if ( turn == 'x')
		return 'o';
	else
		return 'x';
}

int playerMove ( int &heroLife , int &heroDamage , int &enemyLife ) {
	int move;
	int life;
	do{
		system ( "cls" );
		displayHp ( );
		cout<<"What is your move ?\n"
			<<"[ 1 ] - attack the enemy\n"
			<<"[ 2 ] - use items\n"
			<<"[ 3 ] - run \n"
			<<"Choice : ";
		cin>>move;
	} while ( move < 1 || move > 3 );

	switch ( move ) {
		
	case 1 : 
			life = attack ( hero.p_life , hero.p_mana , hero.p_power , villain.e_life  );
			return life;
			break;
	case 2 :
			life = useItems ( hero.p_life , hero.potion , hero.manaPotion , hero.powerPotion , hero.p_mana , hero.p_power );
			return life;
			break;
	case 3 :
			run ( hero.p_life , villain.e_maxLife );
			return life;
			break;
	}

	

}

void run ( int &heroLife , int &enemyMaxLife) {
	displayHp ( );
	cout<<"Escaped safely ....\n";
	hero.p_life = heroLife;
	villain.e_life = enemyMaxLife;
	//go back to main menu
	menu ( );
}

int useItems ( int &heroLife , int &potion , int &manaPotion , int & powerPotion , int &mana , int &power ){
	int choice;
	do{
		system ( "cls" );
		cout<<title ( )
			<<"Inventory : \n"
			<<"[ 1 ] - potion "<<potion<<" pcs\n"
			<<"[ 2 ] - mana potion "<<manaPotion<<" pcs\n"
			<<"[ 3 ] - power potion "<<powerPotion<<" pcs\n"
			<<"What do you want to use : ";
		cin>>choice;
	} while ( choice < 1 || choice > 3 );

	switch ( choice ) {
		case 1 :
			if ( potion <= 0 ){
				cout<<"Sorry out of stock\n";
				system ( "pause" );
				return heroLife;
			}else{
				cout<<"You have use a potion\n";
				system ( "pause" );
				heroLife = heroLife + 10;
				potion--;
				if ( heroLife > hero.p_maxLife  ){
						heroLife = hero.p_maxLife ;
						return heroLife;
				}else{
					return heroLife;
				}
			}
			break;

		case 2:
			if ( manaPotion <= 0 ){
				cout<<"Sorry out of stock\n";
				system ( "pause" );
				return heroLife;
			}else{
				cout<<"You have use a mana potion\n";
				system ( "pause" );
				mana = mana + 10;
				manaPotion--;
				if (mana >hero.p_maxMana ){
						mana = hero.p_maxMana ;
						return heroLife;
				}else{
					return heroLife;
				}
			}
			break;
			
		case 3:
			if ( powerPotion <= 0 ){
				cout<<"Sorry out of stock\n";
				system ( "pause" );
				return heroLife;
			}else{
				cout<<"You have use a power potion\n";
				system ( "pause" );
				power = power + 10;
				powerPotion--;
				if (power > hero.p_maxPower  ){
						power = hero.p_maxPower  ;
						return heroLife;
				}else{
					return heroLife;
				}
			}
			break;
	}
}




int attack ( int & heroLife , int &mana , int &power , int &enemyLife ){
	int choice;
	do{
		system ( "cls" );
		cout<<title ( )
			<<"what do you want to use ?\n"
			<<"[ 1 ] - normal attack\n"
			<<"[ 2 ] - magic attack\n"
			<<"[ 3 ] - power attack\n"
			<<"choice : ";
		cin>>choice;
	} while ( choice < 1 || choice > 3 );

	switch ( choice ) {
		case 1 :
			cout<<"You have inflicted a normal damage of "<<hero.p_damage <<" to your enemy\n";
			system ( "pause" );
			enemyLife = enemyLife - hero.p_damage ;
			return enemyLife;
			break;
		case 2 :
			if ( mana <= 0 ){
				cout<<"Sorry out of mana\n";
				system ( "pause" );
				return enemyLife;
			}else {
				cout<<"You have inflicted a magic damage of "<<hero.p_magicDamage  <<" to your enemy\n";
				system ( "pause" );
				mana = mana - 1;
				enemyLife = enemyLife - hero.p_magicDamage ;
				return enemyLife;
			}
			break;
		case 3:
			if ( power <= 0 ){
				cout<<"Sorry out of power\n";
				system ( "pause" );
				return enemyLife;
			}else {
				cout<<"You have inflicted a power damage of "<<hero.p_powerDamage  <<" to your enemy\n";
				system ( "pause" );
				enemyLife = enemyLife - hero.p_powerDamage ;
				power = power - 1;
				return enemyLife;
			}
			break;
	}
	return enemyLife;

}


int enemyMove ( int &heroLife , int enemyDamage ){

	system ( "cls" );
	displayHp ( );
	cout<<"The enemy inflicted damage of "<<enemyDamage<<" to your life.\n";
	heroLife = heroLife - enemyDamage;
	system ( "pause" );
	return heroLife;

}

void displayStatus ( int &xp , int &gold , int & maxXp ){
	system ( "cls" );
	cout<<title ( )
		<<"Player Status \n"
		<<"Player Name : "<<hero.p_name <<endl
		<<"Player Job : "<<hero.p_job <<endl
		<<"Player lvl : "<<hero.p_lvl <<endl
		<<"HP : "<<hero.p_life <<endl
		<<"MANA : "<<hero.p_mana <<endl
		<<"POWER : "<<hero.p_power <<endl
		<<"\ncurrent Gold : "<<gold <<endl
		<<"Exp : "<<xp <<endl
		<<"Exp to lvl up : "<<maxXp <<endl;
	system ( "pause" );
	//go back to menu
	menu ( );
}

void displayHp ( ) {
	system ( "cls" );
	cout<<title ( )
		<<"Player \n"
		<<"HP : "<<hero.p_life <<endl
		<<"MANA : "<<hero.p_mana <<endl
		<<"POWER : "<<hero.p_power <<endl<<endl
		<<"Enemy \n"
		<<"HP : "<<villain.e_life <<endl<<endl<<endl;
}



void shop ( int &gold , int &potion , int &manaPotion , int &powerPotion ){
	system ( "cls" );
	int choice;
	do {
	cout<<title ( )
		<<"Current gold : "<<gold<<endl
		<<"what do you want to buy ?\n"
		<<"[ 1 ] - <potion> restores 10 hp  cost 5 gold\n"
		<<"[ 2 ] - <mana potion> restores 2 mana cost 5 gold \n"
		<<"[ 3 ] - <power potion> restores 2 power cost 5 gold\n"
		<<"choice : ";
	cin>>choice;
	} while ( choice < 1 || choice > 3 );

		switch ( choice ) {
			case 1 :
				if ( gold > 0 ){
					cout<<"You have buy a potion.\n"
						<<"Thanks for buying.\n";
					system ( "pause" );
					potion++;
					gold = gold - 5;
				}else{
					cout<<"Insufficient gold.\n";
					system ( "pause" );
				}
				break;
			case 2 :
				if ( gold > 0 ){
					cout<<"You have buy a mana potion.\n"
						<<"Thanks for buying.\n";
					system ( "pause" );
					gold = gold - 5;
					manaPotion++;
				}else{
					cout<<"Insufficient gold.\n";
					system ( "pause" );
				}
				break;
			case 3:
				if ( gold > 0 ){
					cout<<"You have buy a power potion.\n"
						<<"Thanks for buying.\n";
					system ( "pause" );
					gold = gold - 5;
					powerPotion++;
				}else{
					cout<<"Insufficient gold.\n";
					system ( "pause" );
				}
				break;

		}

		//go back to menu
		menu ( );
}

void check ( int &xp , int &maxXp , int &life , int &maxLife , int &mana , int &maxMana , int &power , int &maxPower ){
	
	if ( xp >= maxXp ){
		system ( "cls" );
		cout<<"CONGRATULATION YOU HAVE LVL UP .....\n";
		life = life + 1;
		maxLife = maxLife + 1 ;
		mana = mana + 1;
		maxMana = maxMana + 1;
		power = power + 1;
		maxPower = maxPower + 1 ;
		maxXp = maxXp + 2;
	}else
		xp = xp + 1;

}


Any comments or suggestion to make this game better is kindly appreciated
AnswerRe: MY simple txt Based Rpg Pin
CPallini23-Sep-09 20:49
mveCPallini23-Sep-09 20:49 
GeneralRe: MY simple txt Based Rpg Pin
akosidandan23-Sep-09 21:12
akosidandan23-Sep-09 21:12 
GeneralRe: MY simple txt Based Rpg Pin
CPallini23-Sep-09 21:28
mveCPallini23-Sep-09 21:28 
GeneralRe: MY simple txt Based Rpg Pin
akosidandan23-Sep-09 21:47
akosidandan23-Sep-09 21:47 
GeneralRe: MY simple txt Based Rpg Pin
CPallini23-Sep-09 21:55
mveCPallini23-Sep-09 21:55 
GeneralRe: MY simple txt Based Rpg Pin
akosidandan24-Sep-09 16:01
akosidandan24-Sep-09 16:01 
QuestionPlease help to display System Tray Ballon in XP. [modified] Pin
Le@rner23-Sep-09 19:54
Le@rner23-Sep-09 19:54 
AnswerRe: Please help to display System Tray Ballon in XP. Pin
kilt24-Sep-09 7:01
kilt24-Sep-09 7:01 
Questionshell32.dll!7ca51646() Pin
MsmVc23-Sep-09 19:15
MsmVc23-Sep-09 19:15 
AnswerRe: shell32.dll!7ca51646() Pin
«_Superman_»23-Sep-09 19:30
professional«_Superman_»23-Sep-09 19:30 
GeneralRe: shell32.dll!7ca51646() Pin
MsmVc23-Sep-09 19:57
MsmVc23-Sep-09 19:57 
GeneralRe: shell32.dll!7ca51646() Pin
«_Superman_»23-Sep-09 20:34
professional«_Superman_»23-Sep-09 20:34 
GeneralRe: shell32.dll!7ca51646() Pin
MsmVc23-Sep-09 20:40
MsmVc23-Sep-09 20:40 
GeneralRe: shell32.dll!7ca51646() Pin
«_Superman_»23-Sep-09 20:42
professional«_Superman_»23-Sep-09 20:42 
GeneralRe: shell32.dll!7ca51646() Pin
MsmVc23-Sep-09 20:46
MsmVc23-Sep-09 20:46 
GeneralRe: shell32.dll!7ca51646() Pin
«_Superman_»23-Sep-09 20:53
professional«_Superman_»23-Sep-09 20:53 
GeneralRe: shell32.dll!7ca51646() Pin
MsmVc23-Sep-09 21:12
MsmVc23-Sep-09 21:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.