473,405 Members | 2,176 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Change single value object to multiple value object

134 100+
anyone know how i could take this code and make it so i could change "enemy"
to something where i could use one script, but add some more small codes to
make enemy span into many things (ex. Rat, Bird.. whatever)

thanks for your help


Expand|Select|Wrap|Line Numbers
  1. int TheEnemiesHealth=5;
  2. int TheEnemiesMaxHealth=5;
  3. char HurtEnemy;
  4.  
  5. bool HurtTheEnemy ()
  6. {
  7.      //GetDamageNow();
  8.      Damage=PlayerPower+1+WeaponPower+PoisonPower;
  9.      TheEnemiesHealth=TheEnemiesHealth-Damage;
  10. }
  11.  
  12. bool ResetEnemyHealth ()
  13. {
  14.      TheEnemiesHealth=TheEnemiesMaxHealth;
  15. }
  16.  
  17. bool FightEnemy ()
  18. {
  19.  
  20.     cout<<"You see an enemy and approach it.\n";
  21.     ArmorList();
  22.     while (TheEnemiesHealth >= 1)
  23.     {
  24.     cout<<"\nWhat would you like to do?\n";
  25.     cout<<"1.Use Weapon\n";
  26.     cout<<"2.Use Hands\n";
  27.  
  28.     cout <<">";
  29.  
  30.  
  31.         cin >> HurtEnemy;
  32.         cin.ignore(20,'\n');
  33.         if (HurtEnemy == '1')
  34.         {
  35.                     GetWeapons();
  36.                     //////////////////////////////////////////////////
  37.  
  38.                     HurtTheEnemy();
  39.                     //cout<<"You use your weapon.";
  40.                     cout<<"\n\nThe enemy has ";
  41.                     cout<<TheEnemiesHealth;
  42.                     cout<<" / ";
  43.                     cout<<TheEnemiesMaxHealth;
  44.                     cout<<" Health";
  45.  
  46.         }
  47.          if (HurtEnemy == '2')
  48.          {
  49.                     HurtTheEnemy();
  50.                     cout<<"\nYou use your hands\n";
  51.                     HandIsOut();
  52.                     cout<<"\n\nThe enemy has ";
  53.                     cout<<TheEnemiesHealth;
  54.                     cout<<" / ";
  55.                     cout<<TheEnemiesMaxHealth;
  56.                     cout<<" Health";
  57.  
  58.         }
  59.          if(TheEnemiesHealth>0)
  60.          {
  61.        EnemyAttackYou();
  62.        }
  63.        }
  64.        if (TheEnemiesHealth < 1)
  65.        {
  66.                          cout<<"\nYou killed the enemy\n";
  67.                          cout<<"You gained 1 experience point.\nYou now have ";
  68.                          Add1Exp();
  69.                          GetExp();
  70.                          cout<<" experience points.\n";
  71.                          cin.get();
  72.                          cout<<"You return to Imperial City\n\n";
  73.                          ResetEnemyHealth();
  74.                          cin.get();
  75.                          }
  76. }
  77.  

Expand|Select|Wrap|Line Numbers
  1. bool EnemyAttackYou()
  2. {
  3.      int MaxEnemyHurtYou= 4;
  4.      srand ( time(NULL) );
  5.      int EnemyHurtYou = rand() % MaxEnemyHurtYou;
  6.      cout<<"\nThe enemy attacks you, subtracting ";
  7.      cout<<EnemyHurtYou;
  8.      cout<<" Health\n";
  9.      PersonsHealth=PersonsHealth-EnemyHurtYou;
  10.      CheckLiving();
  11.      CheckLifeLeft();
  12. }
  13.  
May 2 '07 #1
5 1368
ilikepython
844 Expert 512MB
anyone know how i could take this code and make it so i could change "enemy"
to something where i could use one script, but add some more small codes to
make enemy span into many things (ex. Rat, Bird.. whatever)

thanks for your help


