items for rpg

Started by
17 comments, last by fastcall22 15 years, 8 months ago
this store would be a funtion that the player would return to in the text based game but there are many issues with it is there a better way that i could do this?



#include<iostream>
using namespace std;
int main()
{
int health,num,gold,potions;
char buy;

cout<<"gold then potions you have now for demo sake"<<endl<<endl<<endl;

cin >>gold;//obtained gold and potion in other part of the game
cin >>potions;

cout<<endl;

cout<<"you now have "<<gold<< " gold to play with"<<endl;
cout<<"you have "<< potions <<" potions"<<endl;//tells the player what he has in invintory

cout<<"welcom to me strore"<<endl;

cout<<"Would you like to buy a health potion?"<<endl;

//choice of thing he wants to buy in the store right now just a potion for (demo)nstration
cout<<"to buy a health potion for 5 gold pres B"<<endl;

//simple yes no question
cin >>buy;

//if the player has no gold to spend
if(gold < 5)
{
cout<<"sorry you dont have the gold to buy me potions..."<<endl;
cout<<"Get Out"<<endl;
system("pause");
return 0;//would in a real game would return somewhere else.
}

else if(buy == 'b' ||buy == 'B')
{
int potion,gold;

cout<<"you bought a health potion"<<endl;
gold - 5;
potion + 1;


cout<<"you now have "<<gold<< " gold to play with"<<endl;
cout<<"you now have "<<potions<<" potions"<<endl;
system("pause");
return 0;
///option to leave the store blah blah
}

//if the player is just in the store
else cout<<"then go away ye scarrvy dog!!"<<endl;
system("pause");
return 0;

}
Advertisement
#include<iostream>using namespace std;int main(){int health,num,gold,potions;    char buy;    cout<<"gold then potions you have now for demo sake"<<endl<<endl<<endl;    cin >>gold;//obtained gold and potion in other part of the game    cin >>potions;        cout<<endl;    cout<<"you now have "<<gold<< " gold to play with"<<endl;    cout<<"you have "<< potions <<" potions"<<endl;//tells the player what he     has in invintory        cout<<"welcom to me strore"<<endl;        cout<<"Would you like to buy a health potion?"<<endl;        //choice of thing he wants to buy in the store right now just a potion for (demo)nstration    cout<<"to buy a health potion for 5 gold pres B"<<endl;        //simple yes no question    cin >>buy;           //if the player has no gold to spend      if(gold < 5)    {      cout<<"sorry you dont have the gold to buy me potions..."<<endl;      cout<<"Get Out"<<endl;      system("pause");      return 0;//would in a real game would return somewhere else.    }        else if(buy == 'b' ||buy == 'B')     {         int potion,gold;                  cout<<"you bought a health potion"<<endl;              gold - 5;         potion + 1;                   cout<<"you now have "<<gold<< " gold to play with"<<endl;       cout<<"you now have "<<potions<<" potions"<<endl;       system("pause");       return 0;       ///option to leave the store blah blah      }           //if the player is just in the store     else cout<<"then go away ye scarrvy dog!!"<<endl;     system("pause");  return 0; }



Well, first of all, you can read up on object-oriented-programming and/or C++ Then creating the classes "player", and "store" make programming fun and easier to manage!

