Organizing code question

Updated on August 1, 2017 in [C] Beginner
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
2 on August 1, 2017

I’ve been coding with C# and Unity for about 7 months and I’m not sure if I’m writing my code efficiently.  First let me say that all of my code is working and my game does what it should be doing, I’m just not sure if there is a better way to go about it.

I’m building a RPG with multiple characters in a party. Every character can acquire skills that let them do unique things. For examples, fighters might have a group attack skill, healers can heal, a wizard could cast fireball, ect.

In my game, the hero character has a script attached that has all of the class properties, methods and functions. One of the properties in the hero script is an array list of Skills, where skills is a unique class.

I have a second script that contains all of the skills in the game and uses an interface to access the skills.  a example of how it looks;

Skills.cs file

public interface ISkills

{

string skillName {get ; set;}

string skillCost{get ;set;}

}

 

Hero.cs file

public ISkills[] HeroSkills  = new ISkills[10] ;

 

Again, everything is working. I can add skills to the array and the hero has access to use them. I am just wondering what problems I could run into down the road using this architecture.

 

 

 

 

  • Liked by
Reply
1 on August 1, 2017

I think you are on a good way. You might want to look for place where your copy&paste code and see if you could use inheritance to avoid the same code in multiple places. 

Also in case you need some specific structures or behaviours you might want to familiarise yourself with Design Patterns in programming. You could also look for Design Patterns specific for game development.

Devoted
on August 1, 2017
Show more replies
  • Liked by
Reply
Cancel