Expand|Select|Wrap|Line Numbers
  1. int TheEnemiesHealth=5;
  2. int TheEnemiesMaxHealth=5;
  3. char HurtEnemy;
  4.  
  5. bool HurtTheEnemy ()
  6. {
  7.      //GetDamageNow();
  8.      Damage=PlayerPower+1+WeaponPower+PoisonPower;
  9.      TheEnemiesHealth=TheEnemiesHealth-Damage;
  10. }
  11.  
  12. bool ResetEnemyHealth ()
  13. {
  14.      TheEnemiesHealth=TheEnemiesMaxHealth;
  15. }
  16.  
  17. bool FightEnemy ()
  18. {
  19.  
  20.     cout<<"You see an enemy and approach it.\n";
  21.     ArmorList();
  22.     while (TheEnemiesHealth >= 1)
  23.     {
  24.     cout<<"\nWhat would you like to do?\n";
  25.     cout<<"1.Use Weapon\n";
  26.     cout<<"2.Use Hands\n";
  27.  
  28.     cout <<">";
  29.  
  30.  
  31.         cin >> HurtEnemy;
  32.         cin.ignore(20,'\n');
  33.         if (HurtEnemy == '1')
  34.         {
  35.                     GetWeapons();
  36.                     //////////////////////////////////////////////////
  37.  
  38.                     HurtTheEnemy();
  39.                     //cout<<"You use your weapon.";
  40.                     cout<<"\n\nThe enemy has ";
  41.                     cout<<TheEnemiesHealth;
  42.                     cout<<" / ";
  43.                     cout<<TheEnemiesMaxHealth;
  44.                     cout<<" Health";
  45.  
  46.         }
  47.          if (HurtEnemy == '2')
  48.          {
  49.                     HurtTheEnemy();
  50.                     cout<<"\nYou use your hands\n";
  51.                     HandIsOut();
  52.                     cout<<"\n\nThe enemy has ";
  53.                     cout<<TheEnemiesHealth;
  54.                     cout<<" / ";
  55.                     cout<<TheEnemiesMaxHealth;
  56.                     cout<<" Health";
  57.  
  58.         }
  59.          if(TheEnemiesHealth>0)
  60.          {
  61.        EnemyAttackYou();
  62.        }
  63.        }
  64.        if (TheEnemiesHealth < 1)
  65.        {
  66.                          cout<<"\nYou killed the enemy\n";
  67.                          cout<<"You gained 1 experience point.\nYou now have ";
  68.                          Add1Exp();
  69.                          GetExp();
  70.                          cout<<" experience points.\n";
  71.                          cin.get();
  72.                          cout<<"You return to Imperial City\n\n";
  73.                          ResetEnemyHealth();
  74.                          cin.get();
  75.                          }
  76. }
  77.  

Expand|Select|Wrap|Line Numbers
  1. bool EnemyAttackYou()
  2. {
  3.      int MaxEnemyHurtYou= 4;
  4.      srand ( time(NULL) );
  5.      int EnemyHurtYou = rand() % MaxEnemyHurtYou;
  6.      cout<<"\nThe enemy attacks you, subtracting ";
  7.      cout<<EnemyHurtYou;
  8.      cout<<" Health\n";
  9.      PersonsHealth=PersonsHealth-EnemyHurtYou;
  10.      CheckLiving();
  11.      CheckLifeLeft();
  12. }
  13.  
First, you shouldn't have all those bool functions if you are not returning any value. They should be set to void.

If you want to have different enemies I suggest using classes or structs:
Expand|Select|Wrap|Line Numbers
  1. struct enemy{
  2.     string name;
  3.     int health;
  4.     int maxHealth;
  5.     int maxDamage;
  6.     etc... ...
  7. };
  8.  
The classes are a little more complicated but post if you are interested. Also, if you think this is going to change your whole game design then you shouldn't do it.
If you want to do it without structs or classes you could have a variable that says the current type of the enemy and then each battle change the attributes(health, damage, etc...) depending on what that variable says. Choose whichever would work best for you.
May 2 '07 #2
lumpybanana247
134 100+
First, you shouldn't have all those bool functions if you are not returning any value. They should be set to void.

If you want to have different enemies I suggest using classes or structs:
Expand|Select|Wrap|Line Numbers
  1. struct enemy{
  2.     string name;
  3.     int health;
  4.     int maxHealth;
  5.     int maxDamage;
  6.     etc... ...
  7. };
  8.  
The classes are a little more complicated but post if you are interested. Also, if you think this is going to change your whole game design then you shouldn't do it.
If you want to do it without structs or classes you could have a variable that says the current type of the enemy and then each battle change the attributes(health, damage, etc...) depending on what that variable says. Choose whichever would work best for you.
just a few quick questions first (on struct) would somthing like RAT replace enemy? and what do i do with string name?


thanks,
--Nate
May 2 '07 #3
ilikepython
844 Expert 512MB
just a few quick questions first (on struct) would somthing like RAT replace enemy? and what do i do with string name?


thanks,
--Nate
Enemy is just the "type" of object. Your "name" is not really needed but I just added it just in case you wanted to have a name for the enemy but it is not really necessary. Look at this:
Expand|Select|Wrap|Line Numbers
  1. struct Enemy{
  2.     int health;
  3.     int damage;
  4.     int maxHealth;
  5. };
  6. int main(){
  7.     Enemy rat;    //make rat object of "enemy" type
  8.  
  9.     rat.damage = 2;   //initialize attributes of a "rat"
  10.     rat.maxHealth = 10;
  11.     rat.health = rat.maxHealth;
  12.  
  13.     Enemy bat;      //make bat object of "enemy" type
  14.  
  15.     bat.damage = 5;
  16.     bat.maxHealth = 15;
  17.     bat.health = bat.maxHealth;
  18.  
  19.    //later...
  20.     rat.health -= player_damage; //just an example
  21.     (rat.health -= is the same as rat.health = rat.health - )
  22.  
  23.     return 0;
  24. }
  25.  
Does that help?

You can create "enemy" objects any time you want such as when the player enters a battle by the method shown above.
May 2 '07 #4
lumpybanana247
134 100+
Enemy is just the "type" of object. Your "name" is not really needed but I just added it just in case you wanted to have a name for the enemy but it is not really necessary. Look at this:
Expand|Select|Wrap|Line Numbers
  1. struct Enemy{
  2.     int health;
  3.     int damage;
  4.     int maxHealth;
  5. };
  6. int main(){
  7.     Enemy rat;    //make rat object of "enemy" type
  8.  
  9.     rat.damage = 2;   //initialize attributes of a "rat"
  10.     rat.maxHealth = 10;
  11.     rat.health = rat.maxHealth;
  12.  
  13.     Enemy bat;      //make bat object of "enemy" type
  14.  
  15.     bat.damage = 5;
  16.     bat.maxHealth = 15;
  17.     bat.health = bat.maxHealth;
  18.  
  19.    //later...
  20.     rat.health -= player_damage; //just an example
  21.     (rat.health -= is the same as rat.health = rat.health - )
  22.  
  23.     return 0;
  24. }
  25.  
Does that help?

You can create "enemy" objects any time you want such as when the player enters a battle by the method shown above.


SWEET!!!!
that saved me a few hours!!!
Thank you very much!
i didnt even have to rewrite much of the script!

thanks again,
--Nate
May 2 '07 #5
ilikepython
844 Expert 512MB
SWEET!!!!
that saved me a few hours!!!
Thank you very much!
i didnt even have to rewrite much of the script!

thanks again,
--Nate
You are very welcome Nate.
May 2 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: d.schulz81 | last post by:
Hi all how can i manipulate a multiple select into a single select dropdown field with JavaScript? thanks
2
by: Hollywood | last post by:
After doing a search through google's archives of this list, I didn't see what I was looking for so here goes... Is it possible to serialize/deserialize multiple objects from a single XML file? ...
15
by: Sinex | last post by:
Hi, Why does C# disallow multiple inheritance? Whats the reason behind this? Is there any advantage or is it just a method to avoid some problems (if so, what problems?) that come with multiple...
0
by: tayssir.hawary | last post by:
Dear all, I need to get the old value when multiple objects are selected. It works fine when a single object is selected, but e.OldValue contains null when multiple objects are selected. I...
3
by: Bill | last post by:
I have a seating chart web form that has over 50 entry field controls (tables/booths) where I use a DropDownList box to select a single company name from a single large list of organizations (200...
3
by: spielmann | last post by:
Hello I want to change the scrollbar size of windows, How can I do that with vb.net I have find this in VB6 but how can we convert simply this code. thx
4
by: vze1r2ht | last post by:
I have many types of classes and I'm deciding whether to use a single class or multiple classes for EACH type of class. For an example: User class has 3 classes associated with it: User...
5
by: BMeyer | last post by:
I have been losing my mind trying to parse an XML document (with nested child elements, not all of which appear in each parent node) into a DataGrid object. What I want to do is "flatten" the XML...
6
by: Orgun | last post by:
Hi, I sent this message to the moderated c++ group too but it is waiting for moderator approval and I wanted to send here too. I am new to Design Patterns. I want to write a simple...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.