Saturday, 18 October 2014

C# Source Code Post #5

It's here!

The grand finale to player.cs!
Also, unfortunately, the end of the AwesomeRPG Source Code Posts. I feel like the majority of AwesomeRPG's code is currently too simple, poorly implemented and quite frankly repetitive for it to be that educational.
If you guys disagree and want to see more AwesomeRPG, let me know in the comments, and I might fit it in on Tuesdays, but for now, this is the last AwesomeRPG source post.

Following Saturdays will be how to implement random things that I want to cover.

Anyway, the rest of the code for Player.cs:

So, EquipItem(int itemID).
This is a "simple" method for equipping an item.
However, it doesn't know what kind of item it is, so it has to figure that out, then equip it in the correct spot.

I won't go into detail on the weapon type checks, as they were covered in the previous post.
Basically, first it checks if it's a weapon and has Damage higher than 0.

If it is, it's a Right Hand weapon. (There is no dual wielding yet)
If it isn't, it checks if it has Defense higher than 0.

If it does, it's a Left Hand Shield.

After that, if it's not a weapon, it checks if it's Armor.
If it is, it checks it's Body armor, if it is, it equips it in the body slot.
If not, it checks if it's Boots.
Then Gloves.
Then finally Helm.

Damage(int amt)

Literally removes amt from HP, and makes sure HP doesn't go below 0.

AddXP(int amt)

Adds XP, simple enough.
Also checks if the player can level up, and levels them up if they can.

And there you have it, the super anti-climactic end to the epic file that is player.cs
And the rather anti-climactic end to the AwesomeRPG posts (unless you guys protest in the forums, in which case I'll know you still want these)

Next Saturday I will be covering something new: C# web interaction.

Specifically how to login to a

No comments:

Post a Comment