(This code sample actually compiles and runs!)
#include <iostream>using namespace std;// Ok so here we go.// We're going to have an object to represent the player and his/her attributes:class player{public:	// The player will have potions and gold variables	int potions;	int gold;	// You can also have variables to describe the player's race, class, and name	// But for now, we'll keep it simplepublic:	// Here is what's called a "constructor," this is called when the player is created	// We want the progammer (aka you) to specify the starting amounts of the player's	// gold and potion, thus the "int p" and "int g" parameters	player( int p, int g ) 	{		// Set potions and gold		potions = p;		gold = g;		// Notify the console:		cout << "Player was created with " << potions << " potions and " << gold << " gold." << endl;	}	// Here is what's called the "destructor," this is called when the player class is destroyed.	~player() 	{		cout << "Player was destroyed :.(" << endl;	}	// Here we have a utility function to display the player's current gold and potions	void display_status()	{		cout << "You have " << gold << " gold and " << potions << " potions" << endl;	}};// Now we're going to create a store class that handles the store operations and other such etcclass store{private:	// The members of a store object	// Note, this is listed under "private," which means that only the functions below can access this variable	int	potions_in_stock;public:	// The constructor	store( int num_potions )	{		// Stock up on potions!		potions_in_stock = num_potions;		cout << "A store was created with " << potions_in_stock << " potions in stock." << endl;	}	// The destructor	~store()	{		cout << "The store was destroyed :.(" << endl;	}	// The player parameter is to specify which player is entering this store	// The '&' stands for "reference to" which means that we'll directly be	// modifying the player, and not a copy of it. 	// by changing it to "player the_player" we're going to be working with 	// a copy of the player that is passed, which isn't what we want, we want	// to modify the object itself.	void player_enters( player &the_player )	{		// Welcome message		cout << endl;		cout << "Welcome to my store!" << endl;		// Check to see if we have some potions:		if ( potions_in_stock == 0 )		{			// We don't			cout << "Unfortunately, I'm out of potions!" << endl;		}			else if ( the_player.gold < 5 ) // (We have potions and then) Check to see if the player has money		{			// He/she doesn't have money			cout << "Unfortunately, you requires more moneys" << endl;		}		else	// (The player has money and we have potions)		{			// This is the main loop, which will run forever until this boolean turn false (or the player buys all the potions)			bool player_is_still_buying = true; 			while ( player_is_still_buying && potions_in_stock > 0 ) // Reads as while the player is still buying and we still have potions			{				// Display player's status:				cout << endl;				the_player.display_status();				if ( the_player.gold < 5 ) // The player is unable to buy any more potions				{					cout << "Looks like you're out of money lol" << endl;					player_is_still_buying = false;					break; // Force out of the "while" loop				}				// Display the menu				cout << endl;				cout << "What would you like to buy?" << endl;				cout << "1) Potion (" << potions_in_stock << ")" << endl;				cout << "2) Leave" << endl;				cout << endl;				cout << "Enter choice: ";				// Get a choice from the user				int choice;				cin >> choice;				if ( choice == 2 ) // Player decides to leave					player_is_still_buying = false; // When this is set to false, this "while" loop will stop running				else				{ 					// Player decides not to leave					if ( choice == 1 ) // Player decides to buy a potion					{						the_player.gold -= 5; // Subtract the money out of the player						the_player.potions += 1; // Add a potion to the player						potions_in_stock -= 1; // Subtract a potion out of the store's stock						if ( potions_in_stock == 0 ) // Player bought the last potion						{							cout << "You just bought my last potion! D:" << endl;							player_is_still_buying = false; // Nothing left to buy!						}						else							cout << "Thank you for your business" << endl;					}				}				// (This is the end of the while loop, if all those '}' throw you off)			}		}		// Player is all done here.		cout << "Goodbye now!" << endl;	}};int main( int, char ** ){	// Temporary variables to get input from user	int g, p, ps;	// Self-explanatory:	cout << "Enter starting gold amount:" << endl;	cin >> g;	cout << "Enter starting potions amount:" << endl;	cin >> p;	cout << "Enter number of potions currently in stock (at the store)" << endl;	cin >> ps;	// This code block here is for demonstration of the constructors and destructors, and isn't necessary 	{		player hero( p, g );	// Create a player object named "hero" with "p" potions and "g" gold		store the_store( ps );	// Create a store object named "the_store" with "ps" potions in stock		// Main game loop		bool is_running = true;		while ( is_running ) // will loop forever until "is_running" is false		{			// Display separator, so it is easier to read:			cout << endl << endl;			// Display current player status:			hero.display_status();			// Display available choices:			cout << "There's a store nearby, what must you do?" << endl;			cout << "1) Enter store" << endl;			cout << "2) Make gold" << endl;			cout << "3) Exit game" << endl;			cout << endl;			cout << "Enter choice: " << endl;			// Receive a choice from the user:			int choice;			cin >> choice;			// Act on it:			if ( choice == 1 ) // Player enters the store				the_store.player_enters( hero );			else if ( choice == 2 ) // Player creates gold out of thin air			{				cout << "How much gold will you make:  " << endl;								int moar_gold;				cin >> moar_gold;				// Of course moar_gold could be a negative number... 				// Oh well, this is for debugging purposes anyway :)				hero.gold += moar_gold;			}			else if ( choice == 3 )	// Player decides he's had enough :)				is_running = false;		}		// And finally...		cout << "Thank you for playing!" << endl;	}	// Here, at this brace, the destructors of "hero" and "the_store" are automatically called	// Pause here so you can view the results 	cin.ignore();	cin.get();		return 0;}


This should give you several ideas on how to get started, and will advance your knowledge of C++ when you practice it. [smile]

If you still don't understand, try going step by step through the sample code using the debugger. If you are using visual studio, here's how you do it:

Press F10 to start the debugger.
Press F10 on statements using cout or cin, and press F11 on the others. (If you accidentally get into some unfamiliar looking code, press shift+F11 to step out of that function)

Also, you can use
[ source lang="cpp" ]
[ /source ]

to display your code, and you can use the "edit" button on the top right hand corner of your post to modify or delete your posts.

