Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Generics to reduce complexity

Generics to reduce complexity

Scheduled Pinned Locked Moved C#
csharpgame-devalgorithmsoophelp
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Genbox
    wrote on last edited by
    #1

    Hi. I'm currently creating a game that contains a lot of characters. I'm now facing the problem of getting a very high complexity in my application because of the high number of characters. I wanted to make a CharacterHandler that creates instances of the characters (Need to be a factory patteren of a kind, character creations need to take game difficulty into accound etc.) this is some code from a character: public class Bananas : NormalBrush, ILevelObject, IPointObject { private readonly int _collisionGroup; private readonly float _mass; private Body _body; private Geom _geom; public Bananas(Vector2 position, int collisionGroup, float mass, float scale, ContentManager contentManager) : base(Color.White, position, contentManager.Load("Content/Objects/Fruits/Bananas")) { _collisionGroup = collisionGroup; _mass = mass; base.Scale = scale; } } Is there a way that i can change the inheritance of the objects to simplify the creation of the characters or maybe use C# generics to do the job? Any improvements are welcome. EDIT: To sum it up. Instead of doing: CharacterHandler.CreateBananas(position); CharacterHandler.CreateOrange(position); CharacterHandler.CreateApple(position); I could do something like this: CharacterHandler.CreateCharacter(position); and so on.

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups