Jump to content
  • Advertisement
Sign in to follow this  
FlawleX

C# - Combat system?

This topic is 2544 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello!

I recently started working on a text based RPG game assignment written in C# and it was going well untill i reached the combat part. I really don't know how to do it and i can't seem to find any solution for it.
This is my first C# project aswell and im new to programming in general.

I was going for a random number generator for the damage but it didn't work out so good so i scraped that but it still won't work!

The issue is that the boss HP won't go down! It becomes like a infinite loop of the same text over and over.
The game is in it's VERY early stages and some of the variables are just placeholders! But i need you guy's help to get past this problem!

The game files currently being used (Lot's of placeholder names and some unused variables):

Program.cs (Main file) : http://pastebin.com/TEQswSyi
Combat.cs (Some of the combat features): http://pastebin.com/bs1BUWUL
Chroniax.cs (One of the bosses): http://pastebin.com/TaFxgAyV

Share this post


Link to post
Share on other sites
Advertisement

Hello!

I recently started working on a text based RPG game assignment written in C# and it was going well untill i reached the combat part. I really don't know how to do it and i can't seem to find any solution for it.
This is my first C# project aswell and im new to programming in general.

I was going for a random number generator for the damage but it didn't work out so good so i scraped that but it still won't work!

The issue is that the boss HP won't go down! It becomes like a infinite loop of the same text over and over.
The game is in it's VERY early stages and some of the variables are just placeholders! But i need you guy's help to get past this problem!

The game files currently being used (Lot's of placeholder names and some unused variables):

Program.cs (Main file) : http://pastebin.com/TEQswSyi
Combat.cs (Some of the combat features): http://pastebin.com/bs1BUWUL
Chroniax.cs (One of the bosses): http://pastebin.com/TaFxgAyV




Well, congratulations on starting programming.

The specific problem you are having of "The issue is that the boss HP won't go down! " is because you never actually decrease the bosses hp's in the attack loop, so it will go over and over and over.

From what I can see, you should research a couple things. First, look into constructors with a bit more detail.

For example, I don't think this code does what you think it should:

[color=#181818][font=monospace]
  1. public Chroniax()
  2. {
  3. userInfo information = new userInfo();
  4. Combat combatFunctions = new Combat();
  5. Random chroniaxTotalDamage = new Random();
  6. chroniaxTD = chroniaxTotalDamage.Next(chroniaxAttackPower, 700);
  7. chroniaxAttackPower = 400;
  8. chroniaxFullHealth = 1000;
  9. chroniaxFullHealth -= combatFunctions.heavyDMG;
  10. /*
  11. chroniaxHealth = chroniaxFullHealth -= combatFunctions.heavyDMG;
  12. */
  13. }
[/font]




A constructor is called once and only once, when the item is created. There "[color=#181818][font=monospace]chroniaxFullHealth -= combatFunctions.heavyDMG;" doing that makes no sense.[/font]
[color=#181818][font=monospace]
[/font]
[color=#181818][font=monospace]The biggest catch though is in your combat loop:[/font]
[color=#181818][font=monospace]
[/font]
[color=#181818][font=monospace][/font][color=#181818][font=monospace]
  1. while (bossAlive == true)
  2. {
  3. if (chroniax.chroniaxFullHealth < 0)
  4. {
  5. bossAlive = false;
  6. }
  7. Console.WriteLine(combatFunctions.warriorAbilities);
  8. try
  9. {
  10. abilityChoice = int.Parse(Console.ReadLine());
  11. }
  12. catch
  13. {
  14. Console.ForegroundColor = ConsoleColor.Red;
  15. Console.WriteLine("An error occured! Please try again!");
  16. Console.ForegroundColor = ConsoleColor.Gray;
  17. Console.WriteLine("\nPress Enter to continue...");
  18. }
  19. if (abilityChoice == 1)
  20. {
  21. Console.WriteLine("You hit the boss for: " + combatFunctions.heavyDMG);
  22. Console.WriteLine("The boss has {0} HP left", chroniax.chroniaxFullHealth);
  23. }
  24. if (abilityChoice == 2)
  25. {
  26. Console.WriteLine("You hit the boss for: " + combatFunctions.mortalDMG);
  27. Console.WriteLine("The boss has {0} HP left", chroniax.chroniaxFullHealth);
  28. }
  29. if (abilityChoice == 3)
  30. {
  31. Console.WriteLine("You hit the boss for: " + combatFunctions.heroicDMG);
  32. Console.WriteLine("The boss has {0} HP left", chroniax.chroniaxFullHealth);
  33. }
  34. Console.WriteLine("The boss swings you for {0} damage", chroniax.chroniaxTD);
  35. Console.ReadKey();
  36. }
  37. }
[/font]
[color=#181818][font=monospace]

[/font]
[color=#181818][font=monospace]
[/font]
[color=#181818][font=monospace]
[/font]
[color=#181818][font=monospace]What you need to do is actually apply the damage against the boss object. First off, you have two health members and one doesn't seem to be used, so I will go with the one you did:[/font]
[color=#181818][font=monospace]
[/font]
[color=#181818][font=monospace]public int chroniaxFullHealth {get; protected set;}[/font]
[color=#181818][font=monospace]
[/font]
[color=#181818][font=monospace]What you want to do is change that to [/font]
[color=#181818][font=monospace]
[/font]
[color=#181818][font=monospace]public int chroniaxFullHealth {get; set;}[/font]
[color=#181818][font=monospace]
[/font]
[color=#181818][font=monospace]So that this value can be changed by code outside the [/font][color=#181818][font=monospace]Chroniax class.[/font]
[color=#181818][font=monospace]
[/font]
[color=#181818][font=monospace]Then in place of: [/font]
[color=#181818][font=monospace][/font][font="monospace"][color="#181818"]if (abilityChoice == 1)[/font]
[font="monospace"][color="#181818"] {[/font]
[font="monospace"][color="#181818"]
[/font]
[font="monospace"][color="#181818"] Console.WriteLine("You hit the boss for: " + combatFunctions.heavyDMG);[/font]
[font="monospace"][color="#181818"] Console.WriteLine("The boss has {0} HP left", chroniax.chroniaxFullHealth);[/font]
[font="monospace"][color="#181818"]
[/font]
[font="monospace"][color="#181818"] }[/font][color=#181818][font=monospace]

[/font]
[color=#181818][font=monospace]
[/font]
[color=#181818][font=monospace]You want:[/font]
[color=#181818][font=monospace][/font][font="monospace"][color="#181818"]if (abilityChoice == 1)[/font]
[font="monospace"][color="#181818"] {[/font]
[font="monospace"][color="#181818"]
[/font]
[font="monospace"][color="#181818"] Console.WriteLine("You hit the boss for: " + combatFunctions.heavyDMG);[/font]
[font="monospace"][color="#181818"] chroniax.chroniaxFullHealth -= combatFunctions.heavyDMG;[/font]
[font="monospace"][color="#181818"] Console.WriteLine("The boss has {0} HP left", chroniax.chroniaxFullHealth);[/font]
[font="monospace"][color="#181818"]
[/font]
[font="monospace"][color="#181818"] }[/font][color=#181818][font=monospace]

[/font]
[color=#181818][font=monospace]
[/font]
[color=#181818][font=monospace]
[/font]
[color=#181818][font=monospace]You will want to do the same thing for the various damage types.[/font]
[color=#181818][font=monospace]
[/font]
[color=#181818][font=monospace]There are other issues, but this should at least get it so you bosses HP's eventually go to zero allowing the loop to exit.[/font]

Share this post


Link to post
Share on other sites
God the CODE tag on this site blows. :(

Sorry, don't have time to repaste all the code right now, hope you can make sense of what I was trying to say.

Share this post


Link to post
Share on other sites

God the CODE tag on this site blows. :(

Sorry, don't have time to repaste all the code right now, hope you can make sense of what I was trying to say.


Thanks alot for your help!

Indeed the code tag isn't so good but i can still read it so thanks again! :D

Share this post


Link to post
Share on other sites
Wow! I would have ran from the freaking dragon, too!!! :lol:

Here, let me fix part of your code (which I ran through Notepad first):

if (attackChoice == true && (attackOrFlee == 2))
{
Console.Clear();
Console.WriteLine("WISE decision! Who could possibly stand toe-to-toe with a DRAGON?!");
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("You WIN!!!");
Console.ForegroundColor = ConsoleColor.Gray;
}

Just kidding with you, man! :)

Sorry that unlike unlike Serapth I don't have a programming answer for you as I am a complete newbie. But, I just wanted to say thanks a lot for sharing that code and for posting. Even though I'm making my first program in Python, it was interesting to see such a simple, basic game just like the one I'm writing.

When I made games with RPG Maker, a front-end for Ruby, the generic advice for non-boss monsters was that you should kill all appropriate monsters in about five hits and all appropriate monsters you fight should kill you in about five hits. That means if you're fighting a "weak" monster, it won't take as many hits to kill it, but if you're fighting a "strong" monster -- i.e., one on a "higher level" than your character is ready to face -- it will take more hits to kill and chances are, it'll kill your character in fewer hits too.

Another generic piece of advice was to have a 20% range above and below base-damage and chance-to-hit stats. So, if your base damage is 100, that means the attack will do between 80 and 120 points of damage, if my math is correct. :wink:

One last piece of generic, standard advice was to have weapons raise the character's base damage by half. So, if his Strength stat (or whatever you use to determine base damage) is 100, a magic sword of normal power level would add 50 to that stat, making his base damage 150.

That's all assuming you're going to have a character that "levels up," or becomes categorically more powerful as your game progresses as classical, console-style RPGs do.

You don't seem to have a combat engine that resembles classic RPGs, though. On first glance, it seems as though you have three combat options, each does more damage than the next... I very well could be wrong, though.


Have you never played Dungeons and Dragons, though? Pretty well all of D&D's stuff is OGL and can be accessed here: http://www.d20srd.org/

That's basically a complete character generation system, combat engine and compendium of monsters with which almost all sword-and-sorcery players are already familiar.

If you haven't, I doubt you'll want to learn an entire pencil-and-paper RPG system just to make a game, but...


Hope I've helped in some small way!

Thanks again for posting your code. I enjoyed reading it.

Share this post


Link to post
Share on other sites

Wow! I would have ran from the freaking dragon, too!!! :lol:

Here, let me fix part of your code (which I ran through Notepad first):

if (attackChoice == true && (attackOrFlee == 2))
{
Console.Clear();
Console.WriteLine("WISE decision! Who could possibly stand toe-to-toe with a DRAGON?!");
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("You WIN!!!");
Console.ForegroundColor = ConsoleColor.Gray;
}

Just kidding with you, man! :)

Sorry that unlike unlike Serapth I don't have a programming answer for you as I am a complete newbie. But, I just wanted to say thanks a lot for sharing that code and for posting. Even though I'm making my first program in Python, it was interesting to see such a simple, basic game just like the one I'm writing.

When I made games with RPG Maker, a front-end for Ruby, the generic advice for non-boss monsters was that you should kill all appropriate monsters in about five hits and all appropriate monsters you fight should kill you in about five hits. That means if you're fighting a "weak" monster, it won't take as many hits to kill it, but if you're fighting a "strong" monster -- i.e., one on a "higher level" than your character is ready to face -- it will take more hits to kill and chances are, it'll kill your character in fewer hits too.

Another generic piece of advice was to have a 20% range above and below base-damage and chance-to-hit stats. So, if your base damage is 100, that means the attack will do between 80 and 120 points of damage, if my math is correct. :wink:

One last piece of generic, standard advice was to have weapons raise the character's base damage by half. So, if his Strength stat (or whatever you use to determine base damage) is 100, a magic sword of normal power level would add 50 to that stat, making his base damage 150.

That's all assuming you're going to have a character that "levels up," or becomes categorically more powerful as your game progresses as classical, console-style RPGs do.

You don't seem to have a combat engine that resembles classic RPGs, though. On first glance, it seems as though you have three combat options, each does more damage than the next... I very well could be wrong, though.


Have you never played Dungeons and Dragons, though? Pretty well all of D&D's stuff is OGL and can be accessed here: http://www.d20srd.org/

That's basically a complete character generation system, combat engine and compendium of monsters with which almost all sword-and-sorcery players are already familiar.

If you haven't, I doubt you'll want to learn an entire pencil-and-paper RPG system just to make a game, but...


Hope I've helped in some small way!

Thanks again for posting your code. I enjoyed reading it.


Thanks for all the advice mate! The combat system is in it's very early stages currently and alot will be changed to make it more dynamic. I will for example not have a set damage value, the reason that it has a set damage value currently is only for testing :)

Share this post


Link to post
Share on other sites
I just ran in to another few problems!

If i use a random number generator to generate the damage for example:

Random heavyStrike = new Random();
int heavyDMG = heavyStrike.Next(charStats.attackPower, charStats.attackDamage);


I cannot take the damage the player deals - the bosses hp. But when i have a set damage value like lets say heavyDMG = 50; I can just use bossHP -= heavyDMG. But if i have a random number generator it says that i deal 0 damage and obviously the bossHP doesn't go down.

And the code doesn't start if i try to loop the random numbers to get different values everytime. I have even tried activating the loop from a bool when the combat is started and then stop it afterwards but it still doesn't work.

Any ideas on how i can solve this?

This is the important and relevant part of the combat file (im using classes to be able to send variables from file to file that's why it doesn't say int heavyDMG etc):


Random heavyStrike = new Random();
Random heroicStrike = new Random();
Random mortalStrike = new Random();


heavyDMG = heavyStrike.Next(charStats.attackPower, charStats.attackDamage);
heroicDMG = heroicStrike.Next(charStats.attackPower, charStats.attackDamage);
mortalDMG = mortalStrike.Next(charStats.attackPower, charStats.attackDamage);


And the combat part in the main file:

Console.WriteLine("You hit the boss for: " + combatFunctions.mortalDMG);
chroniax.chroniaxHealth -= combatFunctions.mortalDMG;
Console.WriteLine("The boss has {0} HP left", chroniax.chroniaxHealth);
Console.WriteLine("");
Console.ReadKey();

Share this post


Link to post
Share on other sites
I'm not sure I understand what you mean, so I'll try as best I can.

Why can't you simply assign the generated number to the damage properties in the abilities class?
In your code example you create a new variable, but in your code that assigns a pre-defined value you use the public properties.

Also, I don't understand what code "isn't starting" when you're looping. But if you have an issue with random numbers not being random, here's a hint:
The random function in programming functions are not really random, so it's good practice to seed them first. A simple and effective seed is to use the current time, like so:

Random random = new Random(DateTime.Now.Millisecond);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!