EDIT:
Here's a sample run of the code:
Enter starting gold amount:14Enter starting potions amount:0Enter number of potions currently in stock (at the store)3Player was created with 0 potions and 14 gold.A store was created with 3 potions in stock.You have 14 gold and 0 potionsThere's a store nearby, what must you do?1) Enter store2) Make gold3) Exit gameEnter choice:1Welcome to my store!You have 14 gold and 0 potionsWhat would you like to buy?1) Potion (3)2) LeaveEnter choice: 1Thank you for your businessYou have 9 gold and 1 potionsWhat would you like to buy?1) Potion (2)2) LeaveEnter choice: 1Thank you for your businessYou have 4 gold and 2 potionsLooks like you're out of money lolGoodbye now!You have 4 gold and 2 potionsThere's a store nearby, what must you do?1) Enter store2) Make gold3) Exit gameEnter choice:1Welcome to my store!Unfortunately, you requires more moneysGoodbye now!You have 4 gold and 2 potionsThere's a store nearby, what must you do?1) Enter store2) Make gold3) Exit gameEnter choice:2How much gold will you make:999You have 1003 gold and 2 potionsThere's a store nearby, what must you do?1) Enter store2) Make gold3) Exit gameEnter choice:1Welcome to my store!You have 1003 gold and 2 potionsWhat would you like to buy?1) Potion (1)2) LeaveEnter choice: 1You just bought my last potion! D:Goodbye now!You have 998 gold and 3 potionsThere's a store nearby, what must you do?1) Enter store2) Make gold3) Exit gameEnter choice:1Welcome to my store!Unfortunately, I'm out of potions!Goodbye now!You have 998 gold and 3 potionsThere's a store nearby, what must you do?1) Enter store2) Make gold3) Exit gameEnter choice:3Thank you for playing!The store was destroyed :.(Player was destroyed :.(


[Edited by - _fastcall on August 15, 2008 5:43:29 PM]
Quote:Original post by idono

cout<<"you bought a health potion"<<endl;
gold - 5;
potion + 1;


I saw this while skimming through so wanted to point it out, _fastcall amends it in the sample code he gave you, but to increment/decrement a variable you can't just leave it as is, your (fully written) line would need to read

gold = gold - 5;

Or the quicker way, which _fastcall uses, but does the same thing:

gold -= 5;

Both tell the system "assign the value of ((whatever value gold currently has) - 5) to the variable "gold". What you wrote is just the operation, it doesn't assign the outcome to anything.

Hazard Pay :: FPS/RTS in SharpDX (gathering dust, retained for... historical purposes)
DeviantArt :: Because right-brain needs love too (also pretty neglected these days)

i have a huge gold mind of errors and i cant see to figure then out i followed the
example but it does not compile what im i doing wrong?

#include <cstdlib>
#include<iostream>
#include<cmath>
#include<iomanip>
#include<ctime>
using namespace std;

class player1
{
public:

int Potions;
int Gold;
int flint_gun = 4;
int Wood_stick = 2;
int Rocket_lancher = 35;
int Ham_granade = 40;
int Nature_magic = 21;
int Electropulse = 15;
int Crule_Mace = 13;
int Ice_mace = 22;
int Deadly_wind = 25;

public:

player1(int P,int G,int F,int W,int R,int H, int N,int E,int C,int I,int D)
{
Potions = P;
Gold = G;
flint_gun = F;
Wood_stick = W;
Rocket_lancher = R;
Ham_granade = H;
Nature_magic = N;
Electropulse = E;
Crule_Mace = C;
Ice_mace = I;
Deadly_wind = D;
}

void display_status()
{
cout << "You have " << gold << " gold. " << potions << " potions." << endl;
cout << "You have " << flint_gun << " flint gun Ammo. " << Rocket_lancher << " Ammo." << endl;
cout << "You have " << Ham_granade << " Ham granades. " << Nature_magic << " spell." << endl;
cout << "You have " << Electropulse << " EMP's. " << Deadly_wind << " spell." << endl;
cout << "You have " << Crule_Mace << ". " << Ice_mace << "." << endl;
}

class store
{
private:

int potions_avalible;
int flint_gun_Ammo_avalible;
int Rocket_lancher_Ammo_avalible;
int Ham_granade_Ammo_avalible;
int Nature_magic_spell_avalible;
int Electropulse_Ammo_avalible;
int Crule_Mace_avalible;
int Ice_mace_avalible;
int Deadly_wind_spell_avalible;

public:

store( int num_potions_in_store,
int num_flint_gun_Ammo,
int num_Rocket_lancher_Ammo,
int num_Ham_granade_Ammo,
int num_Nature_magic_spell,
int num_Electropulse_Ammo,
int num_Crule_Mace,
int num_Ice_mace,
int num_Deadly_wind_spell)

{
potions_avalible = num_potions_in_store;
flint_gun_Ammo_avalible = num_flint_gun_Ammo;
Rocket_lancher_Ammo_avalible = num_Rocket_lancher_Ammo;
Ham_granade_Ammo_avalible = num_Ham_granade_Ammo;
Nature_magic_spell_avalible = num_Nature_magic_spell;
Electropulse_Ammo_avalible = num_Electropulse_Ammo;
Crule_Mace_avalible = num_Crule_Mace;
Ice_mace_avalible = num_Ice_mace;
Deadly_wind_spell_avalible = num_Deadly_wind_spell;
}

void player_enters( player1 &the_player )
{

cout<<endl;
cout<< "Hello young fighter!!!" <<endl;
cout<< "Welcome to the fighters Dirty Den" <<endl;
cout<< "we have every thing you could possibly want" <<endl;

if(potions_avalible == 0)
{
cout<<" out of stock"<<endl;
}

if(flint_gun_Ammo_avalible == 0)
{
cout<<" out of stock"<<endl;
}

if(Rocket_lancher_Ammo_avalible == 0)
{
cout<<" out of stock"<<endl;
}

if(Ham_granade_Ammo_avalible == 0)
{
cout<<" out of stock"<<endl;
}

if(Nature_magic_spell_avalible == 0)
{
cout<<" out of stock"<<endl;
}

if(Electropulse_Ammo_avalible == 0)
{
cout<<" out of stock"<<endl;
}

if(Crule_Mace_avalible == 0)
{
cout<<" out of stock"<<endl;
}

if(Ice_mace_avalible == 0)
{
cout<<" out of stock"<<endl;
}

if(Deadly_wind_spell_avalible == 0)
{
cout<<" out of stock"<<endl;
}

else if ( the_player.gold < 5 ) // (We have potions and then) Check to see if the player has money
{
// He/she doesn't have money
cout << "all thats to bad ouuta money well then.. Get Out" << endl;
}

else
{
bool player_is_still_buying = true;
while ( player_is_still_buying && potions_avalible > 0 || player_is_still_buying && flint_gun_Ammo_avalible > 0||
player_is_still_buying && Rocket_lancher_Ammo_avalible > 0||player_is_still_buying && Ham_granade_Ammo_avalible > 0||
player_is_still_buying && Nature_magic_spell_avalible > 0||player_is_still_buying && Electropulse_Ammo_avalible > 0||
player_is_still_buying && Crule_Mace_avalible > 0||player_is_still_buying && Ice_mace_avalible > 0||
player_is_still_buying && Deadly_wind_spell_avalible > 0)
{

cout << endl;
the_player.display_status();

if ( the_player.gold < 0 ) // The player is unable to buy any more potions

{
cout << "Well i gesss i have all your money AH AH AH...i hate me self" << endl;
player_is_still_buying = false;
break; // Force out of the "while" loop
}

cout << endl;
cout << "What would you like to buy?" << endl;
cout << "1) Potion $3 (" << potions_avalible << ")" << endl;
cout << "2) Flint Gun Ammo $5 (" << flint_gun_Ammo_avalible << ")" << endl;
cout << "3) Rocket Lancher Ammo $40(" << Rocket_lancher_Ammo_avalible << ")" << endl;
cout << "4) Ham Granades $65(" << Ham_granade_Ammo_avalible << ")" << endl;
cout << "5) Nature Magic spell $10(" << Nature_magic_spell_avalible << ")" << endl;
cout << "6) Electropulse $12(" << Electropulse_Ammo_avalible << ")" << endl;
cout << "8) Crule Mace $70(" << Crule_Mace_avalible << ")" << endl;
cout << "8) Ice mace $56(" << Ice_mace_avalible << ")" << endl;
cout << "9) Deadly wind spell $13(" << Deadly_wind_spell_avalible << ")" << endl;
cout << "10) Leave" << endl;
cout << endl;
cout << "Enter choice: ";

int choice;
cin >> choice;

if(choice == 10)
player_is_still_buying = false;

else
{
if(choice == 1)
{
the_player.gold -= 3;
the_player.potions += 1;
potions_avalible -= 1;
}

if(choice == 2)
{
the_player.gold -= 5;
the_player.flint_gun += 1;
flint_gun_Ammo_avalible -= 1;
}

if(choice == 3)
{
the_player.gold -= 40;
the_player.Rocket_lancher += 1;
Rocket_lancher_Ammo_avalible -= 1;
}

if(choice == 4)
{
the_player.gold -= 65;
the_player.Ham_granade += 1;
Ham_granade_Ammo_avalible -= 1;
}

if(choice == 5)
{
the_player.gold -= 10;
the_player.Nature_magic += 1;
Nature_magic_spell_avalible -= 1;
}

if(choice == 6)
{
the_player.gold -= 12;
the_player.Electropulse += 1;
Electropulse_Ammo_avalible -= 1;
}

if(choice == 7)
{
the_player.gold -= 70;
the_player.Crule_Mace += 1;
Crule_Mace_avalible -= 1;
}


if(choice == 8)
{
the_player.gold -= 56;
the_player.Ice_mace += 1;
Ice_mace_avalible -= 1;
}


if(choice == 9)
{
the_player.gold -= 13;
the_player.Deadly_wind += 1;
Deadly_wind_spell_avalible -= 1;
}



if ( potions_in_stock == 0 ) // Player bought the last potion
{
cout << "You Rich Basterd you took all me potions HA HA HA..." << endl;
player_is_still_buying = false; // Nothing left to buy!
}

if ( potions_in_stock == 0 ) // Player bought the last potion
{
cout << "more people like you come in here and i can retire HA HA HA..." << endl;
player_is_still_buying = false; // Nothing left to buy!
}

if ( potions_in_stock == 0 ) // Player bought the last potion
{
cout << "Hmmm all those Exploseives hmm are you some kind of Terrorist? HA HA HA..." << endl;
player_is_still_buying = false; // Nothing left to buy!
}

if ( potions_in_stock == 0 ) // Player bought the last potion
{
cout << "mmmm Granade Ham five star dinner right there HA HA HA..." << endl;
player_is_still_buying = false; // Nothing left to buy!
}

if ( potions_in_stock == 0 ) // Player bought the last potion
{
cout << "Magic thats stuff's for girls! HA HA HA..." << endl;
player_is_still_buying = false; // Nothing left to buy!
}

if ( potions_in_stock == 0 ) // Player bought the last potion
{
cout << "Hey you have a vacation planed in the Maxtix or something? HA HA HA..." << endl;
player_is_still_buying = false; // Nothing left to buy!
}

if ( potions_in_stock == 0 ) // Player bought the last potion
{
cout << "they Call it Crule, but its not as crule as me wifes cooking HA HA HA..." << endl;
player_is_still_buying = false; // Nothing left to buy!
}

if ( potions_in_stock == 0 ) // Player bought the last potion
{
cout << "hmm thats pretty cool.. get it coool HA HA HA..." << endl;
player_is_still_buying = false; // Nothing left to buy!
}

if ( potions_in_stock == 0 ) // Player bought the last potion
{
cout << "that Deadly wind is not match for my Mighty Fart! HA HA HA..." << endl;
player_is_still_buying = false; // Nothing left to buy!
}

else
cout<<"thanks for your time Raaaggghh im a pirate now lulz!?!?."<<endl;

}
}
}
}

cout << "C yah later HA Ha Haaa!" << endl;
system("CLS");
}
};
int main(int argc, char *argv[])
{

const int name = 30;
char player1[name];
int G = 300, P = 4, PS = 3,F = 2,R = 2,E = 3,H = 4,I = 1,D = 2,C = 1;

system("title Tale of Argonia 2: The Wizzerd and the Demon Bull King Demo ");
system("color 9");

cout<<"please enter your name Hero"<<endl;
cin >> setw (name) >> player1;

cout<<"Days later after you slain the Gorbling Commander life has slowly"<<endl;
cout<<"creeped back to normal.."<<endl;

system("pause");
system("CLS");

cout<<"hey " << player1 <<" what are you doing here?"<<endl;

cout<<"lets see if the Market is open"<<endl;

cout<<"this is a demo fuction of market"<<endl;

system("pasue");

player_enters( player1 );

system("PAUSE");
return EXIT_SUCCESS;
}
[\code]
#include <cstdlib>#include<iostream>#include<cmath>#include<iomanip>#include<ctime>using namespace std;    class player1     {      public:                    int Potions;          int Gold;          int flint_gun = 4;          int Wood_stick =  2;          int Rocket_lancher = 35;          int Ham_granade = 40;          int Nature_magic = 21;          int Electropulse = 15;          int Crule_Mace = 13;          int Ice_mace = 22;          int Deadly_wind = 25;                public:                   player1(int P,int G,int F,int W,int R,int H, int N,int E,int C,int I,int D)           {             Potions = P;             Gold = G;             flint_gun = F;             Wood_stick = W;             Rocket_lancher = R;             Ham_granade = H;             Nature_magic = N;             Electropulse = E;             Crule_Mace = C;             Ice_mace = I;             Deadly_wind = D;          }       void display_status()        {            cout << "You have " << gold << " gold. " << potions << " potions." << endl;            cout << "You have " << flint_gun << " flint gun Ammo. " << Rocket_lancher << " Ammo." << endl;            cout << "You have " << Ham_granade << " Ham granades. " << Nature_magic << " spell." << endl;            cout << "You have " << Electropulse << " EMP's. " << Deadly_wind << " spell." << endl;            cout << "You have " << Crule_Mace << ". " << Ice_mace << "." << endl;        }       class store        {         private:                          int potions_avalible;               int flint_gun_Ammo_avalible;             int Rocket_lancher_Ammo_avalible;             int Ham_granade_Ammo_avalible;             int Nature_magic_spell_avalible;             int Electropulse_Ammo_avalible;             int Crule_Mace_avalible;             int Ice_mace_avalible;             int Deadly_wind_spell_avalible;                                 public:                                 store( int num_potions_in_store,                         int num_flint_gun_Ammo,                       int num_Rocket_lancher_Ammo,                       int num_Ham_granade_Ammo,                       int num_Nature_magic_spell,                       int num_Electropulse_Ammo,                       int num_Crule_Mace,                       int num_Ice_mace,                       int num_Deadly_wind_spell)                                      {                        potions_avalible = num_potions_in_store;                       flint_gun_Ammo_avalible = num_flint_gun_Ammo;                       Rocket_lancher_Ammo_avalible = num_Rocket_lancher_Ammo;                       Ham_granade_Ammo_avalible = num_Ham_granade_Ammo;                       Nature_magic_spell_avalible = num_Nature_magic_spell;                       Electropulse_Ammo_avalible = num_Electropulse_Ammo;                       Crule_Mace_avalible = num_Crule_Mace;                       Ice_mace_avalible = num_Ice_mace;                       Deadly_wind_spell_avalible = num_Deadly_wind_spell;                       }                                  void player_enters( player1 &the_player )        {                  cout<<endl;         cout<< "Hello young fighter!!!" <<endl;         cout<< "Welcome to the fighters Dirty Den" <<endl;         cout<< "we have every thing you could possibly want" <<endl;    if(potions_avalible == 0)     {        cout<<" out of stock"<<endl;     }             if(flint_gun_Ammo_avalible == 0)     {        cout<<" out of stock"<<endl;     }     if(Rocket_lancher_Ammo_avalible == 0)     {        cout<<" out of stock"<<endl;     }      if(Ham_granade_Ammo_avalible == 0)     {        cout<<" out of stock"<<endl;     }     if(Nature_magic_spell_avalible == 0)     {        cout<<" out of stock"<<endl;     }     if(Electropulse_Ammo_avalible == 0)     {        cout<<" out of stock"<<endl;     }     if(Crule_Mace_avalible == 0)     {        cout<<" out of stock"<<endl;     }     if(Ice_mace_avalible == 0)     {        cout<<" out of stock"<<endl;     }     if(Deadly_wind_spell_avalible == 0)     {        cout<<" out of stock"<<endl;     }     else if ( the_player.gold < 5 ) // (We have potions and then) Check to see if the player has money		{			// He/she doesn't have money			cout << "all thats to bad ouuta money well then.. Get Out" << endl;		}     else        {           bool player_is_still_buying = true;            while ( player_is_still_buying && potions_avalible > 0 || player_is_still_buying && flint_gun_Ammo_avalible > 0||                       player_is_still_buying && Rocket_lancher_Ammo_avalible > 0||player_is_still_buying && Ham_granade_Ammo_avalible > 0||                                 player_is_still_buying && Nature_magic_spell_avalible > 0||player_is_still_buying && Electropulse_Ammo_avalible > 0||                                        player_is_still_buying && Crule_Mace_avalible > 0||player_is_still_buying && Ice_mace_avalible > 0||                      player_is_still_buying && Deadly_wind_spell_avalible > 0)                {                                                             cout << endl;                   the_player.display_status();                                             if ( the_player.gold < 0 ) // The player is unable to buy any more potions				                {					cout << "Well i gesss i have all your money AH AH AH...i hate me self" << endl;					player_is_still_buying = false;					break; // Force out of the "while" loop				}                                       cout << endl;				cout << "What would you like to buy?" << endl;				cout << "1) Potion              $3 (" << potions_avalible << ")" << endl;				cout << "2) Flint Gun Ammo      $5 (" << flint_gun_Ammo_avalible << ")" << endl;				cout << "3) Rocket Lancher Ammo $40(" << Rocket_lancher_Ammo_avalible << ")" << endl;				cout << "4) Ham Granades        $65(" << Ham_granade_Ammo_avalible << ")" << endl; 				cout << "5) Nature Magic spell  $10(" << Nature_magic_spell_avalible << ")" << endl;                cout << "6) Electropulse        $12(" << Electropulse_Ammo_avalible << ")" << endl;                cout << "8) Crule Mace          $70(" << Crule_Mace_avalible << ")" << endl;				cout << "8) Ice mace            $56(" << Ice_mace_avalible << ")" << endl;                cout << "9) Deadly wind spell   $13(" << Deadly_wind_spell_avalible << ")" << endl;                cout << "10) Leave" << endl;                cout << endl;                cout << "Enter choice: ";                        int choice;				cin >> choice;                       if(choice == 10)                     player_is_still_buying = false;                      else                  {                      if(choice == 1)                      {                           the_player.gold -= 3;                           the_player.potions += 1;                           potions_avalible -= 1;                      }                            if(choice == 2)                      {                           the_player.gold -= 5;                           the_player.flint_gun += 1;                           flint_gun_Ammo_avalible -= 1;                      }                                                       if(choice == 3)                      {                           the_player.gold -= 40;                           the_player.Rocket_lancher += 1;                           Rocket_lancher_Ammo_avalible -= 1;                      }                                 if(choice == 4)                      {                           the_player.gold -= 65;                           the_player.Ham_granade += 1;                           Ham_granade_Ammo_avalible -= 1;                      }                             if(choice == 5)                      {                           the_player.gold -= 10;                           the_player.Nature_magic += 1;                           Nature_magic_spell_avalible -= 1;                      }                                  if(choice == 6)                      {                           the_player.gold -= 12;                           the_player.Electropulse += 1;                           Electropulse_Ammo_avalible -= 1;                      }                            if(choice == 7)                      {                           the_player.gold -= 70;                           the_player.Crule_Mace += 1;                           Crule_Mace_avalible -= 1;                      }                            if(choice == 8)                      {                           the_player.gold -= 56;                           the_player.Ice_mace += 1;                           Ice_mace_avalible -= 1;                      }                            if(choice == 9)                      {                           the_player.gold -= 13;                           the_player.Deadly_wind += 1;                           Deadly_wind_spell_avalible -= 1;                      }                             if ( potions_in_stock == 0 ) // Player bought the last potion						{							cout << "You Rich Basterd you took all me potions HA HA HA..." << endl;							player_is_still_buying = false; // Nothing left to buy!						}                       if ( potions_in_stock == 0 ) // Player bought the last potion						{							cout << "more people like you come in here and i can retire HA HA HA..." << endl;							player_is_still_buying = false; // Nothing left to buy!						}                        if ( potions_in_stock == 0 ) // Player bought the last potion						{							cout << "Hmmm all those Exploseives hmm are you some kind of Terrorist? HA HA HA..." << endl;							player_is_still_buying = false; // Nothing left to buy!						}                              if ( potions_in_stock == 0 ) // Player bought the last potion						{							cout << "mmmm Granade Ham five star dinner right there HA HA HA..." << endl;							player_is_still_buying = false; // Nothing left to buy!						}                         if ( potions_in_stock == 0 ) // Player bought the last potion						{							cout << "Magic thats stuff's for girls! HA HA HA..." << endl;							player_is_still_buying = false; // Nothing left to buy!						}                        if ( potions_in_stock == 0 ) // Player bought the last potion						{							cout << "Hey you have a vacation planed in the Maxtix or something? HA HA HA..." << endl;							player_is_still_buying = false; // Nothing left to buy!						}                         if ( potions_in_stock == 0 ) // Player bought the last potion						{							cout << "they Call it Crule, but its not as crule as me wifes cooking HA HA HA..." << endl;							player_is_still_buying = false; // Nothing left to buy!						}                        if ( potions_in_stock == 0 ) // Player bought the last potion						{							cout << "hmm thats pretty cool.. get it coool HA HA HA..." << endl;							player_is_still_buying = false; // Nothing left to buy!						}                        if ( potions_in_stock == 0 ) // Player bought the last potion						{							cout << "that Deadly wind is not match for my Mighty Fart! HA HA HA..." << endl;							player_is_still_buying = false; // Nothing left to buy!						}                     else                         cout<<"thanks for your time Raaaggghh im a pirate now lulz!?!?."<<endl;                         }                       }                   }                }        cout << "C yah later HA Ha Haaa!" << endl;	    system("CLS");            }         };int main(int argc, char *argv[]){    const int name = 30;    char player1[name];    int G = 300, P = 4, PS = 3,F = 2,R = 2,E = 3,H = 4,I = 1,D = 2,C = 1;      system("title    Tale of Argonia 2: The Wizzerd and the Demon Bull King Demo  ");    system("color 9");                          cout<<"please enter your name Hero"<<endl;    cin >> setw (name) >> player1;         cout<<"Days later after you slain the Gorbling Commander life has slowly"<<endl;    cout<<"creeped back to normal.."<<endl;    system("pause");    system("CLS");    cout<<"hey " << player1 <<" what are you doing here?"<<endl;    cout<<"lets see if the Market is open"<<endl;     cout<<"this is a demo fuction of market"<<endl;     system("pasue");        player_enters( player1  );    system("PAUSE");    return EXIT_SUCCESS;}
When I really look at it fastcall_'s method is much more better.
--------------------------------To slap or not to slap that is the question? Ehh what the heck slap.
i finally got the code no work a few days ago, and i now better understand how the code for the player works an there relationship to items,but can this code above be adapted to combat like the code i made earlier. gain gold or items out of it? or do i need to re-work the code completely?


#include<iostream>#include<cmath>#include<cstdlib>#include<iomanip>#include<ctime>using namespace std;int main(){    cout<<"  What do you do!"<<endl;      char Fight;    cout<<"  Press F to fight";	cout<<" or Press any key for Quit: ";    cin >>Fight;    if(Fight == 'F' || Fight == 'f')/////story my continues in here//////		{    //monster always attaks first       ///////weapons & Damage///    double Flint_Gun = 5;    double Small_Dagger = 3;    double health = 70;    double Wooden_stick = 3;    double Gobling_health = 30;    double health_potion = 10;    double bonus_10 = 10;	///i ran the program no loss of data found in my program.	unsigned Gobling_Damage = time(0);	//////////////////////////                       		while (Gobling_health >= 1 && health >= 1)						{///master while for combat			    cout<<"  your health "<<health<<endl;    cout<<"  the Gobling "<<Gobling_health<<endl;       srand(Gobling_Damage);    Gobling_Damage = (rand() % 10) + 1;   cout<<"  The Goblin did "<<Gobling_Damage<<" Damage"<<endl;    health = health - Gobling_Damage;		///1 spaces////////////////    int space = 1;                while(space <= 1){            cout <<""<<endl;            space++;}          ///////////////////////////        cout<<"  your health "<<health<<endl;    cout<<"  the Gobling "<<Gobling_health<<endl;             system("pause");			///1 spaces////////////////    space = 1;                while(space <= 1){            cout <<""<<endl;            space++;}          ///////////////////////////    	char Attack;		//condition that player1 dies in fight		if(Gobling_health > 0 && health < 1)		{			cout<<"  Your killed lolz sorry"<<endl;				system("Title        Game Over          ");				system ("pause");		return 0;		}		cout<<"  pick a weapon and fight or he will kill you!"<<endl;    cout<<"  S:Small Dagger attack 3"<<endl;    cout<<"  F:Flint Gun attack 5"<<endl;    cout<<"  W:Wooden stick 2"<<endl;    cout<<"  P:health bottle"<<endl;    cout<<"  pick or die: ";    cin >>Attack;		///2 spaces////////////////    space = 1;                while(space <= 2){            cout <<""<<endl;            space++;}          ///////////////////////////	    //these are the condition of fighting 		if(Attack == 'S' || Attack == 's')		{               	Gobling_Damage = (rand() % 10) + 1;    	Gobling_health = Gobling_health - Small_Dagger;        cout<<"  Small Dagger Attack dealed 3 Damage! "<<endl;   		}       						if(Attack == 'F' || Attack == 'f')		{           	Gobling_Damage = (rand() % 20) + 1;	Gobling_health = bonus_10 + Gobling_health - Flint_Gun;	cout<<"  Flint Gun attack dealed 5 Damage! "<<endl;   	cout<<"  you hit the monster but bullets make it Stronger!!!"<<endl;		}       				if(Attack == 'W' || Attack == 'w')		{                   Gobling_Damage = (rand() % 8) + 1;        Gobling_health = Gobling_health - Wooden_stick;	cout<<"  Wooden stick attack dealed 3 Damage! "<<endl;   		}							if(Attack == 'P' || Attack == 'p')		{                  Gobling_Damage = (rand() % 5) + 1;	health =  health + health_potion ;	cout<<"  Monster Attacked you but"<<endl;	cout<<"  health bottle gave you 5 health! "<<endl;   		}			///5 spaces////////////////    space = 1;                while(space <= 5){            cout <<""<<endl;            space++;}          ///////////////////////////	//ondiction that player1 wins 		  if(Gobling_health <= 0 && health > 0)		{                   system("Title        The Tale of Argoonia          ");        system("Color 3");                              cout<<"  you did it the town of Argonia is safe but for how long"<<endl;        cout<<"                           The End"<<endl;   ///2 spaces////////////////    space = 1;                while(space <= 2){            cout <<""<<endl;            space++;}          /////////////////////////// cout<<" Argonia 2:The Wizzerd and the Demon Bull King comming soon!!!"<<endl;     cout<<" Talk to idono about it!!"<<endl;																	system ("pause");								return 0;																					            }													}///master while for combat end		}     else cout<<"You have failed do anything to save your friends or yourcity"<<endl;    system ("pause");   return 0;}

Quote:Original post by idono
i now better understand how the code for the player works an there relationship to items,but can this code above be adapted to combat like the code i made earlier. gain gold or items out of it? or do i need to re-work the code completely?


It's completely up to you, if you want to rewrite it or not. However, judging by your code, I'd rewrite the whole thing; but this time, put more emphasis on representing objects and events as objects. But, before you begin coding, you might want to plan out what kind of objects you're going to need first. Get a pen and paper. Think through your game, step by step, in your head. Write down any nouns in your game that could be represented as objects. (A lot of examples of objects have been covered.) Next, write down next to those objects you've written down functionality they might need -- such as a sword might need an equip() method to modify the player's stats accordingly (and also a dagger, so why not create a base class weapon to provide equip() for both the sword and dagger?). Do you see what I'm saying? Object oriented programming is difficult at first, but as you practice it, you'll never program without it! [smile]

Here's a nice tutorial on Object-Oriented programming:
Introduction to C++ Classes and Objects

This topic is closed to new replies.

Advertisement